[CMake] RPATH for pkg-config
Franck Houssen
franck.houssen at inria.fr
Wed Jan 3 04:08:09 EST 2018
Hello,
How to ask cmake to add a library path (coming from pc file) to rpath ?
I checked this https://cmake.org/Wiki/CMake_RPATH_handling, but still not working. Can somebody help ?
>> more main.cpp
#include <petsc.h>
int main(int argc, char ** argv) {
PetscInitialize(&argc, &argv, NULL, "");
PetscFinalize();
return 0;
}
>> more CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
enable_language(CXX)
find_package(MPI REQUIRED)
find_package(PkgConfig REQUIRED) # Get pkg_check_modules.
pkg_check_modules(PETSc REQUIRED PETSc)
project(main)
add_executable(main main.cpp)
target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH})
target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})
target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS})
foreach(lib ${PETSc_LDFLAGS})
target_link_libraries(main PUBLIC ${lib})
endforeach(lib)
foreach(dir ${PETSc_LIBRARY_DIRS})
link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
endforeach(dir)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
include(CTest)
enable_testing()
add_test(NAME main COMMAND "mpirun -n 2 ./main" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
Now,
>> export PKG_CONFIG_PATH="/path/to/petsc/local/lib/pkgconfig"
>> cmake ..; make => OK
But
>> ldd main
linux-vdso.so.1 (0x00007ffcf23ca000)
libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 (0x00007f68593ea000)
libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x00007f68590f4000)
libpetsc.so.3.8 => not found
and so, make test fails ?!...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180103/462abf58/attachment.html>
More information about the CMake
mailing list