Skip to content

Commit fdca2a9

Browse files
committed
Updated target properties
- Added CXX_STANDARD 17 - Added POSITION_INDEPENDENT_CODE ON - Added BUILDRPTH_USE_ORIGIN ON Changed python command to use single quotes to make build output log more legible. removed manual rpath origin from link options prevent use of -static-libgcc on APPLE platform Re-Arranged initial cmake file to allow options before project command, specifically CMAKE_BUILD_TYPE as the default should be Release unless DEV_BUILD is enabled. Added GODOT_DEV_BUILD to allow differentiation of debug or Release builds. Removed manual link options for test target Updated test target properties - Added CXX_STANDARD 17 - Added CXX_VISIBILITY_PRESET - Added LINK_SEARCH_START_STATIC - Added LINK_SEARCH_END_STATIC - Added to .gitignore CMakeUserPresets.json
1 parent a6b206b commit fdca2a9

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,6 @@ venv
199199
# Clion Configuration
200200
.idea/
201201
cmake-build-*
202+
203+
# CMake related
204+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(godot-cpp LANGUAGES CXX)
32

4-
# Get Python
5-
find_package(Python3 3.4 REQUIRED) # pathlib should be present
3+
# As we are attempting to maintain feature parity, and ease of maintenance,
4+
# these CMake scripts are built to resemble the structure of the SCons build system.
5+
# The closer the two build systems look the easier they will be to maintain.
66

7-
if( CMAKE_C_COMPILER)
8-
#Silence warning from unused CMAKE_C_COMPILER from toolchain
9-
endif ()
7+
# include pulls in the code from godotcpp.cmake
8+
# the equivalent in scons:
9+
# cpp_tool = Tool("godotcpp", toolpath=["tools"])
10+
include( ${CMAKE_SOURCE_DIR}/cmake/godotcpp.cmake )
1011

11-
# Main Library
12-
include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
12+
godotcpp_options()
1313

14-
# I know this doesn't look like a typical CMakeLists.txt, but as we are
15-
# attempting mostly feature parity with SCons, and easy maintenance, the closer
16-
# the two build systems look the easier they will be to keep in lockstep.
14+
# godot-cpp targets three main configurations, editor, template_release and template_debug.
15+
# These are all built in "Release" mode unless GODOT_DEV_BUILD is enabled, then the build type is "Debug".
16+
get_property( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
17+
if( NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE )
18+
if( GODOT_DEV_BUILD )
19+
set( CMAKE_BUILD_TYPE "Debug" )
20+
else ()
21+
set( CMAKE_BUILD_TYPE "Release" )
22+
endif ()
23+
endif ()
1724

18-
# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake
25+
# Get Python
26+
find_package(Python3 3.4 REQUIRED) # pathlib should be present
1927

20-
godotcpp_options()
28+
# Define our project.
29+
project(godot-cpp LANGUAGES CXX)
2130

2231
godotcpp_generate()
2332

cmake/common_compiler_flags.cmake

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,12 @@ target_compile_definitions(${PROJECT_NAME}
121121
$<$<STREQUAL:${GODOT_PRECISION},double>:REAL_T_IS_DOUBLE>
122122
)
123123

124-
target_link_options(${PROJECT_NAME} PRIVATE
125-
$<$<OR:${IS_CLANG},${IS_GNU}>:
126-
-static-libgcc
127-
-static-libstdc++
128-
>
129-
130-
$<$<PLATFORM_ID:Linux>:
131-
$<${IS_GNU}:
132-
-Wl,-R,'$$ORIGIN'
124+
# godot-cpp is a static archive, so there is no link step.
125+
# However, I can save consumers some build configuration steps by propagating static linking to libc
126+
target_link_options(${PROJECT_NAME}
127+
PUBLIC
128+
$<$<OR:${IS_CLANG},${IS_GNU}>:
129+
$<$<NOT:$<BOOL:${APPLE}>>:-static-libgcc>
130+
-static-libstdc++
133131
>
134-
>
135132
)

cmake/godotcpp.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function( godotcpp_options )
3838

3939
#TODO optimize
4040
#TODO debug_symbols
41-
#TODO dev_build
41+
option( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
4242

4343
# FIXME These options are not present in SCons, and perhaps should be added there.
4444
option(GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." ON)
@@ -87,14 +87,14 @@ function( godotcpp_generate )
8787
set(GENERATE_BINDING_PARAMETERS "False")
8888
endif()
8989

90-
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_GDEXTENSION_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)"
90+
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list('${GODOT_GDEXTENSION_API_FILE}', '${CMAKE_CURRENT_BINARY_DIR}', headers=True, sources=True)"
9191
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9292
OUTPUT_VARIABLE GENERATED_FILES_LIST
9393
OUTPUT_STRIP_TRAILING_WHITESPACE
9494
)
9595

9696
add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
97-
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_GDEXTENSION_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${GODOT_PRECISION}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
97+
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings('${GODOT_GDEXTENSION_API_FILE}', '${GENERATE_BINDING_PARAMETERS}', '${BITS}', '${GODOT_PRECISION}', '${CMAKE_CURRENT_BINARY_DIR}')"
9898
VERBATIM
9999
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
100100
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}
@@ -150,9 +150,11 @@ function( godotcpp_generate )
150150

151151
set_target_properties( ${PROJECT_NAME}
152152
PROPERTIES
153+
CXX_STANDARD 17
153154
CXX_EXTENSIONS OFF
154-
POSITION_INDEPENDENT_CODE ON
155155
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
156+
POSITION_INDEPENDENT_CODE ON
157+
BUILD_RPATH_USE_ORIGIN ON
156158
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
157159
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
158160
PREFIX lib

doc/cmake.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Info on cross compiling triplets indicates that the naming is a little more free
218218
Untested
219219

220220
### MacOS Host
221-
Untested
221+
tested on a mac mini, but I have to check the target triplet.
222222

223223
### Windows Host
224224

test/CMakeLists.txt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ target_compile_options( godot-cpp-test
2424
>
2525
)
2626

27-
target_link_options( godot-cpp-test
28-
PRIVATE
29-
$<$<OR:${IS_CLANG},${IS_GNU}>:
30-
-static-libgcc
31-
-static-libstdc++
32-
>
33-
$<$<PLATFORM_ID:Linux>:
34-
$<${IS_GNU}:
35-
-Wl,-R,'$$ORIGIN'
36-
>
37-
>
38-
)
3927

4028
### Create the correct name (name.os.build_type.arch)
4129
set( ARCH_KEYS "w64;x86_64;amd64" )
@@ -52,10 +40,13 @@ set( SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>$<$<BOOL:${ANDROID}>:.${ANDR
5240

5341
set_target_properties( godot-cpp-test
5442
PROPERTIES
43+
CXX_STANDARD 17
5544
CXX_EXTENSIONS OFF
45+
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
5646
POSITION_INDEPENDENT_CODE ON
5747
BUILD_RPATH_USE_ORIGIN ON
58-
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
48+
LINK_SEARCH_START_STATIC ON
49+
LINK_SEARCH_END_STATIC ON
5950
LIBRARY_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/project/bin/>"
6051
RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/project/bin/>"
6152
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/project/bin/>"

0 commit comments

Comments
 (0)