Skip to content

Commit c684c3c

Browse files
committed
Fix up linker flags for gdexample library.
1 parent 291338d commit c684c3c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

cmake/common_compiler_flags.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ target_link_options(${PROJECT_NAME} PRIVATE
119119
$<$<OR:${IS_CLANG},${IS_GNU}>:
120120
-static-libgcc
121121
-static-libstdc++
122+
>
123+
# reading up on RPATH this is only relevant for unix based systems
124+
# https://stackoverflow.com/questions/107888/is-there-a-windows-msvc-equivalent-to-the-rpath-linker-flag
125+
# Is probably worth putting it behind another guard in the future.
126+
# It appears that gcc silently ignores it on windows
127+
# It's also probably unnecessary to be explicitly stated as CMake has a target property for it.
128+
$<${IS_GNU}:
122129
-Wl,-R,'$$ORIGIN'
123130
>
124131
)

test/CMakeLists.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ else()
1515
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
1616
endif()
1717

18+
set( IS_CLANG "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
19+
set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
20+
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
21+
22+
1823
# Define our godot-cpp library
1924
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL )
2025

21-
target_sources( ${PROJECT_NAME}
26+
target_sources(${PROJECT_NAME}
2227
PRIVATE
2328
src/example.cpp
2429
src/example.h
@@ -27,13 +32,34 @@ target_sources( ${PROJECT_NAME}
2732
src/tests.h
2833
)
2934

30-
target_link_libraries( ${PROJECT_NAME}
35+
target_link_libraries(${PROJECT_NAME}
3136
PRIVATE
3237
godot::cpp )
3338

39+
target_compile_options(${PROJECT_NAME}
40+
PRIVATE
41+
$<$<OR:${IS_CLANG},${IS_GNU}>:
42+
-fPIC
43+
-Wwrite-strings
44+
>
45+
)
46+
47+
target_link_options( ${PROJECT_NAME}
48+
PRIVATE
49+
$<$<OR:${IS_CLANG},${IS_GNU}>:
50+
-static-libgcc
51+
-static-libstdc++
52+
>
53+
$<${IS_GNU}: # see comments in the cmake/common_compiler_flags.cmake
54+
-Wl,-R,'$$ORIGIN'
55+
>
56+
)
57+
3458
set_target_properties( ${PROJECT_NAME}
3559
PROPERTIES
3660
OUTPUT_NAME "gdexample"
61+
POSITION_INDEPENDENT_CODE ON
62+
BUILD_RPATH_USE_ORIGIN ON
3763
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH}
3864
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH}
3965
)

0 commit comments

Comments
 (0)