Skip to content

Commit

Permalink
Fix up linker flags for gdexample library.
Browse files Browse the repository at this point in the history
  • Loading branch information
enetheru committed Sep 20, 2024
1 parent 291338d commit c684c3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ target_link_options(${PROJECT_NAME} PRIVATE
$<$<OR:${IS_CLANG},${IS_GNU}>:
-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'
>
)
30 changes: 28 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ else()
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
endif()

set( IS_CLANG "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
set( IS_MSVC "$<CXX_COMPILER_ID: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
Expand All @@ -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
$<$<OR:${IS_CLANG},${IS_GNU}>:
-fPIC
-Wwrite-strings
>
)

target_link_options( ${PROJECT_NAME}
PRIVATE
$<$<OR:${IS_CLANG},${IS_GNU}>:
-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}
)

0 comments on commit c684c3c

Please sign in to comment.