<div><div dir="auto">The cmake rpath settings handle build/install directories more or less automatically, but you need to add a completely different path.</div><div dir="auto"><br></div><div dir="auto">Try adding the additional path (pretty much every -L you added) to CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.</div><div dir="auto"><br></div><div dir="auto">Then run cmake with the ‘-v’ option and look at the link command to verify rpath was passed correctly.</div><div dir="auto"><br></div><div dir="auto">You can also examine it in a library or executable with ‘objdump-x’.</div><div dir="auto"><br></div><div dir="auto">You may want to customize this for your project, but this should get you started.</div><div dir="auto"><br></div><div dir="auto">hth...</div><div dir="auto">don</div><br><div class="gmail_quote"><div>On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen <<a href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My understanding is that you need a local copy of FindPETSc.cmake: if this changes, you don't know it.<br>
That's why I tried to go with the pc file.<br>
<br>
----- Mail original -----<br>
> De: "Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>><br>
> À: <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br>
> Envoyé: Mercredi 3 Janvier 2018 21:41:51<br>
> Objet: Re: [CMake] RPATH for pkg-config<br>
><br>
> What about using a FindPETSC-Module? Some hints are<br>
> *<a href="http://jacobmerson.com/2016/01/17/cmake-petsc2.html" rel="noreferrer" target="_blank">http://jacobmerson.com/2016/01/17/cmake-petsc2.html</a><br>
> *<a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake</a><br>
><br>
> Regards,<br>
> Andreas<br>
><br>
> Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:<br>
> > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:<br>
> >> Hello,<br>
> >><br>
> >> How to ask cmake to add a library path (coming from pc file) to rpath ?<br>
> >><br>
> >> I checked this <a href="https://cmake.org/Wiki/CMake_RPATH_handling" rel="noreferrer" target="_blank">https://cmake.org/Wiki/CMake_RPATH_handling</a>, but still not<br>
> >> working. Can somebody help ?<br>
> >>>> more main.cpp<br>
> >> #include <petsc.h><br>
> >><br>
> >> int main(int argc, char ** argv) {<br>
> >> PetscInitialize(&argc, &argv, NULL, "");<br>
> >> PetscFinalize();<br>
> >> return 0;<br>
> >> }<br>
> >><br>
> >>>> more CMakeLists.txt<br>
> >> cmake_minimum_required(VERSION 3.7)<br>
> >> enable_language(CXX)<br>
> >><br>
> >> find_package(MPI REQUIRED)<br>
> >> find_package(PkgConfig REQUIRED) # Get pkg_check_modules.<br>
> >> pkg_check_modules(PETSc REQUIRED PETSc)<br>
> >><br>
> >> project(main)<br>
> >> add_executable(main main.cpp)<br>
> >><br>
> >> target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH})<br>
> >> target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES})<br>
> >><br>
> >> target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS})<br>
> >> foreach(lib ${PETSc_LDFLAGS})<br>
> >> target_link_libraries(main PUBLIC ${lib})<br>
> >> endforeach(lib)<br>
> > How does each ${lib} look like ?<br>
> > Is it "-lpetsc" or does it have the full path to the libraries ?<br>
> > You should use the full path to the libraries, otherwise cmake doesn't know<br>
> > where they are and the RPATH computation will not work.<br>
> ><br>
> >> foreach(dir ${PETSc_LIBRARY_DIRS})<br>
> >> link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?<br>
> >> endforeach(dir)<br>
> > no, link_directories() in general should not be used.<br>
> ><br>
> >> # use, i.e. don't skip the full RPATH for the build tree<br>
> >> SET(CMAKE_SKIP_BUILD_RPATH FALSE)<br>
> >> # when building, don't use the install RPATH already<br>
> >> # (but later on when installing)<br>
> >> SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)<br>
> >> SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")<br>
> > If the automatic computation fails, you could add the petsc lib dir here as<br>
> > INSTALL_RPATH<br>
> ><br>
> > Alex<br>
> ><br>
><br>
> --<br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at:<br>
> <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more<br>
> information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
><br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div></div>