-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
237 lines (185 loc) · 7.93 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
cmake_minimum_required(VERSION 3.18.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.6.7)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
set(BIN_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_BUILD_TYPE}/bin)
# Use C++17
set(PROJ_CXX_STD_FEATURE cxx_std_17)
set(PROJ_CXX_STANDARD C++17)
# Require (at least) it
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Don't use e.g. GNU extension (like -std=gnu++11) for portability
set(CMAKE_CXX_EXTENSIONS OFF)
# Relevant cmake files are in this folder
set(CMAKE_CONFIG_FOLDER ${CMAKE_SOURCE_DIR}/cmake)
# the main library name
set(GRIDDLY_LIB_NAME Griddly)
# the griddly test target name
set(GRIDDLY_TEST_BIN_NAME ${GRIDDLY_LIB_NAME}_Test)
# project main directory for all c++ related files
set(GRIDDLY_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# project main directory for all c++ related files
set(GRIDDLY_PYBINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bindings)
# project test directory
set(GRIDDLY_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
# main test sources folder
set(GRIDDLY_TEST_SRC_DIR ${GRIDDLY_TEST_DIR}/src)
# project resources folder (e.g. map files, shaders, configs etc.)
set(GRIDDLY_RESOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources)
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
option(ENABLE_CACHE "Enable cache if available" ON)
option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" OFF)
option(ENABLE_CPPCHECK "Enable static analysis with cppcheck" OFF)
option(ENABLE_INCLUDE_WHAT_YOU_USE "Enable static analysis with include-what-you-use" OFF)
option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" OFF)
option(ENABLE_PCH "Enable Precompiled Headers" ON)
option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF)
option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" OFF)
option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" OFF)
option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" OFF)
option(ENABLE_PYTHON_BINDINGS "Enable to build the bindings to other languages." ON)
option(ENABLE_TESTING "Enable Test Builds" ON)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
option(WASM "Enable Web-assembly build" OFF)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)
message(STATUS ${CMAKE_SYSTEM_NAME})
if(WASM)
message(STATUS "Compiling for webassembly using emscripten")
target_compile_definitions(project_options INTERFACE "-DWASM")
target_compile_options(project_options INTERFACE "-fexceptions")
endif()
if(CMAKE_HOST_WIN32)
message("Compiling with CMAKE_HOST_WIN32")
# bigobj is required for windows builds
target_compile_options(project_options INTERFACE "/bigobj")
set_target_properties(project_options PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
target_compile_features(project_options INTERFACE ${PROJ_CXX_STD_FEATURE})
if(ENABLE_PCH)
target_precompile_headers(project_options
INTERFACE
<vector>
<string>
<map>
<utility>
<memory>
<array>
<optional>
)
endif()
# import utility methods for cmake
include(${CMAKE_CONFIG_FOLDER}/settings/Utilities.cmake)
# enable clang-format and clang-tidy project wide
include(${CMAKE_CONFIG_FOLDER}/settings/Clang-cxx-dev-tools.cmake)
# enable cache system
include(${CMAKE_CONFIG_FOLDER}/settings/Cache.cmake)
# standard compiler warnings
include(${CMAKE_CONFIG_FOLDER}/settings/CompilerWarnings.cmake)
set_project_warnings(project_warnings)
# sanitizer options if supported by compiler
include(${CMAKE_CONFIG_FOLDER}/settings/Sanitizers.cmake)
enable_sanitizers(project_options)
# allow for static analysis
include(${CMAKE_CONFIG_FOLDER}/settings/StaticAnalyzers.cmake)
# glm
find_package(glm REQUIRED)
# Yaml-Cpp
find_package(yaml-cpp REQUIRED)
# spdlog
find_package(spdlog REQUIRED)
# boost
find_package(Boost COMPONENTS Random REQUIRED)
if(NOT WASM)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
# find the dependencies from conan
set(PYBIND11_FINDPYTHON FALSE)
# set(Python_ROOT_DIR /opt/python/$ENV{PYBIN})
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
# pybind11
find_package(pybind11 REQUIRED)
# GTest
if(ENABLE_TESTING)
find_package(GTest REQUIRED)
endif()
# stb
find_package(stb REQUIRED)
# Vulkan
find_package(volk REQUIRED)
# ShaderC for compiling shaders
find_package(shaderc REQUIRED)
endif()
include(${CMAKE_CONFIG_FOLDER}/targets/griddly.cmake)
if(WASM)
include(${CMAKE_CONFIG_FOLDER}/targets/wasm.cmake)
else()
# Compile shaders and copy them into resources directory in build output
if(NOT WASM)
message(STATUS "Compiling shaders...")
set(ENV{GLSLC_BIN} ${CONAN_SHADERC_ROOT}/bin/glslc)
if(CMAKE_HOST_WIN32)
execute_process(COMMAND powershell ${CMAKE_CURRENT_SOURCE_DIR}/compile_shaders.bat RESULT_VARIABLE STATUS)
if(STATUS AND NOT STATUS EQUAL 0)
message( FATAL_ERROR "Cannot compile shaders: ${STATUS}")
endif()
else()
execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/compile_shaders.sh RESULT_VARIABLE STATUS)
if(STATUS AND NOT STATUS EQUAL 0)
message( FATAL_ERROR "Cannot compile shaders: ${STATUS}")
endif()
endif()
if(ENABLE_PYTHON_BINDINGS)
message("Configuring Python Bindings.")
include(${CMAKE_CONFIG_FOLDER}/targets/python_griddly.cmake)
endif()
if(ENABLE_TESTING)
message("Configuring Tests.")
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) # prevent CTest from flooding the target space with CI/CD targets
include(CTest)
enable_testing()
include(${CMAKE_CONFIG_FOLDER}/targets/test.cmake)
endif()
endif()
include(CMakePackageConfigHelpers)
# Want the python lib to be output in the same directory as the other dll/so
if(CMAKE_HOST_WIN32)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set_target_properties(${PYTHON_MODULE} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${BIN_OUTPUT_DIR})
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
endif()
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWERCASE}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(TARGETS project_options EXPORT ${PROJECT_NAME_LOWERCASE}Options)
install(TARGETS ${GRIDDLY_LIB_NAME}_interface ${GRIDDLY_LIB_NAME}_shared ${GRIDDLY_LIB_NAME}_static
EXPORT ${PROJECT_NAME_LOWERCASE}Targets
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME_LOWERCASE}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWERCASE}Config.cmake"
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME_LOWERCASE}
)
install(EXPORT ${PROJECT_NAME_LOWERCASE}Options DESTINATION lib/cmake/${PROJECT_NAME_LOWERCASE})
install(EXPORT ${PROJECT_NAME_LOWERCASE}Targets DESTINATION lib/cmake/${PROJECT_NAME_LOWERCASE})
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWERCASE}ConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWERCASE}Config.cmake"
DESTINATION lib/cmake/${PROJECT_NAME_LOWERCASE})
install(FILES ${GRIDDLY_HEADERS} DESTINATION include)
install(DIRECTORY ${GRIDDLY_RESOURCE_DIR} DESTINATION resources)
endif()