-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
242 lines (192 loc) · 7.77 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
# Build
cmake_minimum_required(VERSION 3.14)
# Prevent building in-tree
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree built in ${CMAKE_SOURCE_DIR}. Create a 'build' directory outside of the source code and call cmake from there.")
endif()
set(GAIA_VERSION_REGEX "#define GAIA_VERSION_.*[ \t]+(.+)")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/gaia/config/version.h" GAIA_VERSION REGEX ${GAIA_VERSION_REGEX})
list(TRANSFORM GAIA_VERSION REPLACE ${GAIA_VERSION_REGEX} "\\1")
string(JOIN "." GAIA_VERSION ${GAIA_VERSION})
project(
gaia
VERSION ${GAIA_VERSION}
DESCRIPTION "ECS framework"
LANGUAGES CXX
)
message(STATUS "*************************************************************")
message(STATUS "${PROJECT_NAME}-ecs v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message(STATUS "Copyright (c) 2024 Richard Biely <richardbiely@gmail.com>")
message(STATUS "*************************************************************")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER}")
message(STATUS "CPU: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "*************************************************************")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sanitizers.cmake")
# CPU
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" lower_processor)
set(IsARM false)
if("${lower_processor}" MATCHES "arm" OR "${lower_processor}" MATCHES "aarch")
set(IsARM true)
endif()
# Compiler
set(IsClangCompiler FALSE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(IsClangCompiler TRUE)
endif()
# Configuration
option(GAIA_USE_LIBCPP "Use libc++." OFF)
if(IsClangCompiler)
set(GAIA_USE_LIBCPP ON)
endif()
option(GAIA_BUILD_UNITTEST "Build unit test." OFF)
option(GAIA_BUILD_BENCHMARK "Build benchmark." OFF)
option(GAIA_BUILD_EXAMPLES "Build examples." OFF)
option(GAIA_GENERATE_CC "Use ninja to generate compile_commands.json as a post-build step." ON)
option(GAIA_MAKE_SINGLE_HEADER "Make the single file header automatically." OFF)
# Profiling settings
option(GAIA_PROFILER_CPU "Enable CPU profiling." OFF)
option(GAIA_PROFILER_MEM "Enable memory profiling." OFF)
option(GAIA_PROFILER_BUILD "Build profiler if possible." OFF)
# Library configuration
option(GAIA_DEVMODE "Enables various verification checks. Only useful for library maintainers." OFF)
option(GAIA_ECS_CHUNK_ALLOCATOR "If enabled, custom allocator is used for allocating archetype chunks." ON)
option(GAIA_FORCE_DEBUG "If enabled, GAIA_DEBUG will be defined despite using the optimized build configuration." OFF)
option(GAIA_DISABLE_ASSERTS "If enabled, no asserts will be thrown even in debug builds." OFF)
if(GAIA_BUILD_UNITTEST)
set(GAIA_BUILD_SRC ON)
elseif(GAIA_BUILD_BENCHMARK)
set(GAIA_BUILD_SRC ON)
elseif(GAIA_BUILD_EXAMPLES)
set(GAIA_BUILD_SRC ON)
else()
set(GAIA_BUILD_SRC OFF)
endif()
# libc++
if(NOT WIN32 AND GAIA_USE_LIBCPP)
# Check for libc++ library presence
find_library(LIBCXX_LIBRARY c++)
if(LIBCXX_LIBRARY)
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
check_cxx_source_compiles("
#include <type_traits>
int main() { return std::is_same_v<int, char>; }
" GAIA_USE_LIBCPP)
cmake_pop_check_state()
endif()
if(NOT GAIA_USE_LIBCPP)
message(WARNING "GAIA_USE_LIBCPP is ON but libc++ is not available. The flag will be ignored.")
endif()
endif()
# Gaia target
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(GAIA_HAS_LIBCPP)
target_compile_options(${PROJECT_NAME} BEFORE INTERFACE -stdlib=libc++)
endif()
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
# Install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
if(NOT INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR include/gaia)
endif()
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
PATH_VARS INCLUDE_INSTALL_DIR)
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
if(NOT "GAIA_USE_SANITIZER" MATCHES "")
add_definitions(-DGAIA_USE_SANITIZER=1)
else()
add_definitions(-DGAIA_USE_SANITIZER=0)
endif()
set(IS_FETCH_AVAILABLE OFF)
if(GAIA_BUILD_BENCHMARK OR GAIA_BUILD_UNITTEST OR GAIA_PROFILER_CPU OR GAIA_PROFILER_MEM OR GAIA_MAKE_SINGLE_HEADER)
find_package(Git REQUIRED)
Include(FetchContent OPTIONAL RESULT_VARIABLE FetchContent_FOUND)
if(NOT FetchContent_FOUND)
message(WARNING "FetchContent might be necessary but it is not available")
else()
set(IS_FETCH_AVAILABLE ON)
endif()
endif()
if(GAIA_PROFILER_CPU OR GAIA_PROFILER_MEM OR GAIA_PROFILER_BUILD)
if(IS_FETCH_AVAILABLE)
find_package(tracy CONFIG QUIET 0.11.1)
if(NOT tracy_FOUND)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.11.1
GIT_SHALLOW TRUE
)
set(TRACY_ENABLE ON CACHE BOOL "TRACY_ENABLE override")
set(TRACY_ON_DEMAND ON CACHE BOOL "TRACY_ON_DEMAND override")
FetchContent_MakeAvailable(tracy)
endif()
else()
find_package(tracy CONFIG REQUIRED 0.11.1)
endif()
if(GAIA_PROFILER_CPU)
add_compile_definitions(GAIA_PROFILER_CPU=1)
endif()
if(GAIA_PROFILER_MEM)
add_compile_definitions(GAIA_PROFILER_MEM=1)
endif()
if(GAIA_PROFILER_CPU OR GAIA_PROFILER_MEM)
link_libraries(TracyClient)
endif()
if(GAIA_PROFILER_BUILD)
# Add a custom target to build the Tracy profiler GUI
if(UNIX)
set(tracy_profiler_build_dir "build/unix")
message("Building profiler for UNIX platform in: " ${tracy_profiler_build_dir})
elseif(WIN32)
set(tracy_profiler_build_dir "build/win32")
message("Building profiler for Windows platform in: " ${tracy_profiler_build_dir})
else()
message(WARNING "Unsupported platform. Building profiler won't be possible")
endif()
if(DEFINED tracy_profiler_build_dir)
add_custom_target(build_tracy_profiler_gui ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${tracy_profiler_build_dir}
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release -B ${tracy_profiler_build_dir} -S .
COMMAND ${CMAKE_COMMAND} --build ${tracy_profiler_build_dir} --config Release
WORKING_DIRECTORY ${tracy_SOURCE_DIR}/profiler
)
endif()
endif()
endif()
if(GAIA_BUILD_SRC)
add_subdirectory(src)
endif()
# Print project variables
get_cmake_property(all_vars VARIABLES)
foreach(var ${all_vars})
if(var MATCHES "^GAIA_")
message(STATUS "${var} = ${${var}}")
endif()
endforeach()