-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
182 lines (147 loc) · 5.62 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
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_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)
# require MOAB for now
if (XDG_ENABLE_MOAB)
find_package(MOAB REQUIRED HINTS ${MOAB_DIR})
endif()
# 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}")
# 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)
endif()
# argparse
add_subdirectory(vendor/argparse)
list(APPEND xdg_sources
src/geometry/measure.cpp
src/geometry/plucker.cpp
src/geometry/closest.cpp
src/error.cpp
src/mesh_manager_interface.cpp
src/ray_tracing_interface.cpp
src/triangle_intersect.cpp
src/util/str_utils.cpp
src/xdg.cpp
src/overlap_check/overlap.cpp
src/overlap_check/progressBar.cpp
)
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})
# 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()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
target_compile_definitions(xdg PUBLIC XDG_DEBUG)
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>
)
target_link_libraries(xdg embree fmt::fmt)
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(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})