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
This commit is contained in:
Frank Voorburg 2022-12-09 10:31:45 +00:00
parent 6d5be72cf6
commit 256e9e74e9
2 changed files with 26 additions and 23 deletions

View File

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

View File

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