Skip to content

Commit

Permalink
native: switch from -static-* to -rpath
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Oct 11, 2023
1 parent bcfb455 commit 607132a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tests/platform-native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ add_subdirectory("platform")

# -----------------------------------------------------------------------------

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")

# On non-Windows, get the actual libraries paths by asking the compiler.
execute_process(
COMMAND "${CMAKE_SOURCE_DIR}/xpacks/@micro-os-plus/build-helper/dev-scripts/get-libraries-paths.sh" ${CMAKE_CXX_COMPILER}
OUTPUT_VARIABLE CXX_LIBRARY_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_path(GET CMAKE_CXX_COMPILER FILENAME CXX_FILENAME)
message(VERBOSE "${CXX_FILENAME} RPATH: ${CXX_LIBRARY_PATH}")

endif()

# -----------------------------------------------------------------------------

if (ENABLE_RTOS_APIS_TEST)

add_executable(rtos-apis-test)
Expand All @@ -41,6 +56,7 @@ if (ENABLE_RTOS_APIS_TEST)
# https://cmake.org/cmake/help/v3.20/manual/cmake-generator-expressions.7.html
target_link_options(rtos-apis-test PRIVATE
$<$<PLATFORM_ID:Linux,Windows>:-Wl,-Map,platform-bin/rtos-apis-test-map.txt>
$<$<PLATFORM_ID:Linux,Darwin>:-Wl,-rpath,${CXX_LIBRARY_PATH}>
)

target_link_libraries(rtos-apis-test PRIVATE
Expand Down Expand Up @@ -87,6 +103,7 @@ if (ENABLE_MUTEX_STRESS_TEST)
# https://cmake.org/cmake/help/v3.20/manual/cmake-generator-expressions.7.html
target_link_options(mutex-stress-test PRIVATE
$<$<PLATFORM_ID:Linux,Windows>:-Wl,-Map,platform-bin/mutex-stress-test-map.txt>
$<$<PLATFORM_ID:Linux,Darwin>:-Wl,-rpath,${CXX_LIBRARY_PATH}>
)

target_link_libraries(mutex-stress-test PRIVATE
Expand Down Expand Up @@ -130,6 +147,7 @@ if (ENABLE_CMSIS_OS_VALIDATOR_TEST)
# https://cmake.org/cmake/help/v3.20/manual/cmake-generator-expressions.7.html
target_link_options(cmsis-os-validator-test PRIVATE
$<$<PLATFORM_ID:Linux,Windows>:-Wl,-Map,platform-bin/cmsis-os-validator-test-map.txt>
$<$<PLATFORM_ID:Linux,Darwin>:-Wl,-rpath,${CXX_LIBRARY_PATH}>
)

target_link_libraries(cmsis-os-validator-test PRIVATE
Expand Down
5 changes: 3 additions & 2 deletions tests/platform-native/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ target_link_options(platform-native-interface INTERFACE

$<$<PLATFORM_ID:Windows>:-static>

$<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Linux,Darwin>>:-static-libgcc>
$<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Linux,Darwin>>:-static-libstdc++>
# No need for them, -rpath is used.
# $<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Linux,Darwin>>:-static-libgcc>
# $<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Linux,Darwin>>:-static-libstdc++>

$<$<PLATFORM_ID:Darwin>:-Wl,-dead_strip>
$<$<PLATFORM_ID:Linux,Windows>:-Wl,--gc-sections>
Expand Down

0 comments on commit 607132a

Please sign in to comment.