forked from OpenCMISS/cm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
143 lines (124 loc) · 4.9 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
cmake_minimum_required (VERSION 3.0 FATAL_ERROR)
project(Iron VERSION 1.0 LANGUAGES C Fortran)
option(WITH_CELLML "Build iron with CellML support" YES)
option(WITH_FIELDML "Build iron with FieldML support" NO)
#option(BUILD_TESTS "${PROJECT_NAME} - Build tests" ON)
option(PACKAGE_CONFIG_DIR "Directory for package config files (relative to CMAKE_INSTALL_PREFIX)" "lib/cmake")
# Config
SET(CMAKE_NO_SYSTEM_FROM_IMPORTED YES)
SET(IRON_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
INCLUDE(${IRON_MODULES}/MacroDefinitions.cmake)
INCLUDE(${IRON_MODULES}/CompileFlags.cmake)
# 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)
# External components
# MPI
find_package(MPI REQUIRED)
SET(LINK_LIBS )
# CellML
if (WITH_CELLML)
find_package(LIBCELLML CONFIG REQUIRED)
find_package(CELLML-API CONFIG REQUIRED)
LIST(APPEND LINK_LIBS cellml cellml_api cellml_model_definition)
endif()
# FieldML
if (WITH_FIELDML)
find_package(FIELDML REQUIRED)
endif()
# Other Dependencies
include(Variables)
SET(DEPS PETSC SUNDIALS HYPRE MUMPS SCALAPACK) #BLACS
foreach(DEP ${DEPS})
# Look for config-aware implementations first
find_package(${DEP} CONFIG QUIET)
if (NOT ${DEP}_FOUND)
FIND_PACKAGE(${DEP} REQUIRED)
INCLUDE_DIRECTORIES(${${DEP}_INCLUDES})
else()
LIST(APPEND LINK_LIBS ${${DEP}_TARGETS})
endif()
endforeach()
message("Iron link libaries: ${LINK_LIBS}")
# Config
SET(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
#SET(HEADER_INC_NAME opencmiss.h)
#SET(HEADER_SOURCE_INC ${SOURCE_DIR}/${HEADER_INC_NAME})
SET(LIBRARY_INSTALL_TYPE ARCHIVE)
##############################
# Libraries / targets
# C-Bindings extra target
find_package(PythonInterp QUIET)
set(HAVE_BINDINGS FALSE)
if (PYTHONINTERP_FOUND)
set(OPENCMISS_H ${CMAKE_CURRENT_BINARY_DIR}/opencmiss.h)
set(OPENCMISS_C_F90 ${CMAKE_CURRENT_BINARY_DIR}/opencmiss_c.f90)
set_source_files_properties(${OPENCMISS_C_F90} PROPERTIES GENERATED TRUE)
add_custom_command(OUTPUT ${OPENCMISS_H} ${OPENCMISS_C_F90}
COMMAND ${PYTHON_EXECUTABLE} generate_bindings ${CMAKE_CURRENT_SOURCE_DIR} C ${OPENCMISS_H} ${OPENCMISS_C_F90}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings
COMMENT "Generating Iron C-bindings")
set(HAVE_BINDINGS TRUE)
else()
message(WARNING "No Python interpreter found. Unable to generate C bindings for Iron.")
endif()
IF(WIN32)
# Need separate C/Fortran code due to Project natures in VS
FILE(GLOB OPENCMISS_FORTRAN_SRCS ${SOURCE_DIR}/*.f90)
FILE(GLOB OPENCMISS_C_SRCS ${SOURCE_DIR}/*.c)
FILE(GLOB OPENCMISS_C_HEADER ${SOURCE_DIR}/*.h)
LIST(APPEND OPENCMISS_C_SRCS ${OPENCMISS_C_HEADER})
INCLUDE(${IRON_MODULES}/Entries.cmake )
FOREACH(infileName ${EXCLUDED_ROUTINES})
LIST(REMOVE_ITEM OPENCMISS_FORTRAN_SRCS ${infileName})
LIST(REMOVE_ITEM OPENCMISS_C_SRCS ${infileName})
ENDFOREACH(infileName)
# ? maybe use object target an then combine to one target..
ADD_LIBRARY(iron_Fortran ${OPENCMISS_FORTRAN_SRCS})
target_include_directories(iron_Fortran PUBLIC ${MPI_Fortran_INCLUDE_PATH})
if (WITH_CELLML)
target_compile_definitions(iron_Fortran PUBLIC USECELLML)
endif()
ADD_LIBRARY(iron_C ${OPENCMISS_C_SRCS})
if (WITH_CELLML)
target_compile_definitions(iron_C PUBLIC USECELLML)
endif()
target_include_directories(iron_C PUBLIC ${MPI_C_INCLUDE_PATH})
ELSE()
# Remove some source files from compilation
FILE(GLOB IRON_SOURCES ${SOURCE_DIR}/*.*)
INCLUDE(${IRON_MODULES}/Entries.cmake)
FOREACH(infileName ${EXCLUDED_ROUTINES})
FILE(GLOB infileName ${infileName}) # necessary to get an exact match of the filename in the list (for out-of-source builds)
IF (infileName) # if file was found
LIST(REMOVE_ITEM IRON_SOURCES ${infileName})
ENDIF ()
ENDFOREACH()
if (HAVE_BINDINGS)
list(APPEND IRON_SOURCES ${OPENCMISS_C_F90})
endif()
ADD_LIBRARY(iron ${IRON_SOURCES})
if (WITH_CELLML)
target_compile_definitions(iron PRIVATE USECELLML)
endif()
if (WITH_FIELDML)
target_compile_definitions(iron PRIVATE USEFIELDML)
endif()
target_include_directories(iron PUBLIC ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
target_link_libraries(iron ${LINK_LIBS})
ENDIF()
# Install steps
INSTALL(TARGETS iron
EXPORT iron-config
DESTINATION iron
INCLUDES DESTINATION include)
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)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iron-config-version.cmake DESTINATION ${PACKAGE_CONFIG_DIR})
# Install fortran modules
INSTALL(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/
DESTINATION include
)
if (HAVE_BINDINGS)
INSTALL(FILES ${OPENCMISS_H} DESTINATION include)
endif()