forked from njroussel/drjit-fork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
265 lines (222 loc) · 9.42 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
cmake_minimum_required(VERSION 3.13...3.22)
project(drjit
DESCRIPTION
"Dr.Jit"
LANGUAGES
CXX
)
if (APPLE)
set(DRJIT_ENABLE_CUDA_DEFAULT OFF)
else()
set(DRJIT_ENABLE_CUDA_DEFAULT ON)
endif()
option(DRJIT_ENABLE_LLVM "Build the Dr.Jit LLVM backend?" ON)
option(DRJIT_ENABLE_CUDA "Build the Dr.Jit CUDA backend?" ${DRJIT_ENABLE_CUDA_DEFAULT})
option(DRJIT_ENABLE_AUTODIFF "Build Dr.Jit automatic differentation library?" ON)
option(DRJIT_ENABLE_PYTHON "Build Python extension library?" ON)
option(DRJIT_ENABLE_TESTS "Build Dr.Jit test suite? (Warning, this takes *very* long to compile)" OFF)
if (NOT MSVC)
option(DRJIT_SANITIZE_UBSAN "Enable the address sanitizer (GCC, Clang)" OFF)
option(DRJIT_SANITIZE_ASAN "Enable the undefined behavior sanitizer (GCC, Clang)" OFF)
option(DRJIT_SANITIZE_INTENSE "Add costly internal instrumentation to catch undefined behavior." OFF)
endif()
# ----------------------------------------------------------
# Check if submodules have been checked out, or fail early
# ----------------------------------------------------------
if (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ext/drjit-core/ext/nanothread/ext/cmake-defaults")
message(FATAL_ERROR "The Dr.Jit dependencies are missing! "
"You probably did not clone the project with --recursive. It is possible to recover "
"by invoking\n$ git submodule update --init --recursive")
endif()
set(DRJIT_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/drjit/fwd.h")
include(ext/drjit-core/ext/nanothread/ext/cmake-defaults/CMakeLists.txt)
if (SKBUILD)
set(CMAKE_INSTALL_DATAROOTDIR drjit)
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_DATAROOTDIR}/include)
endif()
if (MSVC)
set(DRJIT_OUTPUT_DIRECTORY
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/drjit
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/drjit
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_BINARY_DIR}/drjit
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_CURRENT_BINARY_DIR}/drjit
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/drjit
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/drjit
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_BINARY_DIR}/drjit
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_CURRENT_BINARY_DIR}/drjit
)
else()
set(DRJIT_OUTPUT_DIRECTORY
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/drjit)
endif()
add_library(drjit INTERFACE)
target_compile_features(drjit INTERFACE cxx_std_17)
target_include_directories(drjit
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ext/drjit-core/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ext/drjit-core/ext/nanothread/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
target_compile_options(drjit INTERFACE -fno-strict-aliasing)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0.0 AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0.5)
message(FATAL_ERROR "Clang versions 14.0.0 to 14.0.4 miscompile Dr.Jit. Please use either a newer (14.0.5+) or older (e.g., 13.x) version. On Ubuntu, you can use the LLVM project's package server (https://apt.llvm.org) to get the latest version.")
endif()
endif()
if (DRJIT_MASTER_PROJECT)
if (APPLE)
set(DRJIT_ORIGIN "@loader_path")
elseif(UNIX)
set(DRJIT_ORIGIN "$ORIGIN")
endif()
set(CMAKE_INSTALL_RPATH "${DRJIT_ORIGIN}")
endif()
if (DRJIT_ENABLE_CUDA)
set(DRJIT_ENABLE_JIT TRUE)
message(STATUS "Dr.Jit: building the CUDA backend.")
else()
message(STATUS "Dr.Jit: *not* building the CUDA backend.")
endif()
if (DRJIT_ENABLE_LLVM)
set(DRJIT_ENABLE_JIT TRUE)
message(STATUS "Dr.Jit: building the LLVM backend.")
else()
message(STATUS "Dr.Jit: *not* building the LLVM backend.")
endif()
if (DRJIT_ENABLE_JIT)
add_subdirectory(ext/drjit-core)
set_target_properties(drjit-core PROPERTIES ${DRJIT_OUTPUT_DIRECTORY})
set_target_properties(nanothread PROPERTIES ${DRJIT_OUTPUT_DIRECTORY})
endif()
mark_as_advanced(NANOTHREAD_ENABLE_TESTS)
mark_as_advanced(DRJIT_CORE_ENABLE_TESTS)
mark_as_advanced(NB_TEST NB_TEST_SHARED_BUILD NB_TEST_STABLE_ABI NB_USE_SUBMODULE_DEPS NB_TEST_SANITZE NB_CREATE_INSTALL_RULES nanobind_DIR)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# In case Clang is used, avoid header file bloat from transitive
# includes. Ignored if Clang is used together with libstdc++.
add_compile_options(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
endif()
if (MSVC)
add_compile_options(/wd4251) # "warning C4251: X needs to have dll-interface to be used by clients of struct Y"
add_compile_options(/wd4127) # "warning C4127 : conditional expression is constant, consider using 'if constexpr' statement instead"
endif()
if (DRJIT_ENABLE_JIT)
add_subdirectory(src/extra)
set_target_properties(drjit-extra PROPERTIES ${DRJIT_OUTPUT_DIRECTORY})
# install(TARGETS drjit-extra EXPORT drjitTargets)
endif()
if (DRJIT_ENABLE_PYTHON)
message(STATUS "Dr.Jit: building the Python plugin.")
add_subdirectory(src/python)
else()
message(STATUS "Dr.Jit: *not* building the Python plugin.")
endif()
if (DRJIT_ENABLE_TESTS)
if (NOT DRJIT_ENABLE_PYTHON)
message(FATAL_ERROR "The test suite requires the Python plugin to be built.")
endif()
add_subdirectory(tests)
endif()
if (DRJIT_SANITIZE_UBSAN)
list(APPEND DRJIT_SANITIZE "undefined")
endif()
if (DRJIT_SANITIZE_ASAN)
list(APPEND DRJIT_SANITIZE "address")
endif()
if (DRJIT_SANITIZE_INTENSE)
target_compile_definitions(drjit-core PRIVATE -DDRJIT_SANITIZE_INTENSE)
target_compile_definitions(drjit-extra PRIVATE -DDRJIT_SANITIZE_INTENSE)
endif()
if (DRJIT_SANITIZE)
string (REPLACE ";" "," DRJIT_SANITIZE "${DRJIT_SANITIZE}")
target_compile_options(drjit INTERFACE -fsanitize=${DRJIT_SANITIZE})
target_link_options (drjit INTERFACE -fsanitize=${DRJIT_SANITIZE})
target_compile_options(drjit-core PRIVATE -fsanitize=${DRJIT_SANITIZE})
target_link_options (drjit-core PRIVATE -fsanitize=${DRJIT_SANITIZE})
endif()
# Build the documentation
if (DRJIT_MASTER_PROJECT)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/resources)
find_package(Sphinx)
if (Sphinx_FOUND)
set(SPHINX_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/docs")
set(SPHINX_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
add_custom_target(mkdoc
${CMAKE_COMMAND} -E env PYTHONPATH="${CMAKE_CURRENT_BINARY_DIR}" ${SPHINX_EXECUTABLE} -b html "${SPHINX_INPUT_DIR}" "${SPHINX_OUTPUT_DIR}"
COMMENT "Building HTML documentation with Sphinx"
USES_TERMINAL)
endif()
endif()
if (DRJIT_MASTER_PROJECT)
install(DIRECTORY include/drjit DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS drjit-core EXPORT drjitTargets DESTINATION drjit)
install(TARGETS drjit-extra EXPORT drjitTargets DESTINATION drjit)
install(TARGETS nanothread EXPORT drjitTargets DESTINATION drjit)
if (DRJIT_ENABLE_PYTHON)
install(TARGETS drjit-python DESTINATION drjit)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/drjit/config.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/__init__.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/interop.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/interop.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/ast.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/ast.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/detail.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/detail.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/py.typed
DESTINATION drjit
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/drjit/scalar/__init__.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/scalar/__init__.py
DESTINATION drjit/scalar
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/drjit/llvm/py.typed
${CMAKE_CURRENT_BINARY_DIR}/drjit/llvm/__init__.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/llvm/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/llvm/ad.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/llvm/ad.py
DESTINATION drjit/llvm
)
if (DRJIT_ENABLE_CUDA)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/drjit/cuda/py.typed
${CMAKE_CURRENT_BINARY_DIR}/drjit/cuda/__init__.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/cuda/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/drjit/cuda/ad.pyi
${CMAKE_CURRENT_BINARY_DIR}/drjit/cuda/ad.py
DESTINATION drjit/cuda
)
endif()
endif()
if (DRJIT_ENABLE_JIT)
install(DIRECTORY ext/drjit-core/include/drjit-core DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ext/drjit-core/ext/nanothread/include/nanothread DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
install(TARGETS drjit EXPORT drjitTargets)
set(DRJIT_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/cmake/drjit")
configure_package_config_file(
resources/drjitConfig.cmake.in drjitConfig.cmake
INSTALL_DESTINATION ${DRJIT_CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(
drjitConfigVersion.cmake
VERSION ${DRJIT_VERSION}
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
install(
EXPORT drjitTargets
DESTINATION ${DRJIT_CMAKECONFIG_INSTALL_DIR})
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/drjitConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/drjitConfig.cmake
DESTINATION ${DRJIT_CMAKECONFIG_INSTALL_DIR})
endif()
mark_as_advanced(
CMAKE_EXECUTABLE_FORMAT CMAKE_OSX_ARCHITECTURES
)