I'm building 2 targets in my CMake project: libA.so , and libB.so. B depends on A (B->A).
Declaration of target A:
file(GLOB SOURCES "*.cpp")
add_library(A SHARED ${SOURCES})
target_include_directories(A PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>
$<INSTALL_INTERFACE:src/>)
#
# Installation
set(PACKAGE_NAME A)
set(PACKAGE_VERSION 1.0)
install(TARGETS ${PACKAGE_NAME} EXPORT ${PACKAGE_NAME}Targets
ARCHIVE DESTINATION lib/${PACKAGE_NAME}-${PACKAGE_VERSION}
LIBRARY DESTINATION lib/${PACKAGE_NAME}-${PACKAGE_VERSION}
INCLUDES DESTINATION include/${PACKAGE_NAME}-${PACKAGE_VERSION}
export(EXPORT ${PACKAGE_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-${PACKAGE_VERSION}/${PACKAGE_NAME}Targets.cmake"
)
Declaration of target B:
add_library(B SHARED b.cpp)
target_include_directories(B PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:> )
target_link_libraries(B PUBLIC A)
#
# Installation
install(TARGETS B LIBRARY DESTINATION lib/B-1.0)
Now this works well in the code base, B has the right path to A:
ldd /home/user/dev/source_code/lib/libB.so
...
libA.so.1.0 => /home/user/dev/source_code/lib/libA.so.1.0 (0x0000007f7fe40000)
...
Now doing an installation to the system:
sudo make install
they install to:
/usr/local/lib/A-1.0/libA.so.1.0
/usr/local/lib/B-1.0/libB.so
Now testing again
ldd /usr/local/lib/B-1.0/libB.so
...
libA.so.1.0 => not found
...
So it would appear that RPATH is not being set correctly for B upon installation? Why isn't CMake figuring out the correct path to known target A?