forked from OpenCMISS/iron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·156 lines (140 loc) · 6.25 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
cmake_minimum_required (VERSION 3.0 FATAL_ERROR)
project(Iron VERSION 0.4.0 LANGUAGES C CXX Fortran)# Need all languages as iron's deps cover all (link phase)
option(WITH_CELLML "Build iron with CellML support" ON)
option(WITH_FIELDML "Build iron with FieldML support" ON)
option(WITH_HYPRE "Build iron with HYPRE integration" ON)
option(WITH_SUNDIALS "Build iron with SUNDIALS integration" ON)
option(WITH_MUMPS "Build iron with MUMPS integration" ON)
option(WITH_SCALAPACK "Build iron with SCALAPACK integration" ON)
option(WITH_PETSC "Build iron with PETSC integration" ON)
option(BUILD_TESTS "${PROJECT_NAME} - Build tests" ON)
option(WITH_PROFILING "${PROJECT_NAME} - Build with profiling flags" OFF)
option(WITH_C_BINDINGS "Build iron C bindings" ON)
option(WITH_Python_BINDINGS "Build iron Python bindings" ON)
set(PACKAGE_CONFIG_DIR "cmake" CACHE STRING "Directory for package config files (relative to CMAKE_INSTALL_PREFIX)")
set(WITH_FIELDML ON)
# Config
# See http://cmake.3232098.n2.nabble.com/How-to-install-Fortran-module-files-td7584399.html
SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran_modules)
SET(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE)
# Have cmake find our own scripts
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# External components
# MPI
find_package(MPI REQUIRED)
# Collect libraries to configure for/link against
SET(LINK_LIBS )
if (WITH_CELLML)
find_package(LIBCELLML ${LIBCELLML_VERSION} CONFIG REQUIRED)
find_package(CELLML ${CELLML_VERSION} CONFIG REQUIRED)
message(STATUS "Building with CELLML (${LIBCELLML_DIR})")
LIST(APPEND LINK_LIBS cellml cellml_model_definition)
endif()
if (WITH_FIELDML)
message(STATUS "Building with FIELDML (${FIELDML-API_DIR})")
find_package(FIELDML-API ${FIELDML-API_VERSION} CONFIG REQUIRED)
endif()
# This include file is in the main "manage" directory.
# We can include this here as iron is an integrated part of the overall build system.
SET(IRON_UPSTREAM_DEPS PETSC SUNDIALS HYPRE MUMPS SCALAPACK PARMETIS)
foreach(DEP ${IRON_UPSTREAM_DEPS})
if (WITH_${DEP})
message(STATUS "Looking for ${DEP}..")
find_package(${DEP} REQUIRED)
if (${DEP}_DIR)
# This is set if CONFIG mode was used
set(DEP_LOC ${${DEP}_DIR})
else()
# This is set if MODULE mode was used
if (${DEP}_LIBRARIES)
set(_ALTERNATIVE ${DEP}_LIBRARIES)
else()
set(_ALTERNATIVE ${DEP}_INCLUDE_PATH)
endif()
list(GET ${_ALTERNATIVE} 0 DEP_LOC)
get_filename_component(DEP_LOC ${DEP_LOC} PATH)
endif()
message(STATUS "Looking for ${DEP}.. found at ${DEP_LOC}")
string(TOLOWER ${DEP} targetname)
LIST(APPEND LINK_LIBS ${targetname})
endif()
endforeach()
# Populates the IRON_XX_SRC variables
include(Sources)
if(MSVC)
# Need separate C/Fortran code due to Project natures in VS
add_library(iron_Fortran OBJECT ${IRON_Fortran_SRC})
target_include_directories(iron_Fortran
PUBLIC ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH}
PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY})
add_library(iron_C OBJECT ${IRON_C_SRC})
target_include_directories(iron_C
PUBLIC ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
# Add joining library to have the "iron" target in each case
add_library(iron $<TARGET_OBJECTS:iron_Fortran> $<TARGET_OBJECTS:iron_C>)
else()
add_library(iron ${IRON_SRC})
set(IRON_TARGETS iron)
ENDIF()
# Set the same stuff for either the separate targets (windows) or one target (else)
foreach(irontarget ${IRON_TARGETS})
target_include_directories(${irontarget}
PUBLIC ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH}
PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY})
if (WITH_CELLML)
target_compile_definitions(${irontarget} PUBLIC USECELLML)
endif()
if (WITH_FIELDML)
target_compile_definitions(${irontarget} PUBLIC USEFIELDML)
endif()
endforeach()
set_source_files_properties(${IRON_Fortran_SRC} PROPERTIES
COMPILE_FLAGS -cpp)
target_link_libraries(iron PRIVATE ${LINK_LIBS})
if(WITH_FIELDML)
target_link_libraries(iron PRIVATE fieldml-api)
endif()
# Dont use "USE MPI" instructions if the percompiled mpi module files are incompatible.
# This happens when the fortran compiler used to build mpi differs from the currently used one.
# This holds on windows (only pre-compiled mpi implementations available; MPICH2 and MSMPI)
# and on e.g. clusters with inappropriately configured toolchain environments.
if (MINGW OR NOT MPI_Fortran_MODULE_COMPATIBLE)
target_compile_definitions(iron PRIVATE NOMPIMOD)
endif()
# Build bindings as selected
add_subdirectory(bindings)
# Install steps
INSTALL(TARGETS iron
EXPORT iron-config
DESTINATION lib
INCLUDES DESTINATION include/iron)
install(EXPORT iron-config DESTINATION ${PACKAGE_CONFIG_DIR})
include(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_CURRENT_BINARY_DIR}/iron-config-version.cmake COMPATIBILITY AnyNewerVersion)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake
"include(CMakeFindDependencyMacro)\r\n"
"set(${PROJECT_NAME}_IMPORT_PREFIX \${_IMPORT_PREFIX})\r\n"
)
foreach(IRON_DEP ${IRON_UPSTREAM_DEPS})
if (WITH_${IRON_DEP})
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake "find_dependency(${IRON_DEP})\r\n")
endif()
endforeach()
if (WITH_CELLML)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake "find_dependency(CELLML)\r\n")
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake "find_dependency(LIBCELLML)\r\n")
endif()
if (WITH_FIELDML)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake "find_dependency(FIELDML-API)\r\n")
endif()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake "set(_IMPORT_PREFIX \${${PROJECT_NAME}_IMPORT_PREFIX})")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/iron-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/iron-config-dependencies.cmake
DESTINATION ${PACKAGE_CONFIG_DIR})
INSTALL(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/
DESTINATION include/iron
PATTERN *.mod)
if (HAVE_C_BINDINGS)
INSTALL(FILES ${OPENCMISS_H} DESTINATION include/iron)
endif()