forked from dobrzynski/hex2tet
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
337 lines (277 loc) · 10.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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0)
PROJECT (hex2tet)
INCLUDE(CMakeDependentOption)
INCLUDE(cmake/modules/macros.cmake)
# Executable path
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(H2T_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
SET(H2T_BUILD_DIR ${PROJECT_BINARY_DIR}/src)
SET(H2T_INCLUDE ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME} )
FILE ( MAKE_DIRECTORY ${H2T_BUILD_DIR} )
###############################################################################
#####
##### Release version and date
#####
###############################################################################
SET (CMAKE_RELEASE_VERSION_MAJOR "1")
SET (CMAKE_RELEASE_VERSION_MINOR "1")
SET (CMAKE_RELEASE_VERSION_PATCH "0")
SET (CMAKE_RELEASE_DATE "Nov 5, 2024")
SET (CMAKE_RELEASE_VERSION
"${CMAKE_RELEASE_VERSION_MAJOR}.${CMAKE_RELEASE_VERSION_MINOR}.${CMAKE_RELEASE_VERSION_PATCH}")
# Create hex2tet.h file with the good release infos.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/hex2tet.h.in
${H2T_BUILD_DIR}/hex2tet.h @ONLY)
INCLUDE_DIRECTORIES ( ${H2T_BUILD_DIR} )
###############################################################################
#####
##### Main CMake compilation variables
#####
###############################################################################
# To see flags and options of compilation
#SET(CMAKE_VERBOSE_MAKEFILE TRUE)
# Find "exotic" compilers
IF (${CMAKE_C_COMPILER} MATCHES Clang OR ${CMAKE_C_COMPILER} MATCHES clang)
# using clang
SET(CMAKE_COMPILER_IS_CLANG TRUE)
ELSEIF(${CMAKE_C_COMPILER} MATCHES Icc OR ${CMAKE_C_COMPILER} MATCHES icc)
# using icc
SET(CMAKE_COMPILER_IS_INTEL TRUE)
ENDIF()
# Hide some options
MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS " -Wno-char-subscripts ${CMAKE_C_FLAGS}")
IF(APPLE)
# Add flags to the compiler to work on old mac
ADD_DEFINITIONS( -mmacosx-version-min=10.4 -arch x86_64)
# To avoid pbs with binary files...
SET(CMAKE_EXE_LINKER_FLAGS "-arch x86_64 ${CMAKE_EXE_LINKER_FLAGS}")
# Determine if the processor supports 64bit execution
EXECUTE_PROCESS(
COMMAND sysctl hw.cpu64bit_capable
ERROR_QUIET
OUTPUT_VARIABLE 64_CMD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
STRING(REGEX REPLACE "^hw.cpu64bit_capable: (.*)" "\\1" 64_BIT "${64_CMD}")
# ELSEIF(UNIX)# UNIX must be after APPLE becaus APPLE is UNIX too
ENDIF()
ENDIF()
IF(NOT CMAKE_COMPILER_IS_CLANG)
# Compiler options for profiling... but not possible with clang
OPTION ( PROFILING "Enable/Disable PROFILING" OFF )
IF(PROFILING)
ADD_DEFINITIONS(-pg)
SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF(PROFILING)
ENDIF(NOT CMAKE_COMPILER_IS_CLANG)
###############################################################################
#####
##### Choose executable target to compile
#####
###############################################################################
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
MESSAGE(STATUS "Setting build type to 'Release' as none was specified.")
seT(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} )
ENDIF()
############################################################################
#####
##### MMG (for mesh data structure)
#####
############################################################################
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
SET(MMG_DIR "" CACHE PATH "Installation directory for mmg")
FIND_PACKAGE(MMG)
IF ( NOT MMG_FOUND )
MESSAGE ( FATAL_ERROR "ERROR: The installation directory for mmg is required:"
"(see https://github.com/MmgTools/mmg and download the branch develop)."
"If you have already installed Mmg and want to use it, "
"please set the CMake variable or environment variable MMG_DIR "
"to your mmg directory.") # Set flags for building test program
ELSE ( )
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS})
MESSAGE(STATUS
"Compilation with Mmg: ${MMG_LIBRARIES}")
SET( LIBRARIES ${MMG_LIBRARIES} ${LIBRARIES})
ENDIF ( )
############################################################################
#####
##### Fortran header: libmmgtypesf.h
#####
############################################################################
ADD_EXECUTABLE(genheader ${PROJECT_SOURCE_DIR}/scripts/genheader.c)
TARGET_LINK_LIBRARIES ( genheader ${LIBRARIES} )
GENERATE_FORTRAN_HEADER ( hex2tet
${H2T_SOURCE_DIR} libhex2tet.h ${MMG_INCLUDE_DIRS}/mmg/common/libmmgtypes.h
${H2T_BUILD_DIR} libhex2tetf.h
)
############################################################################
#####
##### Scotch
#####
############################################################################
# Find SCOTCH library?
SET(SCOTCH_DIR "" CACHE PATH "Installation directory for scotch")
# add Scotch library?
SET ( USE_SCOTCH "" CACHE STRING "Use SCOTCH tool for renumbering (ON, OFF or <empty>)" )
SET_PROPERTY(CACHE USE_SCOTCH PROPERTY STRINGS "ON" "OFF" "")
IF ( NOT DEFINED USE_SCOTCH OR USE_SCOTCH STREQUAL "" OR USE_SCOTCH MATCHES " +" )
# Variable is not provided by user
FIND_PACKAGE(SCOTCH QUIET)
ELSE ()
IF ( USE_SCOTCH )
FIND_PACKAGE(SCOTCH)
IF ( NOT SCOTCH_FOUND )
MESSAGE ( WARNING "Scotch library not found:"
"Using scotch reduce the execution time of mmg3d "
"(see https://gforge.inria.fr/frs/?group_id=248 to download it)."
"If you have already installed Scotch and want to use it, "
"please set the CMake variable or environment variable SCOTCH_DIR "
"to your scotch directory.")
ENDIF ( )
ENDIF()
ENDIF()
If ( SCOTCH_FOUND )
add_definitions(-DUSE_SCOTCH)
MESSAGE(STATUS
"Compilation with scotch: ${SCOTCH_LIBRARIES}")
SET( LIBRARIES ${LIBRARIES} ${SCOTCH_LIBRARIES})
INCLUDE_DIRECTORIES(${SCOTCH_INCLUDE_DIRS})
ENDIF()
############################################################################
#####
##### Elastic
#####
############################################################################
# add SUscElas library?
SET(ELAS_DIR "" CACHE PATH "Installation directory for Elas")
INCLUDE(cmake/modules/FindElas.cmake)
CMAKE_DEPENDENT_OPTION (
USE_ELAS "Use the Elas library for lagrangian motion option" ON
"ELAS_FOUND" OFF)
IF( USE_ELAS )
# Set flags for building test program
INCLUDE_DIRECTORIES(${ELAS_INCLUDE_DIR})
SET(CMAKE_REQUIRED_INCLUDES ${ELAS_INCLUDE_DIR})
SET(CMAKE_REQUIRED_LIBRARIES ${ELAS_LIBRARY})
SET(CMAKE_C_FLAGS "-DUSE_ELAS ${CMAKE_C_FLAGS}")
MESSAGE(STATUS
"Compilation with the Elas library: ${ELAS_LIBRARY} ")
SET( LIBRARIES ${ELAS_LINK_FLAGS} ${LIBRARIES})
SET( LIBRARIES ${ELAS_LIBRARY} ${LIBRARIES})
ENDIF()
IF (ELAS_NOTFOUND)
MESSAGE ( WARNING "Elas is a library to solve the linear elasticity "
"problem (see https://github.com/SUscTools/Elas to download it). "
"This library is needed to use the lagrangian motion option. "
"If you have already installed Elas and want to use it, "
"please set the CMake variable or environment variable ELAS_DIR "
"to your Elas directory.")
ENDIF ( )
###############################################################################
#####
##### Sources and libraries
#####
###############################################################################
# Header files
INCLUDE_DIRECTORIES(${H2T_SOURCE_DIR})
# Source files
FILE(
GLOB
library_files
${H2T_SOURCE_DIR}/*.c ${H2T_SOURCE_DIR}/*.h
)
LIST(REMOVE_ITEM library_files
${H2T_SOURCE_DIR}/hex2tet.c)
FILE(
GLOB
main_file
${H2T_SOURCE_DIR}/hex2tet.c
)
IF (NOT WIN32)
FIND_LIBRARY(M_LIB m)
SET( LIBRARIES ${LIBRARIES} ${M_LIB})
ENDIF()
############################################################################
#####
##### RPATH for MACOSX
#####
############################################################################
SET(CMAKE_MACOSX_RPATH 1)
############################################################################
#####
##### Compile hex2tet libraries
#####
############################################################################
OPTION ( LIBHEX2TET_STATIC "Compile the hex2tet static library" OFF)
OPTION ( LIBHEX2TET_SHARED "Compile the hex2tet shared library" OFF)
# Compile static library
IF ( LIBHEX2TET_STATIC )
ADD_AND_INSTALL_LIBRARY ( lib${PROJECT_NAME}_a STATIC
"${library_files}" ${PROJECT_NAME} )
ENDIF()
# Compile shared library
IF ( LIBHEX2TET_SHARED )
ADD_AND_INSTALL_LIBRARY ( lib${PROJECT_NAME}_so SHARED
"${library_files}" ${PROJECT_NAME} )
ENDIF()
# hex2tet header files needed for library
SET( h2t_headers
${H2T_SOURCE_DIR}/libhex2tet.h
${H2T_BUILD_DIR}/libhex2tetf.h
)
# Install header files in /usr/local or equivalent
INSTALL(FILES ${h2t_headers} DESTINATION include/hex2tet COMPONENT headers)
# Copy header files in project directory at every build step
COPY_HEADERS_AND_CREATE_TARGET ( ${H2T_SOURCE_DIR} ${H2T_BUILD_DIR} ${H2T_INCLUDE} hex2tet )
############################################################################
#####
##### Compile program to test library
#####
############################################################################
IF ( TEST_LIBMMG3D )
INCLUDE(cmake/testing/h2t_tests.cmake)
ENDIF()
###############################################################################
#####
##### Compile H2T executable
#####
###############################################################################
ADD_AND_INSTALL_EXECUTABLE ( ${PROJECT_NAME} "${library_files}" ${main_file} )
###############################################################################
#####
##### Create API Documentation
#####
###############################################################################
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
# hex2tet Documentation
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile.in
${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile @ONLY)
ADD_CUSTOM_TARGET(h2t_doc
COMMAND ${DOXYGEN_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile
# COMMAND ${CMAKE_COMMAND} -E chdir
# ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/latex make
# COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/latex/refman.pdf
# ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/
COMMENT "Generating hex2tet API documentation with Doxygen.
Open the doc/doxygen/html/index.html file to see it." VERBATIM
)
ADD_CUSTOM_TARGET(doc
DEPENDS h2t_doc
COMMENT "Generating hex2tet API documentation with Doxygen.
Open the doc/doxygen/html/index.html file to see it" VERBATIM
)
ENDIF ( DOXYGEN_FOUND )
OPTION ( BUILD_TESTING "Enable / Disable tests" OFF )
INCLUDE( ${CMAKE_SOURCE_DIR}/cmake/testing/h2t_tests.cmake )