Skip to content

Commit

Permalink
rework -rpath list
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Oct 11, 2023
1 parent 96988b4 commit 2babf8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 14 additions & 6 deletions tests/platform-native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ 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_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}")
string(REPLACE ":" ";" cxx_library_path_list ${cxx_library_path})

set(rpath_options_list)
foreach(RPATH IN LISTS cxx_library_path_list)
cmake_path(SET normalized_path NORMALIZE ${RPATH})
list(APPEND rpath_options_list "-Wl,-rpath,${normalized_path}")
endforeach()

cmake_path(GET CMAKE_CXX_COMPILER FILENAME cxx_filename)
message(STATUS "${cxx_filename} RPATH_LIST: ${rpath_options_list}")

endif()

Expand All @@ -56,7 +64,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}>
$<$<PLATFORM_ID:Linux,Darwin>:${rpath_options_list}>
)

target_link_libraries(rtos-apis-test PRIVATE
Expand Down Expand Up @@ -103,7 +111,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}>
$<$<PLATFORM_ID:Linux,Darwin>:${rpath_options_list}>
)

target_link_libraries(mutex-stress-test PRIVATE
Expand Down Expand Up @@ -147,7 +155,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}>
$<$<PLATFORM_ID:Linux,Darwin>:${rpath_options_list}>
)

target_link_libraries(cmsis-os-validator-test PRIVATE
Expand Down
10 changes: 6 additions & 4 deletions tests/platform-native/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(xpack_platform_common_args

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
list(APPEND xpack_platform_common_args
# $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-used-but-marked-unused>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-used-but-marked-unused>
)
endif()

Expand Down Expand Up @@ -85,9 +85,11 @@ target_link_options(platform-native-interface INTERFACE

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

# 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++>
# On Linux no need for statics, -rpath is fine.
# On macOS, GCC 11 gets confused
# dyld[72401]: Symbol not found: (__ZNKSt3_V214error_category10_M_messageB5cxx11Ei)
$<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Darwin>>:-static-libgcc>
$<$<AND:$<C_COMPILER_ID:GNU>,$<PLATFORM_ID:Darwin>>:-static-libstdc++>

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

0 comments on commit 2babf8f

Please sign in to comment.