Skip to content

Commit af8f04c

Browse files
committed
Privatise and Tidy
There are tiny issues that don't effect the build that can be cleaned. And flags that can be made private to not effect consumers. Remove RPATH_USE_ORIGIN from static libs add INTERFACE_POSITION_INDEPENDENT_CODE ON reset GODOT_ARCH property to SYSTEM_ARCH for macos because universal add MACOSX_RPATH to test target remove redundant properties from test target remove redundant and PUBLIC cxx_std_17 compile feature Change compiler options to PRIVATE, tested on godot-cpp-test, and orchestrator
1 parent 97c16d3 commit af8f04c

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

cmake/common_compiler_flags.cmake

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
1919
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
2020
set( NOT_MSVC "$<NOT:$<CXX_COMPILER_ID:MSVC>>" )
2121

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>" )
22+
set( GNU_LT_V8 "$<${IS_GNU}:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>>" )
23+
set( GNU_GE_V9 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>>" )
24+
set( GNU_GT_V11 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>>" )
25+
set( GNU_LT_V11 "$<${IS_GNU}:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>>" )
26+
set( GNU_GE_V12 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>>" )
2727

2828
#[[ Check for clang-cl with MSVC frontend
2929
The compiler is tested and set when the project command is called.
@@ -46,19 +46,12 @@ endfunction( )
4646

4747
function( common_compiler_flags TARGET_NAME )
4848

49-
target_compile_features(${TARGET_NAME}
50-
PUBLIC
51-
cxx_std_17
52-
)
53-
5449
# These compiler options reflect what is in godot/SConstruct.
5550
target_compile_options( ${TARGET_NAME}
56-
PUBLIC
51+
PRIVATE
5752
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
5853
# saves around 20% of binary size and very significant build time.
59-
$<${DISABLE_EXCEPTIONS}:
60-
$<${NOT_MSVC}:-fno-exceptions>
61-
>
54+
$<${DISABLE_EXCEPTIONS}:$<${NOT_MSVC}: -fno-exceptions >>
6255

6356
# Enabling Debug Symbols
6457
$<${DEBUG_SYMBOLS}:
@@ -74,16 +67,16 @@ function( common_compiler_flags TARGET_NAME )
7467
$<${NOT_MSVC}:-fno-omit-frame-pointer -O0>
7568
>
7669

77-
$<${HOT_RELOAD}:
78-
$<${IS_GNU}:-fno-gnu-unique>
79-
>
70+
$<${HOT_RELOAD}:$<${IS_GNU}: -fno-gnu-unique>>
8071

8172
# MSVC only
8273
$<${IS_MSVC}:
8374
# /MP isn't valid for clang-cl with msvc frontend
8475
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
8576
/W4
8677

78+
/W4 # Warning level 4 (informational) warnings that aren't off by default.
79+
8780
# Disable warnings which we don't plan to fix.
8881
/wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
8982
/wd4127 # C4127 (conditional expression is constant)
@@ -95,8 +88,6 @@ function( common_compiler_flags TARGET_NAME )
9588
/wd4514 # C4514 (unreferenced inline function has been removed)
9689
/wd4714 # C4714 (function marked as __forceinline not inlined)
9790
/wd4820 # C4820 (padding added after construct)
98-
99-
/utf-8
10091
>
10192

10293
# Clang and GNU common options
@@ -124,51 +115,50 @@ function( common_compiler_flags TARGET_NAME )
124115
-Wplacement-new=1
125116
-Wshadow-local
126117
-Wstringop-overflow=4
118+
>
127119

128-
# Bogus warning fixed in 8+.
129-
$<${GNU_LT_V8}:-Wno-strict-overflow>
120+
# Bogus warning fixed in 8+.
121+
$<${GNU_LT_V8}: -Wno-strict-overflow >
130122

131-
$<${GNU_GE_V9}:-Wattribute-alias=2>
123+
$<${GNU_GE_V9}: -Wattribute-alias=2 >
132124

133-
# Broke on MethodBind templates before GCC 11.
134-
$<${GNU_GT_V11}:-Wlogical-op>
125+
# Broke on MethodBind templates before GCC 11.
126+
$<${GNU_GT_V11}: -Wlogical-op >
135127

136-
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
137-
$<${GNU_LT_V11}:-Wno-type-limits>
128+
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
129+
$<${GNU_LT_V11}: -Wno-type-limits >
130+
131+
# False positives in our error macros, see GH-58747.
132+
$<${GNU_GE_V12}: -Wno-return-type >
138133

139-
# False positives in our error macros, see GH-58747.
140-
$<${GNU_GE_V12}:-Wno-return-type>
141-
>
142134
)
143135

144136
target_compile_definitions(${TARGET_NAME}
145137
PUBLIC
146138
GDEXTENSION
147139

148140
# features
149-
$<${DEBUG_FEATURES}:DEBUG_ENABLED DEBUG_METHODS_ENABLED>
141+
$<${DEBUG_FEATURES}: DEBUG_ENABLED DEBUG_METHODS_ENABLED >
150142

151143
$<${IS_DEV_BUILD}:DEV_ENABLED>
152144

153145
$<${HOT_RELOAD}:HOT_RELOAD_ENABLED>
154146

155-
$<$<STREQUAL:${GODOT_PRECISION},double>:REAL_T_IS_DOUBLE>
147+
$<$<STREQUAL:${GODOT_PRECISION},double>: REAL_T_IS_DOUBLE >
156148

157-
$<${IS_MSVC}:$<${DISABLE_EXCEPTIONS}:_HAS_EXCEPTIONS=0>>
149+
$<${IS_MSVC}:$<${DISABLE_EXCEPTIONS}: _HAS_EXCEPTIONS=0 >>
158150
)
159151

160152
target_link_options( ${TARGET_NAME}
161-
PUBLIC
162-
$<${IS_MSVC}:
163-
/WX # treat link warnings as errors.
164-
/MANIFEST:NO # We dont need a manifest
165-
>
153+
PRIVATE
154+
$<${IS_MSVC}: /WX /MANIFEST:NO >
155+
# /WX # treat link warnings as errors.
156+
# /MANIFEST:NO # We dont need a manifest
166157

167-
$<${DEBUG_SYMBOLS}:$<${IS_MSVC}:/DEBUG:FULL>>
168158
$<$<NOT:${DEBUG_SYMBOLS}>:
169-
$<${IS_GNU}:-s>
170-
$<${IS_CLANG}:-s>
171-
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
159+
$<${IS_GNU}: -s >
160+
$<${IS_CLANG}: -s >
161+
$<${IS_APPLECLANG}: -Wl,-S -Wl,-x -Wl,-dead_strip >
172162
>
173163
)
174164

cmake/godotcpp.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ function( godotcpp_generate )
294294
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
295295

296296
COMPILE_WARNING_AS_ERROR ${GODOT_WARNING_AS_ERROR}
297+
297298
POSITION_INDEPENDENT_CODE ON
298-
BUILD_RPATH_USE_ORIGIN ON
299+
INTERFACE_POSITION_INDEPENDENT_CODE ON
299300

300301
PREFIX lib
301302
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}${DEV_TAG}.${SYSTEM_ARCH}"

cmake/macos.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ function( macos_generate TARGET_NAME )
3636
set_target_properties( ${TARGET_NAME}
3737
PROPERTIES
3838

39+
# Specify multiple architectures for universal builds
3940
OSX_ARCHITECTURES "${OSX_ARCH}"
41+
GODOT_ARCH ${SYSTEM_ARCH}
4042
)
4143

4244
target_compile_definitions(${TARGET_NAME}

test/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ target_link_libraries( godot-cpp-test
2020
PRIVATE
2121
godot-cpp::${TEST_TARGET} )
2222

23+
# These compiler options reflect what is in godot/SConstruct.
24+
target_compile_options( godot-cpp-test
25+
PRIVATE
26+
# Interpret source code files using utf8
27+
$<${IS_MSVC}:/utf-8>
28+
)
29+
2330
### Get useful properties of the library
2431
get_target_property( GODOT_PLATFORM godot-cpp::${TEST_TARGET} GODOT_PLATFORM )
2532
get_target_property( GODOT_TARGET godot-cpp::${TEST_TARGET} GODOT_TARGET )
@@ -56,13 +63,15 @@ if( CMAKE_SYSTEM_NAME STREQUAL Darwin )
5663

5764
set_target_properties( godot-cpp-test
5865
PROPERTIES
59-
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
60-
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
6166

6267
OUTPUT_NAME "gdexample.macos.${TEST_TARGET}${DEV_TAG}"
6368
SUFFIX ""
6469

6570
#macos options
6671
OSX_ARCHITECTURES "${OSX_ARCH}"
72+
73+
# enable RPATH on MACOS, with the BUILD_RPATH_USE_ORIGIN
74+
# this should allow loading libraries from relative paths on macos.
75+
MACOSX_RPATH ON
6776
)
6877
endif ()

0 commit comments

Comments
 (0)