<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><div>not working with the last cmakelist I have which is:</div><div><br></div>>> 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>  message("target_link_libraries - lib is ${lib}")<br>endforeach(lib)<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 TRUE)<br>SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_RPATH}")<br># add the automatically determined parts of the RPATH<br># which point to directories outside the build tree to the install RPATH<br>SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)<br># the RPATH to be used when installing, but only if it's not a system directory<br>LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)<br>IF("${isSystemDir}" STREQUAL "-1")<br>   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_RPATH}")<br>ENDIF("${isSystemDir}" STREQUAL "-1")<br>foreach(dir ${PETSc_LIBRARY_DIRS})<br>  link_directories(main PUBLIC ${dir})<br>  message("link_directories - dir is ${dir}")<br>  set(CMAKE_INSTALL_RPATH "${dir};${CMAKE_INSTALL_RPATH}")<br>endforeach(dir)<br>message("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")<br><br>include(CTest)<br>enable_testing()<br>add_test(NAME main COMMAND "mpirun -n 2 ./main" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")</div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Don Hinton" <hintonda@gmail.com><br><b>À: </b>"Franck Houssen" <franck.houssen@inria.fr><br><b>Cc: </b>"Andreas Naumann" <Andreas-Naumann@gmx.net>, "CMake Mail List" <cmake@cmake.org><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 17:47:19<br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><div dir="ltr">Are you still doing this at the end?  You are overwriting here, not adding.<div><br></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">IF("${isSystemDir}" STREQUAL "-1")</span><br style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")</span><br style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">ENDIF("${isSystemDir}" STREQUAL "-1")</span><br></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif">Also, do not use ':', use ';' instead as a separator.  Or use 'list(APPEND ...), to add to a list.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 4, 2018 at 8:34 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>nope !... :D<br></div><div><br></div><hr id="m_-1436670033624782906zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><span class=""><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br></span><b>Envoyé: </b>Jeudi 4 Janvier 2018 16:52:53<span class=""><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><div><br><div class="gmail_quote"><div dir="auto">On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen <<a href="mailto:franck.houssen@inria.fr" target="_blank">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"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><hr id="m_-1436670033624782906m_-4529413231888781811zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>De: </b>"Don Hinton" <<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br><b>Cc: </b>"Andreas Naumann" <<a href="mailto:Andreas-Naumann@gmx.net" target="_blank">Andreas-Naumann@gmx.net</a>>, <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br><b>Envoyé: </b>Jeudi 4 Janvier 2018 10:43:28</blockquote></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br><b>Objet: </b>Re: [CMake] RPATH for pkg-config<br><div><br></div><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></blockquote></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div><div>Yes. That's the problem: I need to add a completely different path.<br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><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></blockquote><div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>See does not work<br></div><div><br></div><div>>> more ../CMakeLists.txt <br>...</div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br>foreach(dir ${PETSc_LIBRARY_DIRS})<br>  link_directories(main PUBLIC ${dir})<br>  message("link_directories - dir is ${dir}")<br>  set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")<br>endforeach(dir)</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">s/:/;/</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div></div></div></blockquote><div dir="auto">You need to use a semicolon instead is a colon as a cmake list separator.</div></div></div></span></blockquote><div><br></div><div><br></div><div>I wish it could have worked. Don't understand.<br></div><div><br></div><div>I added a message<br></div><span class=""><div><br></div><div>>> cmake ..; make VERBOSE=1<br>...<br></div></span><div><span class="">target_link_libraries - lib is -L/home/fghoussen/Documents/INRIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib<br></span>CMAKE_INSTALL_RPATH: /home/fghoussen/Documents/INRIA/petsc/local/lib;/usr/local/lib;/usr/local/lib;<br>...<br></div><div>>> ldd main<br></div><div>    linux-vdso.so.1 (0x00007ffdec8e8000)<br>    libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 (0x00007f429a28a000)<br>    libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x00007f4299f94000)<br>    libpetsc.so.3.8 => not found<br><div><br></div></div><div><div class="h5"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...</div><div>SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)<br>...<br></div><div><br></div><div>>> cmake ..; make VERBOSE=1<br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...<br>target_link_libraries - lib is -L/home/fghoussen/Documents/INRIA/petsc/local/lib<br>target_link_libraries - lib is -lpetsc<br>link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib</div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>...<br>[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o<br>/usr/bin/c++   -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/home/fghoussen/Documents/INRIA/petsc/local/include   -o CMakeFiles/main.dir/main.cpp.o -c /home/fghoussen/Downloads/cmake/rpath-pkgconfig/main.cpp<br>[100%] Linking CXX executable main<br>/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1<br>/usr/bin/c++     CMakeFiles/main.dir/main.cpp.o  -o main -Wl,-rpath,/usr/lib/x86_64-linux-gnu/openmpi/lib /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so -L/home/fghoussen/Documents/INRIA/petsc/local/lib -lpetsc <br>make[2]: Leaving directory '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'<br>[100%] Built target main<br>make[1]: Leaving directory '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'<br>/usr/bin/cmake -E cmake_progress_start /home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD/CMakeFiles 0<br></div><div><br></div><div>>> ldd main<br></div><div>    linux-vdso.so.1 (0x00007ffcd876b000)<br>    libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 (0x00007f9eaba1f000)<br>    libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x00007f9eab729000)<br>    libpetsc.so.3.8 => not found<br><div><br></div><br></div></div></div><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><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" target="_blank">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><div><br></div>----- 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><div><br></div>Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br><div><br></div>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><div><br></div>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br><div><br></div>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><div><br></div>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><div><br></div>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></blockquote><div><br></div></div></div></blockquote></div></div></blockquote><div><br></div></div></div></div></div></blockquote></div><br></div>
</blockquote><div><br></div></div></body></html>