-
Notifications
You must be signed in to change notification settings - Fork 65
/
DAGMC_macros.cmake
354 lines (301 loc) · 13.3 KB
/
DAGMC_macros.cmake
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
macro (dagmc_setup_build)
message("")
# All DAGMC libraries
set(DAGMC_LIBRARY_LIST dagmc pyne_dagmc uwuw dagtally makeWatertight dagsolid fludag)
# Keep track of which libraries are installed
set(DAGMC_LIBRARIES MOAB CACHE INTERNAL "DAGMC_LIBRARIES")
# Default to a release build
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_BUILD_TYPE not specified, defaulting to Release")
set(CMAKE_BUILD_TYPE Release)
endif ()
if (NOT CMAKE_BUILD_TYPE STREQUAL "Release" AND
NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND
NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(FATAL_ERROR "Specified CMAKE_BUILD_TYPE is invalid; valid options are Release, Debug, RelWithDebInfo")
endif ()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
# Installation directories
set(INSTALL_BIN_DIR bin)
set(INSTALL_LIB_DIR lib)
set(INSTALL_INCLUDE_DIR include)
set(INSTALL_TESTS_DIR tests)
set(INSTALL_TOOLS_DIR tools)
set(INSTALL_SHARE_DIR share)
# Get some environment variables
set(ENV_USER "$ENV{USER}")
execute_process(COMMAND hostname OUTPUT_VARIABLE ENV_HOST OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -s OUTPUT_VARIABLE ENV_OS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND date +%m/%d/%y OUTPUT_VARIABLE ENV_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND date +%H:%M:%S OUTPUT_VARIABLE ENV_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
endmacro ()
macro (dagmc_setup_options)
message("")
option(BUILD_MCNP5 "Build DAG-MCNP5" OFF)
option(BUILD_MCNP6 "Build DAG-MCNP6" OFF)
option(BUILD_MCNP_PLOT "Build DAG-MCNP5/6 with plotting support" OFF)
option(BUILD_MCNP_OPENMP "Build DAG-MCNP5/6 with OpenMP support" OFF)
option(BUILD_MCNP_MPI "Build DAG-MCNP5/6 with MPI support" OFF)
option(BUILD_MCNP_PYNE_SOURCE "Build DAG-MCNP5/6 with PyNE mesh source support" OFF)
option(BUILD_GEANT4 "Build DAG-Geant4" OFF)
option(WITH_GEANT4_UIVIS "Build DAG-Geant4 with visualization support" ${BUILD_GEANT4})
option(BUILD_FLUKA "Build FluDAG" OFF)
option(BUILD_UWUW "Build UWUW library and uwuw_preproc" ON)
option(BUILD_TALLY "Build dagtally library" ON)
option(BUILD_BUILD_OBB "Build build_obb tool" ON)
option(BUILD_MAKE_WATERTIGHT "Build make_watertight tool" ON)
option(BUILD_OVERLAP_CHECK "Build overlap_check tool" ON)
option(BUILD_TESTS "Build unit tests" ON)
option(BUILD_CI_TESTS "Build everything needed to run the CI tests" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(BUILD_EXE "Build DAGMC executables" ON)
option(BUILD_STATIC_EXE "Build static executables" OFF)
option(BUILD_PIC "Build with PIC" OFF)
option(BUILD_RPATH "Build libraries and executables with RPATH" ON)
option(DOUBLE_DOWN "Enable ray tracing with Embree via double down" OFF)
if (BUILD_ALL)
set(BUILD_MCNP5 ON)
set(BUILD_MCNP6 ON)
set(BUILD_GEANT4 ON)
set(BUILD_FLUKA ON)
endif ()
if (DOUBLE_DOWN AND BUILD_STATIC_LIBS)
message(WARNING "DOUBLE_DOWN is enabled but will only be applied to the shared DAGMC library")
endif()
if (DOUBLE_DOWN AND BUILD_STATIC_EXE)
message(WARNING "DOUBLE_DOWN is enabled but will only be applied to executables using the DAGMC shared library")
endif()
if (DOUBLE_DOWN)
find_package(DOUBLE_DOWN REQUIRED)
if (dd_VERSION VERSION_LESS 1.1.0)
message(FATAL_ERROR "Discovered Double Down Version: ${DOUBLE_DOWN_VERSION}. \
Please update Double Down to version 1.1.0 or greater.")
endif()
endif()
if (NOT BUILD_STATIC_LIBS AND BUILD_STATIC_EXE)
message(FATAL_ERROR "BUILD_STATIC_EXE cannot be ON while BUILD_STATIC_LIBS is OFF")
endif ()
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS and BUILD_STATIC_LIBS cannot both be OFF")
endif ()
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_EXE AND BUILD_EXE)
SET(BUILD_EXE OFF)
message("Turning BUILD_EXE OFF: SHARED_BUILD_LIBS and BUILD_STATIC_EXE are OFF")
endif ()
endmacro ()
macro (dagmc_setup_flags)
message("")
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
if (BUILD_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()
set(CXX_LIBRARY)
foreach (library IN LISTS CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
if (library MATCHES "c\\+\\+")
set(CXX_LIBRARY ${library})
break()
endif ()
endforeach ()
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "${CXX_LIBRARY}")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "")
if (BUILD_EXE)
if (BUILD_STATIC_EXE)
message(STATUS "Building static executables")
set(BUILD_SHARED_EXE OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
if(NOT MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
if(NOT MSVC)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_Fortran_FLAGS)
endif()
else ()
message(STATUS "Building shared executables")
set(BUILD_SHARED_EXE ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif ()
endif ()
if (BUILD_RPATH)
if (CMAKE_INSTALL_RPATH)
set(INSTALL_RPATH_DIRS "${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}")
else ()
set(INSTALL_RPATH_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}")
endif ()
message(STATUS "INSTALL_RPATH_DIRS: ${INSTALL_RPATH_DIRS}")
endif ()
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}")
message(STATUS "CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}: ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
message(STATUS "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}: ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
message(STATUS "CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE_UPPER}: ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
message(STATUS "CMAKE_C_IMPLICIT_LINK_LIBRARIES: ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}")
message(STATUS "CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
message(STATUS "CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES: ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
endmacro ()
# Figure out what LINK_LIBS_SHARED and LINK_LIBS_STATIC should be based on the
# values of LINK_LIBS and LINK_LIBS_EXTERN_NAMES
macro (dagmc_get_link_libs)
set(LINK_LIBS_SHARED)
set(LINK_LIBS_STATIC)
foreach (extern_name IN LISTS LINK_LIBS_EXTERN_NAMES)
list(APPEND LINK_LIBS_SHARED ${${extern_name}_SHARED})
list(APPEND LINK_LIBS_STATIC ${${extern_name}_STATIC})
endforeach ()
foreach (link_lib IN LISTS LINK_LIBS)
list(FIND DAGMC_LIBRARY_LIST ${link_lib} index)
if (index STREQUAL "-1")
list(APPEND LINK_LIBS_SHARED ${link_lib})
list(APPEND LINK_LIBS_STATIC ${link_lib})
else ()
list(APPEND LINK_LIBS_SHARED ${link_lib}-shared)
list(APPEND LINK_LIBS_STATIC ${link_lib}-static)
endif ()
endforeach ()
endmacro ()
# Setup the configuration file and install
macro (dagmc_make_configure_files)
message("")
message(STATUS "DAGMC cmake config file: ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}/cmake/dagmc/DAGMCConfig.cmake")
message(STATUS "DAGMC cmake version file: ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}/cmake/dagmc/DAGMCConfigVersion.cmake")
configure_file(cmake/DAGMCConfig.cmake.in DAGMCConfig.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DAGMCConfig.cmake DESTINATION ${INSTALL_LIB_DIR}/cmake/dagmc/)
configure_file(cmake/DAGMCConfigVersion.cmake.in DAGMCConfigVersion.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DAGMCConfigVersion.cmake DESTINATION ${INSTALL_LIB_DIR}/cmake/dagmc)
install(EXPORT DAGMCTargets DESTINATION ${INSTALL_LIB_DIR}/cmake/dagmc)
endmacro ()
# To use the dagmc_install macros, the following lists must be defined:
# SRC_FILES: source files
# PUB_HEADERS: public header files
# LINK_LIBS: e.g. dagmc, pyne_dagmc, uwuw, lapack, gfortran
# LINK_LIBS_EXTERN_NAMES: e.g. MOAB_LIBRARIES
# Install a library in both shared and static mode
macro (dagmc_install_library lib_name)
message(STATUS "Building library: ${lib_name}")
dagmc_get_link_libs()
if (BUILD_SHARED_LIBS)
add_library(${lib_name}-shared SHARED ${SRC_FILES})
set_target_properties(${lib_name}-shared
PROPERTIES OUTPUT_NAME ${lib_name}
PUBLIC_HEADER "${PUB_HEADERS}")
if (BUILD_RPATH)
set_target_properties(${lib_name}-shared
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
endif ()
message(STATUS "LINK LIBS: ${LINK_LIBS_SHARED}")
target_link_libraries(${lib_name}-shared PUBLIC ${LINK_LIBS_SHARED})
if (DOUBLE_DOWN)
target_compile_definitions(${lib_name}-shared PRIVATE DOUBLE_DOWN)
target_link_libraries(${lib_name}-shared PUBLIC dd)
endif()
target_include_directories(${lib_name}-shared INTERFACE $<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
${MOAB_INCLUDE_DIRS})
install(TARGETS ${lib_name}-shared
EXPORT DAGMCTargets
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
endif ()
if (BUILD_STATIC_LIBS)
add_library(${lib_name}-static STATIC ${SRC_FILES})
set_target_properties(${lib_name}-static
PROPERTIES OUTPUT_NAME ${lib_name}
PUBLIC_HEADER "${PUB_HEADERS}")
if (BUILD_RPATH)
set_target_properties(${lib_name}-static
PROPERTIES INSTALL_RPATH "" INSTALL_RPATH_USE_LINK_PATH FALSE)
endif ()
target_link_libraries(${lib_name}-static ${LINK_LIBS_STATIC})
target_include_directories(${lib_name}-static INTERFACE $<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
${MOAB_INCLUDE_DIRS})
install(TARGETS ${lib_name}-static
EXPORT DAGMCTargets
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
endif ()
# Keep a list of all libraries being installed
set(DAGMC_LIBRARIES ${DAGMC_LIBRARIES} ${lib_name} CACHE INTERNAL "DAGMC_LIBRARIES")
endmacro ()
# Install an executable
macro (dagmc_install_exe exe_name)
if (NOT BUILD_EXE)
message(STATUS "Skipping executable ${exe_name} build")
else ()
message(STATUS "Building executable: ${exe_name}")
dagmc_get_link_libs()
add_executable(${exe_name} ${SRC_FILES})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
endif ()
else ()
if (BUILD_STATIC_EXE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
else ()
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
endif ()
endif ()
install(TARGETS ${exe_name} DESTINATION ${INSTALL_BIN_DIR})
endif ()
endmacro ()
# Install a unit test
macro (dagmc_install_test test_name ext)
if (NOT BUILD_EXE)
message(STATUS "Skipping unit tests ${test_name} build.")
else ()
message(STATUS "Building unit tests: ${test_name}")
list(APPEND LINK_LIBS gtest)
dagmc_get_link_libs()
add_executable(${test_name} ${test_name}.${ext} ${DRIVERS})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
endif ()
else ()
if (BUILD_STATIC_EXE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
else ()
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
endif ()
endif ()
install(TARGETS ${test_name} DESTINATION ${INSTALL_TESTS_DIR})
add_test(NAME ${test_name} COMMAND ${test_name})
set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=''")
endif ()
endmacro ()
# Install a file needed for unit testing
macro (dagmc_install_test_file filename)
install(FILES ${filename} DESTINATION ${INSTALL_TESTS_DIR})
configure_file(${CMAKE_CURRENT_LIST_DIR}/${filename} ${CMAKE_CURRENT_BINARY_DIR}/${filename} COPYONLY)
endmacro ()