Skip to content

Commit

Permalink
Privatise and Tidy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
enetheru committed Dec 11, 2024
1 parent 27ffd8c commit 4d5b9ef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
72 changes: 31 additions & 41 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
set( NOT_MSVC "$<NOT:$<CXX_COMPILER_ID:MSVC>>" )

set( GNU_LT_V8 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>" )
set( GNU_GE_V9 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>" )
set( GNU_GT_V11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
set( GNU_LT_V11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
set( GNU_GE_V12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )
set( GNU_LT_V8 "$<${IS_GNU}:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>>" )
set( GNU_GE_V9 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>>" )
set( GNU_GT_V11 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>>" )
set( GNU_LT_V11 "$<${IS_GNU}:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>>" )
set( GNU_GE_V12 "$<${IS_GNU}:$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>>" )

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

function( common_compiler_flags TARGET_NAME )

target_compile_features(${TARGET_NAME}
PUBLIC
cxx_std_17
)

# These compiler options reflect what is in godot/SConstruct.
target_compile_options( ${TARGET_NAME}
PUBLIC
PRIVATE
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time.
$<${DISABLE_EXCEPTIONS}:
$<${NOT_MSVC}:-fno-exceptions>
>
$<${DISABLE_EXCEPTIONS}:$<${NOT_MSVC}: -fno-exceptions >>

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

$<${HOT_RELOAD}:
$<${IS_GNU}:-fno-gnu-unique>
>
$<${HOT_RELOAD}:$<${IS_GNU}: -fno-gnu-unique>>

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

/W4 # Warning level 4 (informational) warnings that aren't off by default.

# Disable warnings which we don't plan to fix.
/wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
/wd4127 # C4127 (conditional expression is constant)
Expand All @@ -95,8 +88,6 @@ function( common_compiler_flags TARGET_NAME )
/wd4514 # C4514 (unreferenced inline function has been removed)
/wd4714 # C4714 (function marked as __forceinline not inlined)
/wd4820 # C4820 (padding added after construct)

/utf-8
>

# Clang and GNU common options
Expand Down Expand Up @@ -124,51 +115,50 @@ function( common_compiler_flags TARGET_NAME )
-Wplacement-new=1
-Wshadow-local
-Wstringop-overflow=4
>

# Bogus warning fixed in 8+.
$<${GNU_LT_V8}:-Wno-strict-overflow>
# Bogus warning fixed in 8+.
$<${GNU_LT_V8}: -Wno-strict-overflow >

$<${GNU_GE_V9}:-Wattribute-alias=2>
$<${GNU_GE_V9}: -Wattribute-alias=2 >

# Broke on MethodBind templates before GCC 11.
$<${GNU_GT_V11}:-Wlogical-op>
# Broke on MethodBind templates before GCC 11.
$<${GNU_GT_V11}: -Wlogical-op >

# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
$<${GNU_LT_V11}:-Wno-type-limits>
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
$<${GNU_LT_V11}: -Wno-type-limits >

# False positives in our error macros, see GH-58747.
$<${GNU_GE_V12}: -Wno-return-type >

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

target_compile_definitions(${TARGET_NAME}
PUBLIC
GDEXTENSION

# features
$<${DEBUG_FEATURES}:DEBUG_ENABLED DEBUG_METHODS_ENABLED>
$<${DEBUG_FEATURES}: DEBUG_ENABLED DEBUG_METHODS_ENABLED >

$<${IS_DEV_BUILD}:DEV_ENABLED>

$<${HOT_RELOAD}:HOT_RELOAD_ENABLED>

$<$<STREQUAL:${GODOT_PRECISION},double>:REAL_T_IS_DOUBLE>
$<$<STREQUAL:${GODOT_PRECISION},double>: REAL_T_IS_DOUBLE >

$<${IS_MSVC}:$<${DISABLE_EXCEPTIONS}:_HAS_EXCEPTIONS=0>>
$<${IS_MSVC}:$<${DISABLE_EXCEPTIONS}: _HAS_EXCEPTIONS=0 >>
)

target_link_options( ${TARGET_NAME}
PUBLIC
$<${IS_MSVC}:
/WX # treat link warnings as errors.
/MANIFEST:NO # We dont need a manifest
>
PRIVATE
$<${IS_MSVC}: /WX /MANIFEST:NO >
# /WX # treat link warnings as errors.
# /MANIFEST:NO # We dont need a manifest

$<${DEBUG_SYMBOLS}:$<${IS_MSVC}:/DEBUG:FULL>>
$<$<NOT:${DEBUG_SYMBOLS}>:
$<${IS_GNU}:-s>
$<${IS_CLANG}:-s>
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
$<${IS_GNU}: -s >
$<${IS_CLANG}: -s >
$<${IS_APPLECLANG}: -Wl,-S -Wl,-x -Wl,-dead_strip >
>
)

Expand Down
3 changes: 2 additions & 1 deletion cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ function( godotcpp_generate )
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}

COMPILE_WARNING_AS_ERROR ${GODOT_WARNING_AS_ERROR}

POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
INTERFACE_POSITION_INDEPENDENT_CODE ON

PREFIX lib
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}${DEV_TAG}.${SYSTEM_ARCH}"
Expand Down
2 changes: 2 additions & 0 deletions cmake/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function( macos_generate TARGET_NAME )
set_target_properties( ${TARGET_NAME}
PROPERTIES

# Specify multiple architectures for universal builds
OSX_ARCHITECTURES "${OSX_ARCH}"
GODOT_ARCH ${SYSTEM_ARCH}
)

target_compile_definitions(${TARGET_NAME}
Expand Down
13 changes: 11 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ target_link_libraries( godot-cpp-test
PRIVATE
godot-cpp::${TEST_TARGET} )

# These compiler options reflect what is in godot/SConstruct.
target_compile_options( godot-cpp-test
PRIVATE
# Interpret source code files using utf8
$<${IS_MSVC}:/utf-8>
)

### Get useful properties of the library
get_target_property( GODOT_PLATFORM godot-cpp::${TEST_TARGET} GODOT_PLATFORM )
get_target_property( GODOT_TARGET godot-cpp::${TEST_TARGET} GODOT_TARGET )
Expand Down Expand Up @@ -56,13 +63,15 @@ if( CMAKE_SYSTEM_NAME STREQUAL Darwin )

set_target_properties( godot-cpp-test
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"

OUTPUT_NAME "gdexample.macos.${TEST_TARGET}${DEV_TAG}"
SUFFIX ""

#macos options
OSX_ARCHITECTURES "${OSX_ARCH}"

# enable RPATH on MACOS, with the BUILD_RPATH_USE_ORIGIN
# this should allow loading libraries from relative paths on macos.
MACOSX_RPATH ON
)
endif ()

0 comments on commit 4d5b9ef

Please sign in to comment.