From f8d05b0353b8b8956b99fb2cb87d36820b2f66f8 Mon Sep 17 00:00:00 2001 From: Suguru ARAKAWA Date: Wed, 4 Sep 2024 10:22:39 +0900 Subject: [PATCH] build: make RPATH relative. --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 36 +++++------------------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 430d112..1d7d5fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,10 @@ option(BUILD_SHARED_LIBS "build shared libraries instead of static" ON) option(FORCE_INSTALL_RPATH "automatically add library directory of custom prefixes to INSTALL_RPATH" OFF) +if (FORCE_INSTALL_RPATH) + message(DEPRECATION "FORCE_INSTALL_RPATH is obsoleted") +endif (FORCE_INSTALL_RPATH) + option(ENABLE_COVERAGE "enable coverage on debug build" OFF) include(GNUInstallDirs) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 602fcfc..eb86205 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -244,6 +244,7 @@ target_link_libraries(takatori target_compile_definitions(takatori PUBLIC BOOST_ENABLE_ASSERT_DEBUG_HANDLER ) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_link_libraries(takatori PUBLIC Boost::stacktrace_backtrace @@ -268,37 +269,10 @@ if (USE_BOOST_MEMORY_RESOURCE) target_compile_definitions(takatori PUBLIC USE_BOOST_MEMORY_RESOURCE) endif (USE_BOOST_MEMORY_RESOURCE) -# Add INSTALL_RPATH from CMAKE_INSTALL_PREFIX and CMAKE_PREFIX_PATH -# The default behavior of CMake omits RUNPATH if it is already in CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES. -if (FORCE_INSTALL_RPATH) - get_target_property(rpath takatori INSTALL_RPATH) - - # add ${CMAKE_INSTALL_PREFIX}/lib if it is not in system link directories - get_filename_component(p "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ABSOLUTE) - list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${p}" is_system) - if (is_system STREQUAL "-1") - list(APPEND rpath "${p}") - endif() - - # add each ${CMAKE_PREFIX_PATH}/lib - foreach (p IN LISTS CMAKE_PREFIX_PATH) - get_filename_component(p "${p}/${CMAKE_INSTALL_LIBDIR}" ABSOLUTE) - list(APPEND rpath "${p}") - endforeach() - - if (rpath) - set_target_properties(takatori - PROPERTIES - INSTALL_RPATH "${rpath}" - ) - endif() - - # add other than */lib paths - set_target_properties(takatori - PROPERTIES - INSTALL_RPATH_USE_LINK_PATH ON - ) -endif (FORCE_INSTALL_RPATH) +set_target_properties(takatori + PROPERTIES + INSTALL_RPATH "\$ORIGIN/../lib" +) install( TARGETS