forked from CraterCrash/godot-orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
219 lines (189 loc) · 7.24 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
## This file is part of the Godot Orchestrator project.
##
## Copyright (c) 2023-present Crater Crash Studios LLC and its contributors.
##
## 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.20 FATAL_ERROR)
SET(GDEXTENSION_LIB_NAME orchestrator)
SET(GDEXTENSION_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/project/addons/orchestrator")
# Configurable options
OPTION(AUTOFORMAT_SRC_ON_CONFIGURE "If enabled, clang-format will be used to format all sources in /src during configuration" OFF)
# Set basic CMAKE properties
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_EXTENSIONS ON)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_COLOR_DIAGNOSTICS ON)
SET(CMAKE_MESSAGE_LOG_LEVEL STATUS)
# Get the current repository Git commit hash
# This is used when creating the data from VERSION to show the commit hash in the about box
FIND_PACKAGE(Git QUIET)
IF (GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp"
OUTPUT_VARIABLE GODOT_CPP_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE ()
# In this case the about box will simply show an unknown git commit
SET(GIT_COMMIT_HASH "<Unknown>")
SET(GODOT_CPP_GIT_COMMIT_HASH "<Unknown>")
ENDIF ()
# Setup the CMAKE_MODULE_PATH
LIST(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/cmake/")
# Include and execute various CMAKE modules
INCLUDE(generate-authors)
INCLUDE(generate-license)
INCLUDE(generate-version)
INCLUDE(generate-donors)
INCLUDE(godot-extension-db-generator)
INCLUDE(godot-docs-generator)
# Generation steps
GENERATE_AUTHORS()
GENERATE_LICENSE()
GENERATE_VERSION()
GENERATE_DONORS()
GENERATE_GODOT_EXTENSION_DB()
GENERATE_GODOT_DOCUMENTATION()
# Configure project
PROJECT("${GDEXTENSION_LIB_NAME}" LANGUAGES C CXX VERSION ${RESOLVED_VERSION})
# Generate library resource
IF (WIN32)
SET(win32_product_name "${RESOLVED_VERSION_NAME}")
SET(win32_file_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_product_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_file_description "Godot ${win32_product_name} Plug-in")
CONFIGURE_FILE(cmake/templates/windows.rc.in ${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc @ONLY)
ENDIF ()
# Orchestrator is an editor plug-in, force TOOLS_ENABLED
ADD_COMPILE_DEFINITIONS(TOOLS_ENABLED)
# MacOS universal binary support
IF (APPLE)
SET(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for OSX" FORCE)
ENDIF ()
# 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-cpp - a statically linked library to this project.
INCLUDE(godot-dev-configuration)
# Library sources
FILE(GLOB_RECURSE gdext_sources
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]pp"
# Includes the generated doc data from /doc_classes
"${CMAKE_BINARY_DIR}/_generated/*.cpp"
# Include windows version resource, if exists
"${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc")
# GDExtension library
ADD_LIBRARY(${PROJECT_NAME} SHARED ${gdext_sources})
## Import compiler warnings from godot-cpp
INCLUDE(GodotCompilerWarnings)
# Setup compiler options for GDExtension Library based on the compiler used
TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC
$<${compiler_is_msvc}:
/EHsc
/utf-8
/Zc:preprocessor
/wd5054 # operator '|' deprecated between enumerations of different types
$<$<CONFIG:Debug>:
/MDd
>
$<$<CONFIG:Release>:
/MD
/O2
>
>
$<$<NOT:${compiler_is_msvc}>:
-Wno-unused-value
$<${compiler_is_gnu}:
-Wno-attributes
-Wno-attributes=r1::
>
$<${compiler_is_clang}:
-Wno-ignored-attributes
-Wno-unknown-attributes
>
$<$<CONFIG:Debug>:
-g
-fno-omit-frame-pointer
-O0
>
$<$<CONFIG:Release>:
-O3
>
>)
find_program(ccache_exe ccache)
IF (ccache_exe)
SET(CMAKE_VS_GLOBALS "TrackFileAccess=false" "UseMultiToolTask=true" "DebugInformationFormat=OldStyle")
ENDIF ()
# Add the special "_generated" directory to the include list
# This is where the generator CMAKE module steps creates automated files
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/_generated)
# Include directories for 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'
$<$<CONFIG:Release>:
$<$<PLATFORM_ID:Android>:-s>
>
>)
ENDIF ()
IF (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON)
include(clang-format)
ENDIF ()
# Dependency linking
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC godot::cpp)
SET(GDEXTENSION_LIB_PREFIX "")
IF (NOT ANDROID)
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(system_bits 64)
ELSE ()
SET(system_bits 32)
ENDIF ()
ELSE ()
SET(GDEXTENSION_LIB_PREFIX "lib")
IF (CMAKE_ANDROID_ARCH STREQUAL "arm64")
SET(system_bits 64)
ELSE ()
SET(system_bits 32)
ENDIF ()
ENDIF ()
STRING(TOLOWER "${PROJECT_NAME}.${CMAKE_SYSTEM_NAME}.${system_bits}.${CMAKE_BUILD_TYPE}" GDEXTENSION_LIB_NAME)
SET_TARGET_PROPERTIES(${PROJECT_NAME}
PROPERTIES
PREFIX "${GDEXTENSION_LIB_PREFIX}"
POSITION_INDEPENDENT_CODE ON
CMAKE_EXPORT_COMPILE_OPTIMIZATION_RELEASE 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 "${GDEXTENSION_LIB_NAME}")
INCLUDE(cmake-utils)
PRINT_PROJECT_VARIABLES()