diff --git a/cmake/common_compiler_flags.cmake b/cmake/common_compiler_flags.cmake index ac3f4490d..39ce591e9 100644 --- a/cmake/common_compiler_flags.cmake +++ b/cmake/common_compiler_flags.cmake @@ -19,11 +19,11 @@ set( IS_GNU "$" ) set( IS_MSVC "$" ) set( NOT_MSVC "$>" ) -set( GNU_LT_V8 "$,8>" ) -set( GNU_GE_V9 "$,9>" ) -set( GNU_GT_V11 "$,11>" ) -set( GNU_LT_V11 "$,11>" ) -set( GNU_GE_V12 "$,12>" ) +set( GNU_LT_V8 "$<${IS_GNU}:$,8>>" ) +set( GNU_GE_V9 "$<${IS_GNU}:$,9>>" ) +set( GNU_GT_V11 "$<${IS_GNU}:$,11>>" ) +set( GNU_LT_V11 "$<${IS_GNU}:$,11>>" ) +set( GNU_GE_V12 "$<${IS_GNU}:$,12>>" ) #[[ Check for clang-cl with MSVC frontend The compiler is tested and set when the project command is called. @@ -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}: @@ -74,9 +67,7 @@ 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}: @@ -84,6 +75,8 @@ function( common_compiler_flags TARGET_NAME ) $<$:/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) @@ -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 @@ -124,21 +115,22 @@ 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} @@ -146,29 +138,27 @@ function( common_compiler_flags TARGET_NAME ) 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> - $<$:REAL_T_IS_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>> $<$: - $<${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 > > ) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index 9bad5ae0d..4ea2d9313 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -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}" diff --git a/cmake/macos.cmake b/cmake/macos.cmake index 1bb4dbcfb..fec0741df 100644 --- a/cmake/macos.cmake +++ b/cmake/macos.cmake @@ -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} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 12e44f163..93fa30d02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 ) @@ -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 ()