1
1
#[=======================================================================[.rst:
2
2
Windows
3
3
-------
4
-
5
4
This file contains functions for options and configuration for targeting the
6
5
Windows platform
7
6
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
+
8
14
MSVC Runtime Selection
9
15
----------------------
10
16
@@ -19,48 +25,50 @@ Default: ``CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
19
25
This initializes each target's ``MSVC_RUNTIME_LIBRARY`` property at the time of
20
26
target creation.
21
27
28
+ it is stated in the msvc_ documentation that: "All modules passed to a given
29
+ invocation of the linker must have been compiled with the same runtime library
30
+ compiler option (/MD, /MT, /LD)."
31
+
22
32
This creates a conundrum for us, the ``CMAKE_MSVC_RUNTIME_LIBRARY`` needs to be
23
33
correct at the time the target is created, but we have no control over the
24
34
consumers CMake scripts, and the per-target ``MSVC_RUNTIME_LIBRARY`` property
25
35
is not transient.
26
36
27
- We need ``CMAKE_MSVC_RUNTIME_LIBRARY`` to be ``"$<1:>"`` to ensure it
28
- will not add any flags. And then use ``target_compile_options()`` so that our
29
- flags will propagate to consumers.
37
+ It has been raised that not using ``CMAKE_MSVC_RUNTIME_LIBRARY`` can also cause
38
+ issues_ when a dependency( independent to godot-cpp ) that doesn't set any
39
+ runtime flags, which relies purely on the ``CMAKE_MSVC_RUNTIME_LIBRARY``
40
+ variable will very likely not have the correct msvc runtime flags set.
41
+
42
+ So we'll set ``CMAKE_MSVC_RUNTIME_LIBRARY`` as CACHE STRING so that it will be
43
+ available for consumer target definitions, but also be able to be overridden if
44
+ needed.
30
45
31
- In the interests of playing nicely we detect whether we are being consumed
32
- and notify the consumer that we are setting ``CMAKE_MSVC_RUNTIME_LIBRARY``,
33
- that dependent targets rely on it, and point them to these comments as to why.
46
+ Additionally we message consumers notifying them and pointing to this
47
+ documentation.
34
48
35
49
.. _CMP0091:https://cmake.org/cmake/help/latest/policy/CMP0091.html
36
50
.. _property:https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
37
51
.. https://discourse.cmake.org/t/mt-staticrelease-doesnt-match-value-md-dynamicrelease/5428/4
52
+ .. _msvc: https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library
53
+ .. _issues: https://github.com/godotengine/godot-cpp/issues/1699
38
54
39
55
]=======================================================================]
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." )
50
-
51
- #[============================[ Windows Options ]============================]
52
56
function ( windows_options )
53
-
54
57
option ( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
55
-
56
58
option ( GODOT_DEBUG_CRT "Compile with MSVC's debug CRT (/MDd)" OFF )
57
59
60
+ message ( STATUS "If not already cached, setting CMAKE_MSVC_RUNTIME_LIBRARY.\n "
61
+ "\t For more information please read godot-cpp/cmake/windows.cmake" )
62
+
63
+ set ( CMAKE_MSVC_RUNTIME_LIBRARY
64
+ "MultiThreaded$<IF:$<BOOL:${GODOT_DEBUG_CRT} >,DebugDLL,$<$<NOT:$<BOOL:${GODOT_USE_STATIC_CPP} >>:DLL>>"
65
+ CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." )
58
66
endfunction ()
59
67
68
+
60
69
#[===========================[ Target Generation ]===========================]
61
70
function ( windows_generate )
62
71
set ( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP} >" )
63
- set ( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT} >" )
64
72
65
73
set_target_properties ( ${TARGET_NAME}
66
74
PROPERTIES
@@ -76,11 +84,6 @@ function( windows_generate )
76
84
>
77
85
)
78
86
79
- target_compile_options ( ${TARGET_NAME}
80
- PUBLIC
81
- $< ${IS_MSVC} :$< IF:${DEBUG_CRT} ,/MDd,$< IF:${STATIC_CPP} ,/MT,/MD> > >
82
- )
83
-
84
87
target_link_options ( ${TARGET_NAME}
85
88
PUBLIC
86
89
0 commit comments