@@ -10,20 +10,20 @@ features. For target platform specific flags look to each of the
1010]=======================================================================]
1111
1212#[[ Compiler Configuration, not to be confused with build targets ]]
13- set ( DEBUG_SYMBOLS "$<OR :$<CONFIG :Debug >,$<CONFIG :RelWithDebInfo >>" )
13+ set (DEBUG_SYMBOLS "$<OR :$<CONFIG :Debug >,$<CONFIG :RelWithDebInfo >>" )
1414
1515#[[ Compiler Identification ]]
16- set ( IS_CLANG "$<CXX_COMPILER_ID :Clang >" )
17- set ( IS_APPLECLANG "$<CXX_COMPILER_ID :AppleClang >" )
18- set ( IS_GNU "$<CXX_COMPILER_ID :GNU >" )
19- set ( IS_MSVC "$<CXX_COMPILER_ID :MSVC >" )
20- set ( NOT_MSVC "$<NOT :$<CXX_COMPILER_ID :MSVC >>" )
21-
22- set ( GNU_LT_V8 "$<VERSION_LESS :$<CXX_COMPILER_VERSION >,8>" )
23- set ( GNU_GE_V9 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,9>" )
24- set ( GNU_GT_V11 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,11>" )
25- set ( GNU_LT_V11 "$<VERSION_LESS :$<CXX_COMPILER_VERSION >,11>" )
26- set ( GNU_GE_V12 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,12>" )
16+ set (IS_CLANG "$<CXX_COMPILER_ID :Clang >" )
17+ set (IS_APPLECLANG "$<CXX_COMPILER_ID :AppleClang >" )
18+ set (IS_GNU "$<CXX_COMPILER_ID :GNU >" )
19+ set (IS_MSVC "$<CXX_COMPILER_ID :MSVC >" )
20+ set (NOT_MSVC "$<NOT :$<CXX_COMPILER_ID :MSVC >>" )
21+
22+ set (GNU_LT_V8 "$<VERSION_LESS :$<CXX_COMPILER_VERSION >,8>" )
23+ set (GNU_GE_V9 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,9>" )
24+ set (GNU_GT_V11 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,11>" )
25+ set (GNU_LT_V11 "$<VERSION_LESS :$<CXX_COMPILER_VERSION >,11>" )
26+ set (GNU_GE_V12 "$<VERSION_GREATER_EQUAL :$<CXX_COMPILER_VERSION >,12>" )
2727
2828#[[ Check for clang-cl with MSVC frontend
2929The compiler is tested and set when the project command is called.
@@ -33,143 +33,125 @@ until CMake 3.30 so we can't use it yet.
3333
3434So to support clang downloaded from llvm.org which uses the MSVC frontend
3535by default, we need to test for it. ]]
36- function ( compiler_detection )
37- if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
38- if ( ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL MSVC )
39- message ( "Using clang-cl" )
40- set ( IS_CLANG "0" PARENT_SCOPE )
41- set ( IS_MSVC "1" PARENT_SCOPE )
42- set ( NOT_MSVC "0" PARENT_SCOPE )
43- endif ()
44- endif ()
45- endfunction ( )
46-
47- function ( common_compiler_flags )
36+ function (compiler_detection )
37+ if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
38+ if (${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL MSVC )
39+ message ("Using clang-cl" )
40+ set (IS_CLANG "0" PARENT_SCOPE )
41+ set (IS_MSVC "1" PARENT_SCOPE )
42+ set (NOT_MSVC "0" PARENT_SCOPE )
43+ endif ()
44+ endif ()
45+ endfunction ()
4846
49- target_compile_features (${TARGET_NAME}
50- PUBLIC
51- cxx_std_17
52- )
47+ function (common_compiler_flags )
48+ target_compile_features (${TARGET_NAME} PUBLIC cxx_std_17 )
5349
5450 # These compiler options reflect what is in godot/SConstruct.
55- target_compile_options ( ${TARGET_NAME}
51+ target_compile_options (
52+ ${TARGET_NAME}
5653 PUBLIC
5754 # Disable exception handling. Godot doesn't use exceptions anywhere, and this
5855 # saves around 20% of binary size and very significant build time.
5956 $<${DISABLE_EXCEPTIONS} :
60- $<${NOT_MSVC} :-fno -exceptions >
57+ $<${NOT_MSVC} :-fno -exceptions >
6158 >
62-
6359 # Enabling Debug Symbols
6460 $<${DEBUG_SYMBOLS} :
65- # Adding dwarf -4 explicitly makes stacktraces work with clang builds ,
66- # otherwise addr2line doesn 't understand them .
67- $<${NOT_MSVC} :
68- -gdwarf -4
69- $<IF :${IS_DEV_BUILD} ,-g3 ,-g2 >
70- >
61+ # Adding dwarf -4 explicitly makes stacktraces work with clang builds ,
62+ # otherwise addr2line doesn 't understand them .
63+ $<${NOT_MSVC} :
64+ -gdwarf -4
65+ $<IF :${IS_DEV_BUILD} ,-g3 ,-g2 >
66+ >
7167 >
72-
7368 $<${IS_DEV_BUILD} :
74- $<${NOT_MSVC} :-fno -omit -frame -pointer -O0 >
69+ $<${NOT_MSVC} :-fno -omit -frame -pointer
70+ -O0 >
7571 >
76-
7772 $<${HOT_RELOAD} :
78- $<${IS_GNU} :-fno -gnu -unique >
73+ $<${IS_GNU} :-fno -gnu -unique >
7974 >
80-
81- # MSVC only
82- $<${IS_MSVC} :
75+ # MSVC only
76+ $<${IS_MSVC} :
8377 # /MP isn 't valid for clang -cl with msvc frontend
8478 $<$<CXX_COMPILER_ID :MSVC >:/MP ${PROC_N} >
8579 /W4
86-
8780 # Disable warnings which we don 't plan to fix .
88- /wd4100 # C4100 (unreferenced formal parameter ): Doesn 't play nice with polymorphism .
89- /wd4127 # C4127 (conditional expression is constant )
90- /wd4201 # C4201 (non -standard nameless struct /union ): Only relevant for C89 .
91- /wd4244 # C4244 C4245 C4267 (narrowing conversions ): Unavoidable at this scale .
81+ /wd4100 # C4100 (unreferenced formal parameter ): Doesn 't play nice with polymorphism .
82+ /wd4127 # C4127 (conditional expression is constant )
83+ /wd4201 # C4201 (non -standard nameless struct /union ): Only relevant for C89 .
84+ /wd4244 # C4244 C4245 C4267 (narrowing conversions ): Unavoidable at this scale .
9285 /wd4245
9386 /wd4267
94- /wd4305 # C4305 (truncation ): double to float or real_t , too hard to avoid .
95- /wd4514 # C4514 (unreferenced inline function has been removed )
96- /wd4714 # C4714 (function marked as __forceinline not inlined )
97- /wd4820 # C4820 (padding added after construct )
98-
87+ /wd4305 # C4305 (truncation ): double to float or real_t , too hard to avoid .
88+ /wd4514 # C4514 (unreferenced inline function has been removed )
89+ /wd4714 # C4714 (function marked as __forceinline not inlined )
90+ /wd4820 # C4820 (padding added after construct )
9991 /utf -8
100- >
101-
102- # Clang and GNU common options
103- $<$<OR :${IS_CLANG} ,${IS_GNU} >:
92+ >
93+ # Clang and GNU common options
94+ $<$<OR :${IS_CLANG} ,${IS_GNU} >:
10495 -Wall
10596 -Wctor -dtor -privacy
10697 -Wextra
10798 -Wno -unused -parameter
10899 -Wnon -virtual -dtor
109100 -Wwrite -strings
110- >
111-
112- # Clang only
113- $<${IS_CLANG} :
101+ >
102+ # Clang only
103+ $<${IS_CLANG} :
114104 -Wimplicit -fallthrough
115105 -Wno -ordered -compare -function -pointers
116- >
117-
118- # GNU only
119- $<${IS_GNU} :
106+ >
107+ # GNU only
108+ $<${IS_GNU} :
120109 -Walloc -zero
121110 -Wduplicated -branches
122111 -Wduplicated -cond
123112 -Wno -misleading -indentation
124113 -Wplacement -new =1
125114 -Wshadow -local
126115 -Wstringop -overflow =4
127-
128116 # Bogus warning fixed in 8+.
129117 $<${GNU_LT_V8} :-Wno -strict -overflow >
130-
131118 $<${GNU_GE_V9} :-Wattribute -alias =2>
132-
133119 # Broke on MethodBind templates before GCC 11.
134120 $<${GNU_GT_V11} :-Wlogical -op >
135-
136121 # Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it .
137122 $<${GNU_LT_V11} :-Wno -type -limits >
138-
139123 # False positives in our error macros , see GH -58747.
140124 $<${GNU_GE_V12} :-Wno -return -type >
141- >
125+ >
142126 )
143127
144- target_compile_definitions (${TARGET_NAME}
128+ target_compile_definitions (
129+ ${TARGET_NAME}
145130 PUBLIC
146131 GDEXTENSION
147-
148132 # features
149- $<${DEBUG_FEATURES} :DEBUG_ENABLED DEBUG_METHODS_ENABLED >
150-
133+ $<${DEBUG_FEATURES} :DEBUG_ENABLED
134+ DEBUG_METHODS_ENABLED >
151135 $<${IS_DEV_BUILD} :DEV_ENABLED >
152-
153136 $<${HOT_RELOAD} :HOT_RELOAD_ENABLED >
154-
155137 $<$<STREQUAL :${GODOT_PRECISION} ,double >:REAL_T_IS_DOUBLE >
156-
157138 $<${IS_MSVC} :$<${DISABLE_EXCEPTIONS} :_HAS_EXCEPTIONS =0>>
158139 )
159140
160- target_link_options ( ${TARGET_NAME}
141+ target_link_options (
142+ ${TARGET_NAME}
161143 PUBLIC
162144 $<${IS_MSVC} :
163- /WX # treat link warnings as errors .
164- /MANIFEST :NO # We dont need a manifest
145+ /WX # treat link warnings as errors .
146+ /MANIFEST :NO # We dont need a manifest
165147 >
166-
167148 $<${DEBUG_SYMBOLS} :$<${IS_MSVC} :/DEBUG :FULL >>
168149 $<$<NOT :${DEBUG_SYMBOLS} >:
169- $<${IS_GNU} :-s >
170- $<${IS_CLANG} :-s >
171- $<${IS_APPLECLANG} :-Wl ,-S -Wl ,-x -Wl ,-dead_strip >
150+ $<${IS_GNU} :-s >
151+ $<${IS_CLANG} :-s >
152+ $<${IS_APPLECLANG} :-Wl ,-S
153+ -Wl ,-x
154+ -Wl ,-dead_strip >
172155 >
173156 )
174-
175157endfunction ()
0 commit comments