forked from Devsh-Graphics-Programming/Nabla
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
262 lines (210 loc) · 8.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
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
# Copyright (c) 2019 DevSH Graphics Programming Sp. z O.O.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.16)
#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 )
project(Irrlicht LANGUAGES CXX C)
find_package(Vulkan)
if (Vulkan_FOUND)
message(STATUS "Building with Vulkan driver")
else()
message(STATUS "Vulkan driver is not enabled")
endif()
option(IRR_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 (IRR_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 (IRR_COMPILE_WITH_CUDA)
enable_language(CUDA)
else()
message(STATUS "CUDA version 9.0+ found, you can enable the IRR_COMPILE_WITH_CUDA option.")
endif()
endif()
#
get_filename_component(IRR_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
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)
# global IDE stuff for examples
set(CMAKE_CODELITE_USE_TARGETS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Cause CUDA is a special snowflake
if (IRR_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 "IrrBAW developer note: No idea what subfolder provides this")
set(LLVM_USE_CRT_RELEASE MT CACHE STRING "IrrBAW developer note: No idea what subfolder provides this")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
endif()
if (DEFINED ENV{NUMBER_OF_PROCESSORS})
set(IRR_PARALLEL_BUILD_JOBS $ENV{NUMBER_OF_PROCESSORS})
else()
set(IRR_PARALLEL_BUILD_JOBS 8)
endif()
macro(irr_adjust_flags)
option(IRR_GCC_SANITIZE_ADDRESS OFF)
option(IRR_GCC_SANITIZE_THREAD OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (NOT IRR_BUILD_CEGUI)
add_compile_options(-fno-exceptions)
endif()
add_compile_options(
-Wextra
-Wno-unused-parameter
-Wno-unused-but-set-parameter
-fno-strict-aliasing
-msse4.2
-mfpmath=sse
-fuse-ld=gold
-Wextra
-Wno-sequence-point
-Wno-error=ignored-attributes
-Wno-error=unused-function
-Wno-error=unused-variable
-Wno-error=unused-parameter
#"$<$<CONFIG:DEBUG>:-g>" # same as with -O3 below
"$<$<CONFIG:DEBUG>:-Wall>"
"$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>"
"$<$<CONFIG:DEBUG>:-fstack-protector-strong>"
#"$<$<CONFIG:RELEASE>:-O3>" # added by default and apparently cmake is not clever enough to filter duplicates for this one
"$<$<CONFIG:RELEASE>:-fexpensive-optimizations>"
)
if (IRR_GCC_SANITIZE_ADDRESS)
add_compile_options(-fsanitize=address)
endif()
if (IRR_GCC_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()
link_libraries(
-fuse-ld=gold
)
if(FAST_MATH)
add_compile_options(
"$<$<CONFIG:RELEASE>:-ffast-math>"
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options("$<$<CONFIG:DEBUG>:-ggdb3>")
endif()
elseif(MSVC) # /arch:sse3 or anything like this is not needed on x64 on MSVC for enabling sse3 instructions
# 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" )
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")
# 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")
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")
# 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")
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")
#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/buildaworldnet/IrrlichtBAW/issues")
endif()
endmacro()
macro(irr_adjust_definitions)
add_definitions(
-DPNG_THREAD_UNSAFE_OK
-DPNG_NO_MMX_CODE
-DPNG_NO_MNG_FEATURES
-D_7ZIP_ST
-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
)
if(WIN32)
add_definitions(
-DWIN32
-D__GNUWIN32__
-D_CRT_SECURE_NO_DEPRECATE
-DNOMINMAX
)
endif()
endmacro()
if(WIN32)
set(_IRR_PLATFORM_WINDOWS_ 1)
elseif(UNIX)
set(_IRR_PLATFORM_LINUX_ 1)
endif()
#uncomment in the future
#option(IRR_TARGET_ARCH_ARM "Build for ARM?" OFF)
option(IRR_COMPILE_WITH_OPENGL "Compile with OpenGL backend?" ON)
option(IRR_COMPILE_WITH_OPENCL "Compile with OpenCL interop?" ON)
option(IRR_PCH "Enable pre-compiled header" ON)
option(IRR_FAST_MATH "Enable fast low-precision math" ON)
option(IRR_BUILD_EXAMPLES "Enable building examples" ON)
option(IRR_BUILD_TOOLS "Enable building tools (just convert2BAW as for now)" ON)
option(IRR_BUILD_MITSUBA_LOADER "Enable irr::ext::MitsubaLoader?" ON)
option(IRR_BUILD_RADEON_RAYS "Enable irr::ext::RadeonRays?" OFF)
if (IRR_COMPILE_WITH_CUDA)
find_package(OPTIX)
if (OPTIX_FOUND)
message(STATUS "CUDA and OptiX found, you can enable IRR_BUILD_OPTIX")
else()
message(STATUS "OptiX not found")
endif()
option(IRR_BUILD_OPTIX "Enable irr::ext::OptiX?" OFF)
else()
message(STATUS "Because IRR_COMPILE_WITH_CUDA is not enabled, the IRR_BUILD_OPTIX option will be hidden.")
endif()
option(IRR_BUILD_CEGUI "Enable CEGUI building and integration?" OFF)
option(IRR_BUILD_BULLET "Enable Bullet Physics building and integration?" OFF)
option(IRR_BUILD_DOCS "Enable building documentation?" ON)
set(THIRD_PARTY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/3rdparty")
set(THIRD_PARTY_BINARY_DIR "${PROJECT_BINARY_DIR}/3rdparty")
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}")
add_subdirectory(${THIRD_PARTY_SOURCE_DIR})
OPTION(IRR_EMBED_BUILTIN_RESOURCES "Embed built-in resources?" ON)
add_subdirectory(src/irr) # Irrlicht code | Moved cmakelists.txt from source/Irrlicht to src/irr
if(IRR_BUILD_TOOLS)
add_subdirectory(tools) # convert2BAW
endif()
add_subdirectory(ext)
if(IRR_BUILD_EXAMPLES)
add_subdirectory(examples_tests)
endif()
if(IRR_BUILD_DOCS)
add_subdirectory(docs)
endif()