-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
421 lines (353 loc) · 12.4 KB
/
Copy pathCMakeLists.txt
File metadata and controls
421 lines (353 loc) · 12.4 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(xdg 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 ${XDG_VERSION_MAJOR}.${XDG_VERSION_MINOR}.${XDG_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()
#===============================================================================
# Update git submodules as needed (borrowed from OpenMC)
#===============================================================================
find_package(Git REQUIRED)
set(VENDOR_PATHS
vendor/linalg
)
# attempt to find external fmt
find_package(fmt QUIET NO_SYSTEM_ENVIRONMENT_PATH)
if(NOT fmt_FOUND)
list(APPEND VENDOR_PATHS vendor/fmt)
endif()
# attempt to find external Catch2
if (XDG_BUILD_TESTS)
find_package(Catch2 QUIET NO_SYSTEM_ENVIRONMENT_PATH)
if(NOT Catch2_FOUND)
list(APPEND VENDOR_PATHS vendor/catch2)
endif()
endif()
if(XDG_BUILD_TESTS)
list(APPEND VENDOR_PATHS
tests/test_files
)
endif()
if(XDG_BUILD_TOOLS)
list(APPEND VENDOR_PATHS
vendor/argparse
vendor/indicators
)
endif()
if(XDG_ENABLE_GPRT)
list(APPEND VENDOR_PATHS
vendor/GPRT
)
endif()
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
option(XDG_GIT_SUBMODULE "Check submodules during build" ON)
if(XDG_GIT_SUBMODULE)
message(STATUS "Submodule update")
foreach(VENDOR_PATH ${VENDOR_PATHS})
message(STATUS "Updating submodule at ${VENDOR_PATH}")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${CMAKE_CURRENT_SOURCE_DIR}/${VENDOR_PATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
message(FATAL_ERROR
"git submodule update --init failed with error code ${GIT_SUBMOD_RESULT}, "
"please checkout submodule at ${VENDOR_PATH} manually and try again.")
endif()
endforeach()
endif()
endif()
foreach(VENDOR_PATH ${VENDOR_PATHS})
file(GLOB _xdg_vendor_readmes "${CMAKE_CURRENT_SOURCE_DIR}/${VENDOR_PATH}/README.*")
if(NOT _xdg_vendor_readmes)
message(FATAL_ERROR
"The vendored dependency at ${VENDOR_PATH} is missing. "
"Expected a README.* file. Please update submodules and try again.")
endif()
endforeach()
# Catch2 testing module
if (XDG_BUILD_TESTS)
if (NOT Catch2_FOUND)
add_subdirectory("vendor/catch2")
endif()
include(CTest)
include(Catch)
message(STATUS "Using Catch2 ${Catch2_VERSION} at ${Catch2_DIR}")
endif()
# fmt
if (NOT fmt_FOUND)
set(FMT_INSTALL OFF CACHE BOOL "Generate the fmt install target")
add_subdirectory(vendor/fmt)
endif()
message(STATUS "Using fmt ${fmt_VERSION} at ${fmt_DIR}")
if(XDG_BUILD_TOOLS)
# argparse
add_subdirectory(${CMAKE_SOURCE_DIR}/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(${CMAKE_SOURCE_DIR}/vendor/indicators)
endif()
# Ensure at least one mesh backend is enabled
if (NOT XDG_ENABLE_MOAB AND NOT XDG_ENABLE_LIBMESH)
message(FATAL_ERROR
"No mesh backend enabled. Enable at least one of:\n"
" -DXDG_ENABLE_MOAB=ON\n"
" -DXDG_ENABLE_LIBMESH=ON")
endif()
# 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/plucker.cpp
src/geometry/closest.cpp
src/bounding_functions.cpp
src/error.cpp
src/intersect_common.cpp
src/mesh_manager_interface.cpp
src/ray_tracing_interface.cpp
src/triangle_intersect.cpp
src/quadrilateral_intersection.cpp
src/util/str_utils.cpp
src/tetrahedron_contain.cpp
src/hexahedron_contain.cpp
src/config.cpp
src/xdg.cpp
src/element_face_accessor.cpp
src/timer.cpp
src/xdg.cpp
)
if (XDG_ENABLE_EMBREE)
list(APPEND xdg_sources
src/embree/ray_tracer.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
# MOAB
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})
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()
# attempt to find OpenMP and include it if found
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
target_link_libraries(xdg PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(xdg PRIVATE 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 PRIVATE -Wl,--unresolved-symbols=ignore-in-shared-libs)
endif()
target_link_libraries(xdg PRIVATE fmt::fmt)
# ==========================
# Link ray tracing libraries
# ==========================
if (XDG_ENABLE_EMBREE)
target_link_libraries(xdg PRIVATE 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
${CMAKE_CURRENT_SOURCE_DIR}/include/xdg/shared_enums.h
${CMAKE_CURRENT_SOURCE_DIR}/include/xdg/geometry/dp_math.h
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/gprt/${device_code}.slang
)
target_link_libraries(xdg PRIVATE ${device_code})
endforeach()
target_link_libraries(xdg PRIVATE $<BUILD_INTERFACE:gprt>)
endif()
# ===================
# Link mesh libraries
# ===================
if(XDG_ENABLE_LIBMESH)
target_link_libraries(xdg PRIVATE 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 PRIVATE MPI::MPI_CXX)
endif()
if (XDG_ENABLE_MOAB)
target_link_libraries(xdg PRIVATE 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})
if (NOT fmt_FOUND)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/vendor/fmt/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()