diff --git a/adtools-light/adtools/cmake/CMakeListsPub.cmake b/adtools-light/adtools/cmake/CMakeListsPub.cmake index a68056f..18e5145 100644 --- a/adtools-light/adtools/cmake/CMakeListsPub.cmake +++ b/adtools-light/adtools/cmake/CMakeListsPub.cmake @@ -252,6 +252,24 @@ else () set (LIB_EXT_STR ".a") set (EXE_EXT_STR "") + # NOTE(anjingyu): + # If you want to append or change the rpath/runpath, you have three ways: + # + # 1. target_link_options, RECOMMENDED + # target_link_options (${TARGET_NAME} + # PRIVATE "-Wl,-rpath,$ORIGIN") + # + # 2. set_target_properties with LINK_FLAGS, NOT LINK_OPTIONS, + # because the LINK_OPTIONS will overwrite all the link flags. + # set_target_properties (${TEST_TARGET_NAME} PROPERTIES + # LINK_FLAGS "-Wl,-rpath,$ORIGIN") + # + # 3. set_target_properties with `SKIP_BUILD_RPATH OFF` and BUILD_RPATH, + # this has a side effect: will introduce all the link_directories into + # your rpath/runpath, them are appended by CMake automatically. + # set_target_properties (${TEST_TARGET_NAME} PROPERTIES + # SKIP_BUILD_RPATH OFF + # BUILD_RPATH "$ORIGIN/lib") if (NOT ADMAKE_ENABLE_BUILD_RPATH) set (CMAKE_SKIP_BUILD_RPATH TRUE) endif () diff --git a/adtools-light/docs/faq.md b/adtools-light/docs/faq.md index e2b719c..d2e3c9a 100644 --- a/adtools-light/docs/faq.md +++ b/adtools-light/docs/faq.md @@ -123,3 +123,30 @@ NEXUS_HOST=http:://repository:1804 admake build NEXUS_HOST=http:://repository:1804 admake fetch protobuf ``` +### How to append or change `rpath/runpath` (Unix ONLY)? + +By default, `admake` will disable the `rpath` globally via `set (CMAKE_SKIP_BUILD_RPATH TRUE)`, so you will get clean `Shared Objects` or `ELFs`. + +If you want to append or change the `rpath/runpath`, you have three ways: + +1. `target_link_options`, *RECOMMENDED*: + ``` cmake + target_link_options (${TARGET_NAME} + PRIVATE "-Wl,-rpath,$ORIGIN") + ``` +2. `set_target_properties` with `LINK_FLAGS`, **NOT** `LINK_OPTIONS`, + because the `LINK_OPTIONS` will overwrite all the link flags. + + ``` cmake + set_target_properties (${TEST_TARGET_NAME} PROPERTIES + LINK_FLAGS "-Wl,-rpath,$ORIGIN") + ``` +3. `set_target_properties` with `SKIP_BUILD_RPATH OFF` and `BUILD_RPATH`, + this has a side effect: will introduce all the `link_directories` into + your `rpath/runpath`, them are appended by CMake automatically. + ``` cmake + set_target_properties (${TEST_TARGET_NAME} PROPERTIES + SKIP_BUILD_RPATH OFF + BUILD_RPATH "$ORIGIN") + ``` +