Browse Source

feat: update FAQ about rpath/runpath

master
anjingyu 1 year ago
parent
commit
ee343869a7
2 changed files with 45 additions and 0 deletions
  1. +18
    -0
      adtools-light/adtools/cmake/CMakeListsPub.cmake
  2. +27
    -0
      adtools-light/docs/faq.md

+ 18
- 0
adtools-light/adtools/cmake/CMakeListsPub.cmake View File

@@ -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 ()


+ 27
- 0
adtools-light/docs/faq.md View File

@@ -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")
```


Loading…
Cancel
Save