-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
335 lines (277 loc) · 9.89 KB
/
CMakeLists.txt
File metadata and controls
335 lines (277 loc) · 9.89 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
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
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc C CXX)
option(XDG_ENABLE_MOAB "Enable support for the MOAB mesh library" ON)
option(XDG_ENABLE_MFEM "Enable support for the MFEM mesh library" OFF)
option(XDG_ENABLE_LIBMESH "Enable support for the libMesh mesh library" OFF)
option(XDG_LINK_MPI "Link with MPI (for dependency compatibility)" OFF)
option(XDG_ENABLE_EMBREE "Enable support for the Embree ray tracing library" ON)
option(XDG_ENABLE_GPRT "Enable support for the GPRT ray tracing library" OFF)
option(XDG_BUILD_TESTS "Enable C++ unit testing" ON)
option(XDG_BUILD_TOOLS "Enable tools and miniapps" ON)
# Set version numbers
set(XDG_VERSION_MAJOR 0)
set(XDG_VERSION_MINOR 14)
set(XDG_VERSION_RELEASE 1)
set(XDG_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose build type" FORCE)
endif()
# Compiler options (things in this section may not be platform-portable)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set module path
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
#===============================================================================
# libMesh
#===============================================================================
if(XDG_ENABLE_LIBMESH)
find_package(LIBMESH REQUIRED)
endif()
#===============================================================================
# MOAB (DAGMC)
#===============================================================================
if (XDG_ENABLE_MOAB)
find_package(MOAB REQUIRED HINTS ${MOAB_DIR})
if (NOT MOAB_USE_HDF5)
message(FATAL_ERROR "MOAB must be built with HDF5 support for file specifications required by XDG.")
endif()
endif()
if (XDG_ENABLE_EMBREE)
# find Embree for CPU ray tracing
# Because Embree doesn't support version ranges there's a limitation
# that the "requested" major version matches that of the Embree package.
# For version ranges, this appears to go in as the lower bound of the
# version range.
# attempt once for Embree versions between 4 and 5
find_package(embree 4.0.0...<4.1.0 PATHS ${CMAKE_PREFIX_PATH})
# if Embree wasn't found, try again for versions between 3 and 4
if (NOT DEFINED EMBREE_VERSION)
message(WARNING "Could not find an Embree version > v4.0. \nSearching for older versions of Embree...")
find_package(embree 3.0.0...<4.0.0 REQUIRED PATHS ${CMAKE_PREFIX_PATH})
endif()
if (NOT DEFINED EMBREE_VERSION)
message(FATAL_ERROR "Embree package was not found")
endif()
if (NOT ${EMBREE_VERSION} VERSION_GREATER 3.6.0)
message(FATAL_ERROR "XDG requires Embree v3.6.1 or higher.")
endif()
message(STATUS "Found Embree ${EMBREE_VERSION} at ${EMBREE_ROOT_DIR}")
endif()
# Catch2 testing module
if (XDG_BUILD_TESTS)
find_package(Catch2 QUIET NO_SYSTEM_ENVIRONMENT_PATH)
if (NOT Catch2_FOUND)
add_subdirectory("vendor/catch2")
endif()
include(CTest)
endif()
# fmt
find_package(fmt QUIET NO_SYSTEM_ENVIRONMENT_PATH)
if (NOT fmt_FOUND)
set(FMT_INSTALL ON CACHE BOOL "Generate the fmt install target")
add_subdirectory(vendor/fmt)
else()
message(STATUS "Found fmt ${fmt_VERSION} at ${fmt_DIR}")
endif()
# argparse
add_subdirectory(vendor/argparse)
# indicators (progress bars)
# ensure indicators targets are exported and installed
set(INDICATORS_INSTALL ON CACHE STRING "Ensure indicators targets are provided")
add_subdirectory(vendor/indicators)
# Ensure at least one ray tracing backend is enabled
if (NOT XDG_ENABLE_EMBREE AND NOT XDG_ENABLE_GPRT)
message(FATAL_ERROR
"No ray tracing backend enabled. Enable at least one of:\n"
" -DXDG_ENABLE_EMBREE=ON\n"
" -DXDG_ENABLE_GPRT=ON")
endif()
# GPRT
set(GPRT_BUILD_SHARED ON CACHE BOOL "Build GPRT as a shared library" FORCE)
if (XDG_ENABLE_GPRT)
add_subdirectory(vendor/GPRT)
endif()
list(APPEND xdg_sources
src/geometry/measure.cpp
src/geometry/closest.cpp
src/geometry/contain.cpp
src/geometry/plucker.cpp
src/error.cpp
src/mesh_manager_interface.cpp
src/ray_tracing_interface.cpp
src/util/str_utils.cpp
src/overlap_check/overlap.cpp
src/element_face_accessor.cpp
src/config.cpp
src/timer.cpp
src/xdg.cpp
)
if (XDG_ENABLE_EMBREE)
list(APPEND xdg_sources
src/embree/ray_tracer.cpp
src/embree/triangle_intersect.cpp
src/embree/tetrahedron_contain.cpp
)
endif()
if (XDG_ENABLE_GPRT)
list(APPEND xdg_sources
src/gprt/ray_tracer.cpp
)
list(APPEND xdg_device_codes
dbl_deviceCode
)
endif()
if (XDG_ENABLE_LIBMESH)
list(APPEND xdg_sources
src/libmesh/mesh_manager.cpp
)
endif()
if (XDG_ENABLE_MOAB)
list(APPEND xdg_sources
src/moab/mesh_manager.cpp
src/moab/direct_access.cpp
src/moab/metadata.cpp
)
endif()
#===============================================================================
# RPATH information (from OpenMC)
#===============================================================================
# Provide install directory variables as defined by GNU coding standards
include(GNUInstallDirs)
# This block of code ensures that dynamic libraries can be found via the RPATH
# whether the executable is the original one from the build directory or the
# installed one in CMAKE_INSTALL_PREFIX. Ref:
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
add_library(xdg SHARED ${xdg_sources})
target_link_libraries(xdg indicators::indicators)
target_link_libraries(xdg fmt::fmt)
if(XDG_ENABLE_EMBREE)
# pass precompile definition depending on embree version
if (${EMBREE_VERSION} VERSION_GREATER_EQUAL 4.0.0)
target_compile_definitions(xdg PUBLIC XDG_EMBREE4)
else()
target_compile_definitions(xdg PUBLIC XDG_EMBREE3)
endif()
endif()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
target_compile_definitions(xdg PUBLIC XDG_DEBUG)
endif()
target_link_libraries(xdg fmt::fmt)
# attempt to find OpenMP and include it if found
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
target_link_libraries(xdg OpenMP::OpenMP_CXX)
target_compile_definitions(xdg PUBLIC XDG_HAVE_OPENMP)
endif()
if (XDG_BUILD_TESTS)
add_subdirectory("tests")
endif()
if (XDG_BUILD_TOOLS)
add_subdirectory("tools")
endif()
target_include_directories(xdg
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${LIBMESH_INCLUDE_DIRS}
)
if (XDG_ENABLE_MOAB)
target_compile_definitions(xdg PUBLIC XDG_ENABLE_MOAB)
endif()
if (XDG_ENABLE_LIBMESH)
target_compile_definitions(xdg PUBLIC XDG_ENABLE_LIBMESH)
endif()
if (XDG_ENABLE_EMBREE)
target_compile_definitions(xdg PUBLIC XDG_ENABLE_EMBREE)
endif()
if (XDG_ENABLE_GPRT)
target_compile_definitions(xdg PUBLIC XDG_ENABLE_GPRT)
target_link_options(xdg INTERFACE -Wl,--unresolved-symbols=ignore-in-shared-libs)
endif()
# ==========================
# Link ray tracing libraries
# ==========================
if (XDG_ENABLE_EMBREE)
target_link_libraries(xdg embree)
endif()
if (XDG_ENABLE_GPRT)
# Compile device code for each slang file (currently only dbl_deviceCode.slang)
foreach(device_code ${xdg_device_codes})
embed_devicecode(
OUTPUT_TARGET
${device_code}
HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/xdg/gprt/shared_structs.h
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/gprt/${device_code}.slang
)
target_link_libraries(xdg ${device_code})
endforeach()
target_link_libraries(xdg $<BUILD_INTERFACE:gprt>)
endif()
# ===================
# Link mesh libraries
# ===================
if(XDG_ENABLE_LIBMESH)
target_link_libraries(xdg PkgConfig::LIBMESH)
endif()
# this provides the ability to link MPI when needed for compatibility with other
# libraries (e.g., libMesh)
if (XDG_LINK_MPI)
find_package(MPI REQUIRED)
target_link_libraries(xdg MPI::MPI_CXX)
endif()
if (XDG_ENABLE_MOAB)
target_link_libraries(xdg MOAB)
endif()
#=================================================================
# Installation & Packaging
#=================================================================
configure_file(cmake/XDGConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfig.cmake" @ONLY)
configure_file(cmake/XDGConfigVersion.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfigVersion.cmake" @ONLY)
install(TARGETS xdg
EXPORT xdg-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
)
# Install GPRT Targets from shared library
if (TARGET gprt)
install(TARGETS gprt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
# Install targets for each slang file compiled (currently only dbl_deviceCode)
foreach(device_code ${xdg_device_codes})
install(TARGETS ${device_code}
EXPORT xdg-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endforeach()
install(EXPORT xdg-targets
FILE XDGTargets.cmake
NAMESPACE xdg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xdg
)
install(FILES
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfig.cmake"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xdg
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})