generated from vorlac/godot-roguelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
206 lines (173 loc) · 5.79 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
cmake_minimum_required(VERSION 3.20)
set(GDEXTENSION_LIB_NAME roguelite)
set(GDEXTENSION_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/project/bin")
option(
AUTOFORMAT_SRC_ON_CONFIGURE
"If enabled, clang-format will be used to format all sources in src/ during configuration"
ON
)
option(
USE_CCACHE_FOR_GDEXT_BUILD
"If enabled, ccache will be used to when building the project lib"
ON
)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_MESSAGE_LOG_LEVEL STATUS)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/cmake/"
)
include(vcpkg-init)
project("${GDEXTENSION_LIB_NAME}"
LANGUAGES
C CXX
VERSION
0.1.0
)
include(vcpkg-install-deps)
# =======================================================================
# Compiler identification
# =======================================================================
set(compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>")
set(compiler_is_gnu "$<CXX_COMPILER_ID:GNU>")
set(compiler_is_msvc "$<CXX_COMPILER_ID:MSVC>")
# =======================================================================
# Configure godot-engine and godot-cpp submodules and define libraries.
# godot-cpp:
# configured as a library that will statically
# link this project's gdextension library.
# godot-engine:
# the engine submodule will be (re)built using scons if a
# debug build of the editor doesn't already exist.
# the engine sources and headers will then be used to declare
# a library in cmake (but will not built). the cmake library
# will improve code browsing, syntax highlighting, searching,
# debbuging, and autocomplete/intellisense for any IDEs that
# gather data from cmake (i.e. VSCode and Visual Studio 2022)
# =======================================================================
include(godot-dev-configuration)
# =======================================================================
# 3rd party library setup/configuration (leverages vcpkg)
# =======================================================================
find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
# =======================================================================
# GDExtension dynamic library setup/configuration
# =======================================================================
# add library sources
file(GLOB_RECURSE gdext_sources
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]pp"
)
# add the gdextension dynamic library
add_library(${PROJECT_NAME}
SHARED
${gdext_sources}
)
# import compiler warningS from godot-cpp
include(GodotCompilerWarnings)
# set compiler options for the gdextension library based on the compiler being used
target_compile_options(${PROJECT_NAME} PUBLIC
$<${compiler_is_msvc}:
/EHsc
/utf-8
/Zc:preprocessor
$<$<CONFIG:Debug>:
/MDd
>
$<$<CONFIG:Release>:
/MD
/O2
>
>
$<$<NOT:${compiler_is_msvc}>:
-g
-Wno-unused-value
$<${compiler_is_gnu}:
-Wno-attributes
-Wno-attributes=rl::
>
$<${compiler_is_clang}:
-Wno-ignored-attributes
-Wno-unknown-attributes
>
$<$<CONFIG:Debug>:
-fno-omit-frame-pointer
-O0
>
$<$<CONFIG:Release>:
-O3
>
>
)
# enable extension hot swapping
target_compile_definitions(${PROJECT_NAME} PUBLIC
HOT_RELOAD_ENABLED
)
# include directories gdextension library
target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
if (NOT APPLE)
# linker options for the gdextension library
target_link_options(${PROJECT_NAME} PRIVATE
$<$<NOT:${compiler_is_msvc}>:
-static-libgcc
-static-libstdc++
-Wl,-R,'$$ORIGIN'
>
)
endif()
# =======================================================================
# Optional configuration / build features
# =======================================================================
if (USE_CCACHE_FOR_GDEXT_BUILD MATCHES ON)
include(ccache)
endif()
if (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON)
include(clang-format)
endif()
# =======================================================================
# Dependency linkage
# =======================================================================
add_subdirectory(extern/tetris-core)
# gdextension library dependency linkage
target_link_libraries(${PROJECT_NAME}
PUBLIC godot::cpp
PRIVATE TetrisCore
PRIVATE fmt::fmt
PRIVATE fmt::fmt-header-only
PRIVATE spdlog::spdlog_header_only
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(system_bits 64)
else()
set(system_bits 32)
endif()
string(TOLOWER
"${PROJECT_NAME}.${CMAKE_SYSTEM_NAME}.${system_bits}.${CMAKE_BUILD_TYPE}"
gde_lib_name
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
POSITION_INDEPENDENT_CODE ON
CMAKE_EXPORT_COMPILE_COMMANDS ON
CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON
ARCHIVE_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
LIBRARY_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
RUNTIME_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
CMAKE_PDB_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
OUTPUT_NAME "${gde_lib_name}"
)
# =======================================================================
# Print configuration report
# =======================================================================
# include utility script that prints a handful of
# useful build/configuration cmake variables
include(cmake-utils)
print_project_variables()