forked from Devsh-Graphics-Programming/Nabla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·306 lines (247 loc) · 10.4 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
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
# Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
# This file is part of the "Nabla Engine".
# For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h
cmake_minimum_required(VERSION 3.20)
#policies
cmake_policy(SET CMP0072 OLD) #not yet, would need to get pointers to all OpenGL functions
set(OpenGL_GL_PREFERENCE LEGACY)
#cmake_policy(SET CMP )
set(NBL_BUILD_ANDROID OFF)
include(ExternalProject)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchains/android/build.cmake)
project(Nabla LANGUAGES CXX C)
if(NBL_BUILD_ANDROID)
enable_language(ASM)
endif()
find_package(Vulkan)
if (Vulkan_FOUND)
message(STATUS "Building with Vulkan driver")
else()
message(STATUS "Vulkan driver is not enabled")
endif()
option(NBL_COMPILE_WITH_CUDA "Compile with CUDA interop?" OFF)
# CUDA test
include(CheckLanguage)
check_language(CUDA)
#if(NOT CMAKE_CUDA_COMPILER OR CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "9.0")
if(NOT CMAKE_CUDA_COMPILER)
if (NBL_COMPILE_WITH_CUDA)
#message(WARNING "CUDA not found or version (${CMAKE_CUDA_COMPILER_VERSION}) lower than 9.0 found, version 9.0+ needed for C++14 support.")
message(WARNING "CUDA not found.")
endif()
else()
if (NBL_COMPILE_WITH_CUDA)
enable_language(CUDA)
else()
message(STATUS "CUDA version 9.0+ found, you can enable the NBL_COMPILE_WITH_CUDA option.")
endif()
endif()
get_filename_component(NBL_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(NBL_ROOT_PATH_BINARY "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE)
# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
option(USE_CCACHE "Some dependency is using it, but I just don't know which!" ON)
else(CCACHE_FOUND)
option(USE_CCACHE "Some dependency is using it, but I just don't know which!" OFF)
endif(CCACHE_FOUND)
if(USE_CCACHE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(USE_CCACHE)
# global IDE stuff for examples
set(CMAKE_CODELITE_USE_TARGETS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Cause CUDA is a special snowflake
if (NBL_COMPILE_WITH_CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11, but is it really needed?
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;")
set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "Nabla developer note: No idea what subfolder provides this")
set(LLVM_USE_CRT_RELEASE MT CACHE STRING "Nabla developer note: No idea what subfolder provides this")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type: Debug or Release" FORCE)
endif()
if (DEFINED ENV{NUMBER_OF_PROCESSORS})
set(NBL_PARALLEL_BUILD_JOBS $ENV{NUMBER_OF_PROCESSORS})
else()
set(NBL_PARALLEL_BUILD_JOBS 8)
endif()
macro(nbl_adjust_flags)
option(NBL_SANITIZE_ADDRESS OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
option(NBL_SANITIZE_THREAD OFF)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
-Wextra
-Wno-unused-parameter
-fno-strict-aliasing
-msse4.2
-mfpmath=sse
-Wextra
-Wno-sequence-point
-Wno-error=ignored-attributes
-Wno-error=unused-function
-Wno-error=unused-variable
-Wno-error=unused-parameter
$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:-maes>
$<$<CONFIG:DEBUG>:-Wall>
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
$<$<CONFIG:DEBUG>:-fstack-protector-strong>
)
if(ANDROID)
add_compile_options(
$<$<CONFIG:DEBUG>:-glldb>
)
function(NBL_INSERT_ANDROID_FLAGS _NBL_CMAKE_FLAGS_VARIABLE_NAME_)
string(FIND "${${_NBL_CMAKE_FLAGS_VARIABLE_NAME_}}" "-g -glldb" CHECK)
if(${CHECK} EQUAL -1)
set(${_NBL_CMAKE_FLAGS_VARIABLE_NAME_} "${${_NBL_CMAKE_FLAGS_VARIABLE_NAME_}} -g -glldb" CACHE STRING "" FORCE)
endif()
endfunction()
NBL_INSERT_ANDROID_FLAGS(CMAKE_ASM_FLAGS_DEBUG)
NBL_INSERT_ANDROID_FLAGS(CMAKE_CXX_FLAGS_DEBUG)
NBL_INSERT_ANDROID_FLAGS(CMAKE_C_FLAGS_DEBUG)
NBL_INSERT_ANDROID_FLAGS(CMAKE_EXE_LINKER_FLAGS_DEBUG)
NBL_INSERT_ANDROID_FLAGS(CMAKE_MODULE_LINKER_FLAGS_DEBUG)
NBL_INSERT_ANDROID_FLAGS(CMAKE_SHARED_LINKER_FLAGS_DEBUG)
else()
add_compile_options(
$<$<CONFIG:DEBUG>:-ggdb3>
)
endif()
add_compile_options(-fno-exceptions)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
-Wno-unused-but-set-parameter
$<$<CONFIG:RELEASE>:-fexpensive-optimizations>
)
endif()
if (NBL_SANITIZE_ADDRESS)
add_compile_options(-fsanitize=address)
endif()
if (NBL_SANITIZE_THREAD)
add_compile_options(-fsanitize=thread)
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.1)
add_compile_options(-Wno-error=ignored-attributes)
endif()
# https://github.com/android/ndk/issues/1426
if (NOT ANDROID)
link_libraries(
-fuse-ld=gold
)
endif()
if(FAST_MATH)
add_compile_options(
$<$<CONFIG:RELEASE>:-ffast-math>
)
endif()
elseif(MSVC) # /arch:sse3 or anything like this is not needed on x64 on MSVC for enabling sse3 instructions
if (NBL_SANITIZE_ADDRESS)
set(NBL_MSVC_FLAG_SANITIZE_ADDRESS "/fsanitize=address")
message(WARNING "Due to https://github.com/google/sanitizers/issues/328 expect not to be able to use the Debug target!")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /wholearchive:clang_rt.asan_dbg-x86_64.lib /wholearchive:clang_rt.asan_cxx_dbg-x86_64.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /wholearchive:clang_rt.asan-x86_64.lib /wholearchive:clang_rt.asan_cxx-x86_64.lib")
endif()
# debug
string(REPLACE "/W3" "/W0" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zc:__cplusplus /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL ${NBL_MSVC_SANITIZE_ADDRESS}" )
string(REPLACE "/W3" "/W0" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL ${NBL_MSVC_SANITIZE_ADDRESS}")
# release
string(REPLACE "/GS" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") # for some reason simply replacing /GS -> /GS- doesn't work... so it vanishes here and appears a few lines below!
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Zc:__cplusplus /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
string(REPLACE "/GS" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
# relWithDebInfo
string(REPLACE "/GS" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL /Zc:__cplusplus /Zc:wchar_t /MP /Gy /Zi /sdl- /Oy- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
string(REPLACE "/GS" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /GL /MP /Gy /Zc:wchar_t /Zi /sdl- /Oy- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
#reason for INCREMENTAL:NO: https://docs.microsoft.com/en-us/cpp/build/reference/ltcg-link-time-code-generation?view=vs-2019 /LTCG is not valid for use with /INCREMENTAL.
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO /LTCG:incremental")
else()
message(WARNING "UNTESTED COMPILER DETECTED, EXPECT WRONG OPTIMIZATION FLAGS! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues")
endif()
endmacro()
macro(nbl_adjust_definitions)
add_compile_definitions(
PNG_THREAD_UNSAFE_OK
PNG_NO_MMX_CODE
PNG_NO_MNG_FEATURES
_7ZIP_ST
SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
)
if(ANDROID)
add_compile_definitions(
NBL_ANDROID_TOOLCHAIN
)
endif()
if(WIN32)
add_compile_definitions(
WIN32
__GNUWIN32__
_CRT_SECURE_NO_DEPRECATE
NOMINMAX
)
endif()
endmacro()
if(WIN32)
set(_NBL_PLATFORM_WINDOWS_ 1)
elseif(ANDROID)
set(_NBL_PLATFORM_ANDROID_ 1)
elseif(UNIX)
set(_NBL_PLATFORM_LINUX_ 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif()
#uncomment in the future
#option(NBL_TARGET_ARCH_ARM "Build for ARM?" OFF)
option(NBL_COMPILE_WITH_OPENGL "Compile with OpenGL backend?" ON)
option(NBL_COMPILE_WITH_OPENCL "Compile with OpenCL interop?" ON)
option(NBL_PCH "Enable pre-compiled header" ON)
option(NBL_FAST_MATH "Enable fast low-precision math" ON)
option(NBL_BUILD_EXAMPLES "Enable building examples" ON)
option(NBL_BUILD_TOOLS "Enable building tools (just convert2BAW as for now)" ON)
option(NBL_BUILD_MITSUBA_LOADER "Enable nbl::ext::MitsubaLoader?" ON)
option(NBL_BUILD_RADEON_RAYS "Enable nbl::ext::RadeonRays?" OFF)
if (NBL_COMPILE_WITH_CUDA)
find_package(OPTIX)
if (OPTIX_FOUND)
message(STATUS "CUDA and OptiX found, you can enable NBL_BUILD_OPTIX")
else()
message(STATUS "OptiX not found")
endif()
option(NBL_BUILD_OPTIX "Enable nbl::ext::OptiX?" OFF)
else()
message(STATUS "Because NBL_COMPILE_WITH_CUDA is not enabled, the NBL_BUILD_OPTIX option will be hidden.")
endif()
option(NBL_BUILD_BULLET "Enable Bullet Physics building and integration?" OFF)
option(NBL_BUILD_DOCS "Enable building documentation?" OFF) # No one has doxygen installed, plus we dont know when was the last time we generated working doxy and we'll use SphinX in the future
set(THIRD_PARTY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/3rdparty")
set(THIRD_PARTY_BINARY_DIR "${PROJECT_BINARY_DIR}/3rdparty")
if(NBL_UPDATE_GIT_SUBMODULE)
execute_process(COMMAND git submodule init
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
execute_process(COMMAND git submodule sync --recursive
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
add_subdirectory(${THIRD_PARTY_SOURCE_DIR})
OPTION(NBL_EMBED_BUILTIN_RESOURCES "Embed built-in resources?" ON)
add_subdirectory(src/nbl) # Nabla code | Moved cmakelists.txt from source/Nabla to src/nbl
if(NBL_BUILD_TOOLS)
add_subdirectory(tools) # convert2BAW
endif()
if(NBL_BUILD_EXAMPLES)
add_subdirectory(examples_tests)
endif()
if(NBL_BUILD_DOCS)
add_subdirectory(docs)
endif()
add_subdirectory(artifacts)
export(TARGETS ${_NBL_3RDPARTY_TARGETS_} Nabla NAMESPACE Nabla:: APPEND FILE ${NBL_ROOT_PATH_BINARY}/NablaExport.cmake)