Skip to content

Commit 89869d7

Browse files
committed
CMake: Fix for godotengine#1699 msvc runtime selection issues
Previously I eschewed the use of CMAKE_MSVC_RUNTIME_LIBRARY in favour of setting the flags using target_compile_options so that they would propagate to consumers. However, it has been raised that a dependency( independent to godot-cpp ) that doesn't set any runtime flags, which relies purely on the CMAKE_MSVC_RUNTIME_LIBRARY variable will very likely not have the correct msvc runtime flags set. Where MSVC documentation states "All modules passed to a given invocation of the linker must have been compiled with the same runtime library compiler option (/MD, /MT, /LD)." It was also mentioned that messaging as a warning that we are setting the option was not ideal. So I have updated the cmake code to use CMAKE_MSVC_RUNTIME_LIBRARY over target-compile_options. And set it as a CACHE STRING variable so that it can be overridden if desired. We still message consumers, but as a NOTICE. While performing this work I noticed that the various options code being inside functions was unnecessary, and less flexible.
1 parent ee2a895 commit 89869d7

File tree

8 files changed

+136
-121
lines changed

8 files changed

+136
-121
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ The CMake equivalent is below.
3939

4040
include( cmake/godotcpp.cmake )
4141

42-
godotcpp_options()
43-
4442
#[[ Python is required for code generation ]]
4543
find_package(Python3 3.4 REQUIRED) # pathlib should be present
4644

cmake/android.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#[=======================================================================[.rst:
22
Android
33
-------
4-
54
This file contains functions for options and configuration for targeting the
65
Android platform
76
7+
Because this file is included into the top level CMakelists.txt before the
8+
project directive, it means that
9+
10+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
11+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
12+
directive was
13+
14+
Android Toolchain
15+
-----------------
816
Configuration of the Android toolchain is done using toolchain files,
917
CMakePresets, or variables on the command line.
1018
@@ -25,9 +33,7 @@ Android platforms.
2533
There is further information and examples in the doc/cmake.rst file.
2634
2735
]=======================================================================]
28-
function( android_options )
29-
# Android Options
30-
endfunction()
36+
3137

3238
function( android_generate )
3339
target_compile_definitions(${TARGET_NAME}

cmake/godotcpp.cmake

Lines changed: 64 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
#[=======================================================================[.rst:
22
godotcpp.cmake
33
--------------
4+
Because this file is included into the top level CMakelists.txt before the
5+
project directive, it means that
6+
7+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
8+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
9+
directive was
10+
]=======================================================================]
411

12+
#[[ Silence CMake warning for missing C Compiler
513
As godot-cpp is a C++ project, there are no C files, and detection of a C
614
compiler is unnecessary. When CMake performs the configure process, if a
715
C compiler is specified, like in a toolchain, or from an IDE, then it will
816
print a warning stating that the CMAKE_C_COMPILER compiler is unused.
9-
This if statement simply silences that warning.
10-
]=======================================================================]
17+
This if statement simply silences that warning. ]]
1118
if( CMAKE_C_COMPILER )
1219
endif ()
1320

14-
#[=======================================================================[.rst:
15-
Include Platform Files
16-
----------------------
17-
18-
Because these files are included into the top level CMakelists.txt before the
19-
project directive, it means that
20-
21-
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
22-
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
23-
directive was
24-
25-
]=======================================================================]
21+
# Include directives
2622
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/common_compiler_flags.cmake)
27-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android.cmake)
28-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios.cmake)
29-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux.cmake)
30-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
31-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
32-
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
3323
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/python_callouts.cmake)
3424

3525
# Detect number of processors
@@ -82,80 +72,81 @@ function( godot_arch_map ALIAS PROC )
8272
endif ()
8373
endfunction()
8474

85-
# Function to define all the options.
86-
function( godotcpp_options )
87-
#NOTE: platform is managed using toolchain files.
8875

89-
# Input from user for GDExtension interface header and the API JSON file
90-
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH
91-
"Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
92-
set(GODOT_CUSTOM_API_FILE "" CACHE FILEPATH
93-
"Path to a custom GDExtension API JSON file (takes precedence over `GODOT_GDEXTENSION_DIR`) ( /path/to/custom_api_file )")
76+
#[================================[ Options ]================================]
9477

95-
#TODO generate_bindings
78+
#NOTE: platform is managed using toolchain files.
9679

97-
option(GODOT_GENERATE_TEMPLATE_GET_NODE
98-
"Generate a template version of the Node class's get_node. (ON|OFF)" ON)
80+
# Input from user for GDExtension interface header and the API JSON file
81+
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH
82+
"Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
83+
set(GODOT_CUSTOM_API_FILE "" CACHE FILEPATH
84+
"Path to a custom GDExtension API JSON file (takes precedence over `GODOT_GDEXTENSION_DIR`) ( /path/to/custom_api_file )")
9985

100-
#TODO build_library
86+
#TODO generate_bindings
10187

102-
set(GODOT_PRECISION "single" CACHE STRING
103-
"Set the floating-point precision level (single|double)")
88+
option(GODOT_GENERATE_TEMPLATE_GET_NODE
89+
"Generate a template version of the Node class's get_node. (ON|OFF)" ON)
10490

105-
# The arch is typically set by the toolchain
106-
# however for Apple multi-arch setting it here will override.
107-
set( GODOT_ARCH "" CACHE STRING "Target CPU Architecture")
108-
set_property( CACHE GODOT_ARCH PROPERTY STRINGS ${ARCH_LIST} )
91+
#TODO build_library
10992

110-
#TODO threads
111-
#TODO compiledb
112-
#TODO compiledb_file
93+
set(GODOT_PRECISION "single" CACHE STRING
94+
"Set the floating-point precision level (single|double)")
11395

114-
set( GODOT_BUILD_PROFILE "" CACHE PATH
115-
"Path to a file containing a feature build profile" )
96+
# The arch is typically set by the toolchain
97+
# however for Apple multi-arch setting it here will override.
98+
set( GODOT_ARCH "" CACHE STRING "Target CPU Architecture")
99+
set_property( CACHE GODOT_ARCH PROPERTY STRINGS ${ARCH_LIST} )
116100

117-
set(GODOT_USE_HOT_RELOAD "" CACHE BOOL
118-
"Enable the extra accounting required to support hot reload. (ON|OFF)")
101+
#TODO threads
102+
#TODO compiledb
103+
#TODO compiledb_file
119104

120-
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
121-
# saves around 20% of binary size and very significant build time (GH-80513).
122-
option(GODOT_DISABLE_EXCEPTIONS "Force disabling exception handling code (ON|OFF)" ON )
105+
set( GODOT_BUILD_PROFILE "" CACHE PATH
106+
"Path to a file containing a feature build profile" )
123107

124-
set( GODOT_SYMBOL_VISIBILITY "hidden" CACHE STRING
125-
"Symbols visibility on GNU platforms. Use 'auto' to apply the default value. (auto|visible|hidden)")
126-
set_property( CACHE GODOT_SYMBOL_VISIBILITY PROPERTY STRINGS "auto;visible;hidden" )
108+
set(GODOT_USE_HOT_RELOAD "" CACHE BOOL
109+
"Enable the extra accounting required to support hot reload. (ON|OFF)")
127110

128-
#TODO optimize
111+
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
112+
# saves around 20% of binary size and very significant build time (GH-80513).
113+
option(GODOT_DISABLE_EXCEPTIONS "Force disabling exception handling code (ON|OFF)" ON )
129114

130-
option( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
115+
set( GODOT_SYMBOL_VISIBILITY "hidden" CACHE STRING
116+
"Symbols visibility on GNU platforms. Use 'auto' to apply the default value. (auto|visible|hidden)")
117+
set_property( CACHE GODOT_SYMBOL_VISIBILITY PROPERTY STRINGS "auto;visible;hidden" )
131118

132-
#[[ debug_symbols
133-
Debug symbols are enabled by using the Debug or RelWithDebInfo build configurations.
134-
Single Config Generator is set at configure time
119+
#TODO optimize
135120

136-
cmake ../ -DCMAKE_BUILD_TYPE=Debug
121+
option( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
137122

138-
Multi-Config Generator is set at build time
123+
#[[ debug_symbols
124+
Debug symbols are enabled by using the Debug or RelWithDebInfo build configurations.
125+
Single Config Generator is set at configure time
139126
140-
cmake --build . --config Debug
127+
cmake ../ -DCMAKE_BUILD_TYPE=Debug
141128
142-
]]
129+
Multi-Config Generator is set at build time
143130
144-
# FIXME These options are not present in SCons, and perhaps should be added there.
145-
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
146-
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
131+
cmake --build . --config Debug
147132
148-
# Enable Testing
149-
option( GODOT_ENABLE_TESTING "Enable the godot-cpp.test.<target> integration testing targets" OFF )
133+
]]
134+
135+
# FIXME These options are not present in SCons, and perhaps should be added there.
136+
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
137+
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
138+
139+
# Enable Testing
140+
option( GODOT_ENABLE_TESTING "Enable the godot-cpp.test.<target> integration testing targets" OFF )
141+
142+
#[[ Target Platforms]]
143+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android.cmake)
144+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios.cmake)
145+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux.cmake)
146+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
147+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
148+
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
150149

151-
#[[ Target Platform Options ]]
152-
android_options()
153-
ios_options()
154-
linux_options()
155-
macos_options()
156-
web_options()
157-
windows_options()
158-
endfunction()
159150

160151
# Function to configure and generate the targets
161152
function( godotcpp_generate )

cmake/ios.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#[=======================================================================[.rst:
22
Ios
33
---
4-
54
This file contains functions for options and configuration for targeting the
65
Ios platform
76
7+
Because this file is included into the top level CMakelists.txt before the
8+
project directive, it means that
9+
10+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
11+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
12+
directive was
13+
814
]=======================================================================]
9-
function(ios_options)
10-
# iOS options
11-
endfunction()
15+
1216

1317
function(ios_generate)
1418
target_compile_definitions(${TARGET_NAME}

cmake/linux.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#[=======================================================================[.rst:
22
Linux
33
-----
4-
54
This file contains functions for options and configuration for targeting the
65
Linux platform
76
7+
Because this file is included into the top level CMakelists.txt before the
8+
project directive, it means that
9+
10+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
11+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
12+
directive was
13+
814
]=======================================================================]
9-
function( linux_options )
10-
# Linux Options
11-
endfunction()
15+
1216

1317
function( linux_generate )
1418
target_compile_definitions( ${TARGET_NAME}

cmake/macos.cmake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#[=======================================================================[.rst:
22
MacOS
33
-----
4-
54
This file contains functions for options and configuration for targeting the
65
MacOS platform
76
7+
Because this file is included into the top level CMakelists.txt before the
8+
project directive, it means that
9+
10+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
11+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
12+
directive was
13+
814
]=======================================================================]
915

1016
# Find Requirements
@@ -18,11 +24,6 @@ IF(APPLE)
1824
ENDIF (APPLE)
1925

2026

21-
function( macos_options )
22-
# macos options here
23-
endfunction()
24-
25-
2627
function( macos_generate )
2728

2829
# OSX_ARCHITECTURES does not support generator expressions.

cmake/web.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#[=======================================================================[.rst:
22
Web
33
---
4-
54
This file contains functions for options and configuration for targeting the
65
Web platform
76
7+
Because this file is included into the top level CMakelists.txt before the
8+
project directive, it means that
9+
10+
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
11+
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
12+
directive was
13+
814
]=======================================================================]
915

1016
# Emscripten requires this hack for use of the SHARED option
1117
set( CMAKE_PROJECT_godot-cpp_INCLUDE cmake/emsdkHack.cmake )
1218

13-
function( web_options )
14-
# web options
15-
endfunction()
16-
1719

1820
function( web_generate )
1921
target_compile_definitions(${TARGET_NAME}

0 commit comments

Comments
 (0)