From c684c3cdf5d2c7d61a19723c5aba390a522fe790 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Fri, 20 Sep 2024 19:42:21 +0930 Subject: [PATCH] Fix up linker flags for gdexample library. --- cmake/common_compiler_flags.cmake | 7 +++++++ test/CMakeLists.txt | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cmake/common_compiler_flags.cmake b/cmake/common_compiler_flags.cmake index fd2142cbe1..39c5616bf2 100644 --- a/cmake/common_compiler_flags.cmake +++ b/cmake/common_compiler_flags.cmake @@ -119,6 +119,13 @@ target_link_options(${PROJECT_NAME} PRIVATE $<$: -static-libgcc -static-libstdc++ + > + # reading up on RPATH this is only relevant for unix based systems + # https://stackoverflow.com/questions/107888/is-there-a-windows-msvc-equivalent-to-the-rpath-linker-flag + # Is probably worth putting it behind another guard in the future. + # It appears that gcc silently ignores it on windows + # It's also probably unnecessary to be explicitly stated as CMake has a target property for it. + $<${IS_GNU}: -Wl,-R,'$$ORIGIN' > ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2b7a6d3743..613fa28120 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,10 +15,15 @@ else() message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}") endif() +set( IS_CLANG "$,$>" ) +set( IS_GNU "$" ) +set( IS_MSVC "$" ) + + # Define our godot-cpp library add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ) -target_sources( ${PROJECT_NAME} +target_sources(${PROJECT_NAME} PRIVATE src/example.cpp src/example.h @@ -27,13 +32,34 @@ target_sources( ${PROJECT_NAME} src/tests.h ) -target_link_libraries( ${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} PRIVATE godot::cpp ) +target_compile_options(${PROJECT_NAME} + PRIVATE + $<$: + -fPIC + -Wwrite-strings + > +) + +target_link_options( ${PROJECT_NAME} + PRIVATE + $<$: + -static-libgcc + -static-libstdc++ + > + $<${IS_GNU}: # see comments in the cmake/common_compiler_flags.cmake + -Wl,-R,'$$ORIGIN' + > +) + set_target_properties( ${PROJECT_NAME} PROPERTIES OUTPUT_NAME "gdexample" + POSITION_INDEPENDENT_CODE ON + BUILD_RPATH_USE_ORIGIN ON LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH} RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH} )