Skip to content

Commit e116328

Browse files
committed
trying to fix an issue with the msvc runtime
1 parent ee2a895 commit e116328

File tree

8 files changed

+122
-119
lines changed

8 files changed

+122
-119
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}

cmake/windows.cmake

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#[=======================================================================[.rst:
22
Windows
33
-------
4-
54
This file contains functions for options and configuration for targeting the
65
Windows 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
MSVC Runtime Selection
915
----------------------
1016
@@ -37,30 +43,25 @@ that dependent targets rely on it, and point them to these comments as to why.
3743
.. https://discourse.cmake.org/t/mt-staticrelease-doesnt-match-value-md-dynamicrelease/5428/4
3844
3945
]=======================================================================]
40-
if( PROJECT_NAME ) # we are not the top level if this is true
41-
if( DEFINED CMAKE_MSVC_RUNTIME_LIBRARY )
42-
# Warning that we are clobbering the variable.
43-
message( WARNING "setting CMAKE_MSVC_RUNTIME_LIBRARY to \"$<1:>\"")
44-
else( )
45-
# Notification that we are setting the variable
46-
message( STATUS "setting CMAKE_MSVC_RUNTIME_LIBRARY to \"$<1:>\"")
47-
endif()
48-
endif()
49-
set( CMAKE_MSVC_RUNTIME_LIBRARY "$<1:>" CACHE INTERNAL "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." )
46+
option( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
47+
option( GODOT_DEBUG_CRT "Compile with MSVC's debug CRT (/MDd)" OFF )
5048

51-
#[============================[ Windows Options ]============================]
52-
function( windows_options )
49+
if( DEFINED CMAKE_MSVC_RUNTIME_LIBRARY )
50+
message( NOTICE "setting CMAKE_MSVC_RUNTIME_LIBRARY, please read godot-cpp/cmake/windows.cmake")
51+
endif()
5352

54-
option( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
53+
# Set this in the parent scope so dependent libraries can use it.
54+
set( SET_PARENT \"PARENT_SCOPE\" )
55+
if( "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}" )
56+
set( SET_PARENT "" )
57+
endif()
5558
56-
option( GODOT_DEBUG_CRT "Compile with MSVC's debug CRT (/MDd)" OFF )
59+
set( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<IF:$<BOOL:${GODOT_DEBUG_CRT}>,DebugDLL,$<IF:$<BOOL:${GODOT_USE_STATIC_CPP}>,,DLL>>" ${SET_PARENT} )
5760
58-
endfunction()
5961
6062
#[===========================[ Target Generation ]===========================]
6163
function( windows_generate )
6264
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
63-
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )
6465
6566
set_target_properties( ${TARGET_NAME}
6667
PROPERTIES
@@ -76,10 +77,6 @@ function( windows_generate )
7677
>
7778
)
7879
79-
target_compile_options( ${TARGET_NAME}
80-
PUBLIC
81-
$<${IS_MSVC}:$<IF:${DEBUG_CRT},/MDd,$<IF:${STATIC_CPP},/MT,/MD>>>
82-
)
8380
8481
target_link_options( ${TARGET_NAME}
8582
PUBLIC

0 commit comments

Comments
 (0)