From 256e9e74e9417e5ef37b95f0e82e614f820d7356 Mon Sep 17 00:00:00 2001 From: Frank Voorburg Date: Fri, 9 Dec 2022 10:31:45 +0000 Subject: [PATCH] Refs #1596. Improved rpath handling in CMakeLists.txt. git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@1005 5dc33758-31d5-4daf-9ae8-b24bf3d40d73 --- Host/Source/BootCommander/CMakeLists.txt | 27 +++++++++++------------- Host/Source/LibOpenBLT/CMakeLists.txt | 22 ++++++++++++------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Host/Source/BootCommander/CMakeLists.txt b/Host/Source/BootCommander/CMakeLists.txt index 3508cfbb..1517b0f4 100644 --- a/Host/Source/BootCommander/CMakeLists.txt +++ b/Host/Source/BootCommander/CMakeLists.txt @@ -139,6 +139,16 @@ else() endif() +#*************************************************************************************** +# Search path +#**************************************************************************************** +# Add the path of the executable to the library search path. This way the LibOpenBLT +# shared library can simply be in the same directory as the BootCommander executable. +set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +set(CMAKE_INSTALL_RPATH "\$ORIGIN") + + #*************************************************************************************** # Targets #**************************************************************************************** @@ -148,21 +158,8 @@ add_executable( ${PROG_SRCS} ) -# Add libraries. Note that when compiling with GNU GCC the path of the executable is -# added to the run-time search path for libraries. This way LibOpenBLT's shared -# object file (.so) does not have to be installed in the Linux's library path as long -# as it is located in the same directory as BootCommander's executable. -if(CMAKE_C_COMPILER_ID MATCHES GNU) - # According to the CMake docs, item names starting with '-', but not '-l' or - # '-framework', are treated as linker flags. This means "-Wl" type linker flags can be - # specified here. Use this to add the path of the executable to the library search - # path. This way the LibOpenBLT shared library can simply be in the same directory as - # the BootCommander executable. - target_link_libraries(BootCommander ${LIBOPENBLT_LIBNAME} "-Wl,-rpath,.") -elseif(CMAKE_C_COMPILER_ID MATCHES MSVC) - target_link_libraries(BootCommander ${LIBOPENBLT_LIBNAME}) -endif() - +# Add libraries. +target_link_libraries(BootCommander ${LIBOPENBLT_LIBNAME}) # Only generate the PC-lint taget if the option is enabled. Use "make BootCommander_LINT" # to lint the project sources diff --git a/Host/Source/LibOpenBLT/CMakeLists.txt b/Host/Source/LibOpenBLT/CMakeLists.txt index cecb11ae..9dc13343 100644 --- a/Host/Source/LibOpenBLT/CMakeLists.txt +++ b/Host/Source/LibOpenBLT/CMakeLists.txt @@ -157,6 +157,17 @@ set( ) +#*************************************************************************************** +# Search path +#**************************************************************************************** +# Add the path of the shared library to the library search path. This way an (optional) +# seed and key shared library file can simply be in the same directory as the LibOpenBLT +# shared library. +set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +set(CMAKE_INSTALL_RPATH "\$ORIGIN") + + #*************************************************************************************** # Targets #**************************************************************************************** @@ -177,16 +188,11 @@ if(BUILD_SHARED) add_library(openblt_shared SHARED ${LIB_SRCS}) if(UNIX) # Under Unix the LibUsb library (http://libusb.info/) is needed for the USB support. - # Make sure the libusb-1.0-0 and libusb-1.0-0-dev packages are installed to be able to - # build LibOpenBLT. Example under Debian/Ubuntu: + # Make sure the libusb-1.0-0 and libusb-1.0-0-dev packages are installed to be able + # to build LibOpenBLT. Example under Debian/Ubuntu: # sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev # Additionally, the LibDL is needed for dynamic library loading. - # According to the CMake docs, item names starting with '-', but not '-l' or - # '-framework', are treated as linker flags. This means "-Wl" type linker flags can be - # specified here. Use this to add the path of the shared library to the library search - # path. This way an (optional) seed and key shared library file can simply be in the - # same directory as the LibOpenBLT shared library. - target_link_libraries(openblt_shared usb-1.0 dl "-Wl,-rpath,.") + target_link_libraries(openblt_shared usb-1.0 dl) elseif(WIN32) # Link the Winsock library target_link_libraries(openblt_shared ws2_32 winusb setupapi)