-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
299 lines (265 loc) · 10.8 KB
/
CMakeLists.txt
File metadata and controls
299 lines (265 loc) · 10.8 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
cmake_minimum_required(VERSION 3.10)
string(CONCAT MFrontGenericInterfaceSupportDescription
"The MFrontGenericInterfaceSupport project provides "
"useful feature for solvers' developpers to "
"integrate MFront generated material libraries.")
include(cmake/modules/mgis.cmake)
set(MFrontGenericInterfaceSupportDevelopmentVersion ON)
project("mfront-generic-interface"
VERSION 3.1.0
DESCRIPTION "${MFrontGenericInterfaceSupportDescription}"
HOMEPAGE_URL "https://thelfer.github.io/mgis/web/index.html")
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/mgis-config-version.cmake"
VERSION "${VERSION}"
COMPATIBILITY SameMinorVersion)
install(FILES "${PROJECT_BINARY_DIR}/mgis-config-version.cmake"
DESTINATION "${mgis_export_install_path}")
set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
# portable-build
option(enable-portable-build "produce binary that can be shared between various machine (same architecture, same gcc version, different processors" OFF)
# OpenMP
option(enable-openmp "enable openmp" OFF)
if(enable-openmp)
find_package(OpenMP REQUIRED)
endif(enable-openmp)
# enable mgis-function
option(enable-mgis-function "enable mgis function" ON)
option(enable-mgis-function-precompiled-operations
"enable compilations of some tensorial operations of basic functions. \
This requires mgis-functions to be handled **and** TFEL support" ON)
# enable exceptions usage
option(enable-exceptions "use exceptions to report contract violation and error reporting" OFF)
# support for STL parallel algorithms
option(enable-parallel-stl-algorithms "enable STL parallel algorithms" ON)
# C-bindings (placed before compiler detection)
option(enable-c-bindings "enable c bindings support")
# fortran-bindings (placed before compiler detection)
option(enable-fortran-bindings "enable fortran bindings support" OFF)
if(enable-fortran-bindings)
if(NOT enable-c-bindings)
message(FATAL_ERROR "c-bindings must be enabled for fortran bindings.")
endif(NOT enable-c-bindings)
enable_language (Fortran)
endif(enable-fortran-bindings)
#python bindings
option(enable-python-bindings "enable python bindings support" OFF)
if(enable-python-bindings)
find_package(Python REQUIRED COMPONENTS Interpreter Development NumPy)
set(HAVE_PYTHON ON)
get_filename_component(PYTHON_LIBRARY_PATH ${Python_LIBRARIES} PATH)
get_filename_component(PYTHON_LIBRARY_FULL ${Python_LIBRARIES} NAME)
string(REGEX REPLACE "lib(.+)\\.(.+)$" "\\1" PYTHON_LIBRARY ${PYTHON_LIBRARY_FULL})
message(STATUS "found python ${Python_VERSION}")
message(STATUS "python include path ${Python_INCLUDE_DIRS}")
message(STATUS "python libraries path ${PYTHON_LIBRARY_PATH}")
message(STATUS "python library ${PYTHON_LIBRARY}")
message(STATUS "python interpreter ${Python_EXECUTABLE}")
message(STATUS "Numpy version ${Python_NumPy_VERSION}")
message(STATUS "Numpy header path ${Python_NumPy_INCLUDE_DIRS}")
# pybind11
find_package(pybind11 CONFIG REQUIRED)
list(APPEND CPACK_COMPONENTS_ALL python_bindings)
set(CPACK_COMPONENT_PYTHON_BINDINGS_DESCRIPTION
"Contains the python bindings for MGIS")
set(CPACK_COMPONENT_PYTHON_BINDINGS_DEPENDS mgis)
# store the location of the python modules in the MGIS_PYTHON_MODULES_INSTALL_DIRECTORY variable
if(MGIS_APPEND_SUFFIX)
if(WIN32)
set(MGIS_PYTHON_MODULES_INSTALL_DIRECTORY
bin/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/mgis_${MGIS_SUFFIX_FOR_PYTHON_MODULES})
else(WIN32)
set(MGIS_PYTHON_MODULES_INSTALL_DIRECTORY
"lib${LIB_SUFFIX}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/mgis_${MGIS_SUFFIX_FOR_PYTHON_MODULES}")
endif(WIN32)
else(MGIS_APPEND_SUFFIX)
if(WIN32)
set(MGIS_PYTHON_MODULES_INSTALL_DIRECTORY
"bin/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/mgis")
else(WIN32)
set(MGIS_PYTHON_MODULES_INSTALL_DIRECTORY
"lib${LIB_SUFFIX}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/mgis")
endif(WIN32)
endif(MGIS_APPEND_SUFFIX)
endif(enable-python-bindings)
# fenics-bindings (placed before compiler detection)
option(enable-fenics-bindings "enable fenics bindings support" OFF)
if(enable-fenics-bindings)
# Find DOLFIN
find_package(DOLFIN REQUIRED)
include(${DOLFIN_USE_FILE})
endif(enable-fenics-bindings)
# julia-bindings (placed before compiler detection)
option(enable-julia-bindings "enable julia bindings support" OFF)
if(enable-julia-bindings)
# The current version (0.16.0) of CxxWrap overrides the
# CMAKE_CXX_STANDARD variables, so we reset it after
# calling find_package to the current version
set(_CMAKE_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
find_package(JlCxx REQUIRED)
set(CMAKE_CXX_STANDARD "${_CMAKE_CXX_STANDARD}")
endif(enable-julia-bindings)
# HDF5 support (optional)
option(enable-hdf5-support "enable HDF5 support" OFF)
option(enable-hdf5-automatic-support "if set, try to support HDF5, even if not explicitly requested by enable-hdf5-support" ON)
if(enable-hdf5-support)
find_package(HDF5 REQUIRED COMPONENTS CXX)
else(enable-hdf5-support)
if(enable-hdf5-automatic-support)
find_package(HDF5 COMPONENTS CXX)
endif(enable-hdf5-automatic-support)
endif(enable-hdf5-support)
if(HDF5_FOUND)
set(MGIS_HDF5_SUPPORT ON)
MESSAGE(STATUS "hdf5 headers : " ${HDF5_INCLUDE_DIRS})
MESSAGE(STATUS "hdf5 librairies : " ${HDF5_LIBRARIES})
MESSAGE(STATUS "hdf5 definitions : " ${HDF5_DEFINITIONS})
else(HDF5_FOUND)
set(MGIS_HDF5_SUPPORT OFF)
endif(HDF5_FOUND)
# summary
if(enable-c-bindings)
message(STATUS "c bindings support enabled")
endif(enable-c-bindings)
if(enable-python-bindings)
message(STATUS "python bindings support enabled")
endif(enable-python-bindings)
if(enable-fortran-bindings)
message(STATUS "fortran bindings support enabled")
endif(enable-fortran-bindings)
if(enable-fenics-bindings)
message(STATUS "FEniCS bindings support enabled")
endif(enable-fenics-bindings)
if(MGIS_HDF5_SUPPORT)
message(STATUS "HDF5 support enabled")
endif(MGIS_HDF5_SUPPORT)
find_package(Threads)
# if(MINGW)
# file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/thread-mingw.cxx"
# "int main(){std::thread t; return 0;}")
# try_compile(MGIS_MINGW_HAVE_NATIVE_STD_THREAD
# ${CMAKE_BINARY_DIR}
# ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/thread-mingw.cxx
# COMPILE_DEFINITIONS ${COMPILER_CXXFLAGS})
# if(MGIS_MINGW_HAVE_NATIVE_STD_THREAD)
# set(MGIS_USE_MINGW_STD_THREADS ON)
# endif(MGIS_MINGW_HAVE_NATIVE_STD_THREAD)
# endif(MINGW)
# Looking for libdl...
if(UNIX)
if(NOT MGIS_DL_LIBRARY)
if((${CMAKE_SYSTEM_NAME} MATCHES "Linux") OR
(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
find_library(MGIS_DL_LIBRARY
NAMES dl)
if(NOT MGIS_DL_LIBRARY)
MESSAGE(FATAL_ERROR "the libdl library not found. You may want to set the `MGIS_DL_LIBRARY` variable manually")
endif(NOT MGIS_DL_LIBRARY)
else((${CMAKE_SYSTEM_NAME} MATCHES "Linux") OR
(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
set(MGIS_DL_LIBRARY "")
endif((${CMAKE_SYSTEM_NAME} MATCHES "Linux") OR
(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
endif(NOT MGIS_DL_LIBRARY)
else(UNIX)
set(MGIS_DL_LIBRARY "")
endif(UNIX)
#compiler options
include(cmake/modules/compiler.cmake)
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
include(cmake/modules/CodeCoverage.cmake)
SETUP_TARGET_FOR_COVERAGE(coverage ctest coverage)
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
#detecting TFEL and MFront
option(disable-tfel "explicitly disable TFEL support. By default, MGIS tries to use TFEL for tests and MGIS/Function" OFF)
if(NOT disable-tfel)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
find_package(TFEL)
if(TFEL_FOUND)
include(tfel)
include(material-properties)
include(behaviours)
endif(TFEL_FOUND)
endif(NOT disable-tfel)
#documentations
option(enable-doxygen-doc "enable generation of the Doxygen documentation" OFF)
option(enable-website "enable generation of the website" ON)
if(enable-doxygen-doc OR enable-website)
add_custom_target(doc)
endif(enable-doxygen-doc OR enable-website)
# add a target to generate API documentation with Doxygen
if(enable-doxygen-doc)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/docs)
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
add_custom_target(doc-html
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
add_dependencies(doc doc-html)
list(APPEND CPACK_COMPONENTS_ALL doxygen)
set(CPACK_COMPONENT_DOXYGEN_DESCRIPTION
"Contains MGIS' doxygen documentation")
set(MGIS_GENERATE_DOXYGEN ON)
else(DOXYGEN_FOUND)
message(FATAL_ERROR "doxygen is required")
endif(DOXYGEN_FOUND)
else(enable-doxygen-doc)
message(STATUS "doxygen documentation is not enabled")
endif(enable-doxygen-doc)
if(enable-website)
set(MGIS_GENERATE_WEBSITE OFF)
# Looking for pandoc (http://johnmacfarlane.net/pandoc)
include(cmake/modules/pandoc.cmake)
if(MGIS_HAVE_PANDOC)
set(MGIS_GENERATE_WEBSITE ON)
endif(MGIS_HAVE_PANDOC)
# Looking for jupyter-nbconvert
include(cmake/modules/jupyter-nbconvert.cmake)
if(MGIS_HAVE_JUPYTER_NBCONVERT)
set(MGIS_GENERATE_WEBSITE ON)
endif(MGIS_HAVE_JUPYTER_NBCONVERT)
if(MGIS_GENERATE_WEBSITE)
list(APPEND CPACK_COMPONENTS_ALL website)
set(CPACK_COMPONENT_WEBSITE_DESCRIPTION
"Contains the MGIS web site")
endif(MGIS_GENERATE_WEBSITE)
else(enable-website)
message(STATUS "Generation of the MGIS website disabled")
endif(enable-website)
add_subdirectory(docs)
# testing
set(CTEST_CONFIGURATION_TYPE "${JOB_BUILD_CONFIGURATION}")
# (must be placed *before* any add_subdirectory, cmake bug ?)
enable_testing()
if(CMAKE_VERSION VERSION_GREATER 3.21.4)
set(ctest_args )
list(APPEND ctest_args --output-junit ctest-results.xml)
endif(CMAKE_VERSION VERSION_GREATER 3.21.4)
if(CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND
${CMAKE_CTEST_COMMAND} ${ctest_args} -T test -C $<CONFIGURATION>)
else(CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND
${CMAKE_CTEST_COMMAND} ${ctest_args} -T test )
endif(CMAKE_CONFIGURATION_TYPES)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(bindings)
# shall be included after the other directories
add_subdirectory(env)
# Packaging
if(MFrontGenericInterfaceSupportDevelopmentVersion)
set(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_PROJECT_VERSION_PATCH}-dev")
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LGPL-3.0.txt")
set(CPACK_VERBATIM_VARIABLES YES)
if(NOT CPACK_SOURCE_GENERATOR)
set(CPACK_SOURCE_GENERATOR "TGZ")
endif(NOT CPACK_SOURCE_GENERATOR)
set(CPACK_SOURCE_IGNORE_FILES "build;/\\.git/;.*~")
include(CPack)