Re: [CMake] CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

2018-01-04 Thread Domen Vrankar
2018-01-04 22:42 GMT+01:00 Sam Lunt :

> Hi Domen,
>
> Thanks for the reply, but that doesn't seem to work for me. I modified
> my example to add this function call:
>
> list(APPEND CPACK_RPM_RELOCATION_PATHS
> ${CPACK_PACKAGING_INSTALL_PREFIX}
> )
>

The documentation states that CPACK_PACKAGING_INSTALL_PREFIX is prepended
so the way you are using it not how it is supposed to be used.

With your example above I'd do something like this:

include(GNUInstallDirs)
install(TARGETS foo
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT Foo_Comp
)

install(TARGETS bar
DESTINATION "a/b/c"
COMPONENT Bar_Comp
)

list(APPEND CPACK_RPM_RELOCATION_PATHS
"${CMAKE_INSTALL_BINDIR}" "a/b/c"
)

set(CPACK_PACKAGING_INSTALL_PREFIX "/")

This will make "/", "/${CMAKE_INSTALL_BINDIR}" and "/a/b/c" relocatable
(and if you want to skip / just set CPACK_PACKAGING_INSTALL_PREFIX).

There was a bug in older versions of CPack that CPACK_PACKAGING_INSTALL_PREFIX
could not be set to / (it was fixed by this commit
https://gitlab.kitware.com/cmake/cmake/merge_requests/583/diffs in CMake
3.9 so you can backport it if you want to as it is a small change to
CPackRPM.cmake file).


>
> that silences the warnings, but it still prepends the
> CPACK_PACKAGING_INSTALL_PREFIX when generating the RPM files, while I
> want it to prepend CPACK_RPM__PACKAGE_PREFIX.
>
> So if I call "rpm -qlp FooBar-0.1.0-Linux-Bar_Comp.rpm", it outputs:
> /tmp_dir/foobar
> /tmp_dir/foobar/bin
> /tmp_dir/foobar/bin/bar
>
> (CPACK_PACKAGING_INSTALL_PREFIX = /tmp_dir/foobar)
>
> I want it to output:
>
> /tmp_dir/bar
> /tmp_dir/bar/bin
> /tmp_dir/bar/bin/bar
>
> (CPACK_RPM_BAR_COMP_PACKAGE_PREFIX = /tmp_dir/bar)
>
> It seems like cpack is prepending the CPACK_PACKAGING_INSTALL_PREFIX
> to any relative paths before actually calling the CPackRPM.cmake
> module, so by the time CPackRPM sees the paths, it is seeing
> /tmp_dir/foobar/bin/bar and /tmp_dir/foobar/bin/foo, while I want it
> to see /tmp_dir/bar/bin/bar and /tmp_dir/foo/bin/foo. Maybe there is
> no way to achieve this currently?
>

What you are trying to achieve seems odd to me particularly since your rpms
will be relocatable so why would you want to create the structure of
/some_dir/bar_dir/bin/repeated_bar_dir instead of /bin/bar or
/tmp_dir/bin/bar with either / for the first case or /tmp_dir for the
second case being relocatable?

Regards,
Domen
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] coding style for modules

2018-01-04 Thread Craig Scott
On Fri, Jan 5, 2018 at 8:09 AM, Alexander Neundorf 
wrote:

> On 2018 M01 4, Thu 05:09:54 CET Dave Milter wrote:
> >
> > c)Include this project as git submodule and use add_subdirectory(libfoo)
>
> the "parent" project will/can influence the behaviour of libfoo then, I
> would
> not recommend this.
>

It depends on the situation, sometimes you explicitly want this. An
advantage of this approach is that libfoo will then be built with the same
set of flags as the main build (apart from those flags it modifies itself).
It also plays nicely with IDE projects because they will typically see all
the sources of libfoo as well as the main project. You can also end up
building just the targets from libfoo that you need instead of building
everything as you would if it was external. The new FetchContent
 module
(on master, not yet in a public release) makes this approach particularly
easy.

-- 
Craig Scott
Melbourne, Australia
https://crascit.com
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

2018-01-04 Thread Sam Lunt
Hi Domen,

Thanks for the reply, but that doesn't seem to work for me. I modified
my example to add this function call:

list(APPEND CPACK_RPM_RELOCATION_PATHS
${CPACK_PACKAGING_INSTALL_PREFIX}
)

that silences the warnings, but it still prepends the
CPACK_PACKAGING_INSTALL_PREFIX when generating the RPM files, while I
want it to prepend CPACK_RPM__PACKAGE_PREFIX.

So if I call "rpm -qlp FooBar-0.1.0-Linux-Bar_Comp.rpm", it outputs:
/tmp_dir/foobar
/tmp_dir/foobar/bin
/tmp_dir/foobar/bin/bar

(CPACK_PACKAGING_INSTALL_PREFIX = /tmp_dir/foobar)

I want it to output:

/tmp_dir/bar
/tmp_dir/bar/bin
/tmp_dir/bar/bin/bar

(CPACK_RPM_BAR_COMP_PACKAGE_PREFIX = /tmp_dir/bar)

It seems like cpack is prepending the CPACK_PACKAGING_INSTALL_PREFIX
to any relative paths before actually calling the CPackRPM.cmake
module, so by the time CPackRPM sees the paths, it is seeing
/tmp_dir/foobar/bin/bar and /tmp_dir/foobar/bin/foo, while I want it
to see /tmp_dir/bar/bin/bar and /tmp_dir/foo/bin/foo. Maybe there is
no way to achieve this currently?

Thanks,
Sam

On Thu, Jan 4, 2018 at 1:51 PM, Domen Vrankar  wrote:
> 2018-01-03 22:40 GMT+01:00 Sam Lunt :
>>
>> I am trying to set a per-component value for
>> CPACK_PACKAGING_INSTALL_PREFIX when using the RPM generator, but I
>> haven't been able to do so.
>>
>> I would like to be able to:
>> 1. Install using "make install" (or cmake --build ${BUILD_DIR}
>> --target install) and have CMAKE_INSTALL_PREFIX control the install
>> location
>> 2. Generate an rpm file for each component such that the rpm is
>> relocatable (i.e. --prefix and --relocate are supported) and each
>> component has a different default installation location
>>
>> The documentation for CPACK_RPM__PACKAGE_PREFIX seems to
>> indicate that it is the correct way to set a per-component install
>> prefix, since it says that CPACK_RPM__PACKAGE_PREFIX "May
>> be used to set per component CPACK_PACKAGING_INSTALL_PREFIX for
>> relocatable RPM packages." However, I am only able to successfully use
>> this if I provide an absolute path to the install command, but that
>> inhibits the use of CMAKE_INSTALL_PREFIX.
>
>
> How about using CPACK_RPM_RELOCATION_PATHS?
> https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_RELOCATION_PATHS
>
> install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/some_dir COMPONENT
> libraries)
> set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
>   "${CMAKE_INSTALL_LIBDIR}")
>
> You specify all the relocation paths for all components and if one or more
> of them are found during package generation that path is written to the
> package as a relocation path.
> You can also use
> https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION
> to discard CPACK_PACKAGING_INSTALL_PREFIX as a relocation path.
>
> This feature can also (is prefered to) be used in combination with
> GNUInstallDirs module
> (https://cmake.org/cmake/help/v3.10/module/GNUInstallDirs.html?highlight=gnuinstalldirs):
>
> include(GNUInstallDirs)
>
> Regards,
> Domen
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Alexander Neundorf
On 2018 M01 4, Thu 10:06:26 CET Franck Houssen wrote:
...
> ...
> target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS})
> foreach(lib ${PETSc_LDFLAGS})
>   target_link_libraries(main PUBLIC ${lib})
>   message("target_link_libraries - lib is ${lib}")
> endforeach(lib)
> 
> foreach(dir ${PETSc_LIBRARY_DIRS})
>   link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
>   message("link_directories - dir is ${dir}")
> endforeach(dir)
> 
> This gives:
> >> cmake ..; make
> 
> ...
> target_link_libraries - lib is -L/path/to/petsc/local/lib
> target_link_libraries - lib is -lpetsc
> link_directories - dir is /path/to/petsc/local/lib

yes, so cmake doesn't know that it will link to /path/to/petsc/local/lib/
libpetsc.so .
I usually recommend to use the results from pkgconfig as input to 
find_library() 
etc. calls, ie. put the directory reported by pkgconfig in the HINTS section of 
find_library(). This should then return the full path to the library, which you 
can then use in target_link_libraries(), and cmake will take care of the 
rpath.

...
> >> ldd main
> 
>   linux-vdso.so.1 (0x7ffebab8a000)
>   libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
> (0x7f36172e3000) libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20
> (0x7f3616fed000) libpetsc.so.3.8 => not found


you can also use readelf or objdump to see the RPATH entry in the ELF file 
directly.

Alex

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] coding style for modules

2018-01-04 Thread Alexander Neundorf
On 2018 M01 4, Thu 05:09:54 CET Dave Milter wrote:
> Hello,
> 
> If there is some libfoo that I want to use in my project,
> and this libfoo has it's own CMakeLists.txt I have 3 options to deal
> with such external dependency:
> 
> a) Treat it like every other external dependency and write cmake code
>   like FindLibFoo.cmake to find libfoo on file system.

This would be a clean solution if you don't want to build libfoo as part of 
your project.

> b)Include this project as git submodule and use ExternalProject to
> invoke `cmake` and `cmake --build`

This would be a clean solution if you want to build libfoo as part of yur 
project.

> 
> c)Include this project as git submodule and use add_subdirectory(libfoo)

the "parent" project will/can influence the behaviour of libfoo then, I would 
not recommend this.

Or use d) as Alan suggests.

Alex

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Don Hinton
Let me send this again for completeness -- left out a couple steps the
first time:

$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(main)

enable_language(CXX)
find_package(MPI REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(PETSc REQUIRED PETSc)

# RPATH variables must be set, and link_directories called. before calling
add_executable.
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_RPATH}:$ORIGIN/../lib:${PETSc_LIBRARY_DIRS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}
-Wl,--enable-new-dtags")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}
-Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}
-Wl,--enable-new-dtags")
link_directories(${PETSc_LIBRARY_DIRS})

add_executable(main main.cpp)

target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH}
${PETSc_INCLUDE_DIRS})
target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES} ${PETSc_LIBRARIES})

install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

$ rm -rf * && cmake -DCMAKE_INSTALL_PREFIX=${HOME}/petsc-test ..
-- The C compiler identification is GNU 5.5.0
-- The CXX compiler identification is GNU 5.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/bin/c++
-- Check for working CXX compiler: /usr/local/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found MPI_C:
/usr/lib/libmpi.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libhwloc.so
-- Found MPI_CXX:
/usr/lib/libmpi_cxx.so;/usr/lib/libmpi.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libhwloc.so
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28")
-- Checking for module 'PETSc'
--   Found PETSc, version 3.8.3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dhinton/test/build

$ make VERBOSE=1
/usr/local/bin/cmake -H/home/dhinton/test -B/home/dhinton/test/build
--check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start
/home/dhinton/test/build/CMakeFiles
/home/dhinton/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dhinton/test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
make[2]: Entering directory '/home/dhinton/test/build'
cd /home/dhinton/test/build && /usr/local/bin/cmake -E cmake_depends "Unix
Makefiles" /home/dhinton/test /home/dhinton/test /home/dhinton/test/build
/home/dhinton/test/build
/home/dhinton/test/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/home/dhinton/test/build/CMakeFiles/main.dir/DependInfo.cmake" is
newer than depender
"/home/dhinton/test/build/CMakeFiles/main.dir/depend.internal".
Dependee
"/home/dhinton/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is
newer than depender
"/home/dhinton/test/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
make[2]: Leaving directory '/home/dhinton/test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
make[2]: Entering directory '/home/dhinton/test/build'
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/usr/local/bin/c++   -I/usr/lib/openmpi/include
-I/usr/lib/openmpi/include/openmpi -I/home/dhinton/usr/include   -o
CMakeFiles/main.dir/main.cpp.o -c /home/dhinton/test/main.cpp
[100%] Linking CXX executable main
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt
--verbose=1
/usr/local/bin/c++ -Wl,--enable-new-dtags
CMakeFiles/main.dir/main.cpp.o  -o main  -L/home/dhinton/usr/lib
-Wl,-rpath,":\$ORIGIN/../lib:/home/dhinton/usr/lib" /usr/lib/libmpi_cxx.so
/usr/lib/libmpi.so /usr/lib/x86_64-linux-gnu/libdl.so
/usr/lib/x86_64-linux-gnu/libhwloc.so -lpetsc
make[2]: Leaving directory '/home/dhinton/test/build'
[100%] Built target main
make[1]: Leaving directory '/home/dhinton/test/build'
/usr/local/bin/cmake -E cmake_progress_start
/home/dhinton/test/build/CMakeFiles 0

$ objdump -x main | grep PATH
  RUNPATH  :$ORIGIN/../lib:/home/dhinton/usr/lib

$ objdump -x main | grep PATH
  RUNPATH  :$ORIGIN/../lib:/home/dhinton/usr/lib
a5459ba277d5:/home/dhinton/test/build $ make install
[100%] Built target main
Install the project...
-- Install configuration: ""
-- Installing: /home/dhinton/petsc-test/bin/main

$ objdump -x ~/petsc-test/bin/main | grep PATH
  RUNPATH  :$ORIGIN/../lib:/home/dhinton/usr/lib


On Thu, Jan 4, 2018 at 12:49 PM, Don Hinton  wrote:

> This is mostly an ordering problem -- you need to setup everything before
> calling add_executable.  Also, I was wrong about using ';' in RPATH
> variables.  

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Don Hinton
This is mostly an ordering problem -- you need to setup everything before
calling add_executable.  Also, I was wrong about using ';' in RPATH
variables.  They should use ':' as in your original since they are used
verbatim.

Here's an example that works:

$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(main)

enable_language(CXX)
find_package(MPI REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(PETSc REQUIRED PETSc)

# RPATH variables must be set, and link_directories called. before calling
add_executable.
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_RPATH}:$ORIGIN/../lib:${PETSc_LIBRARY_DIRS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}
-Wl,--enable-new-dtags")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}
-Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}
-Wl,--enable-new-dtags")
link_directories(${PETSc_LIBRARY_DIRS})

add_executable(main main.cpp)

target_include_directories(main PUBLIC ${MPI_CXX_INCLUDE_PATH}
${PETSc_INCLUDE_DIRS})
target_link_libraries(main PUBLIC ${MPI_CXX_LIBRARIES} ${PETSc_LIBRARIES})

install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

$ make VERBOSE=1
/usr/local/bin/cmake -H/home/dhinton/test -B/home/dhinton/test/build
--check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start
/home/dhinton/test/build/CMakeFiles
/home/dhinton/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dhinton/test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
make[2]: Entering directory '/home/dhinton/test/build'
cd /home/dhinton/test/build && /usr/local/bin/cmake -E cmake_depends "Unix
Makefiles" /home/dhinton/test /home/dhinton/test /home/dhinton/test/build
/home/dhinton/test/build
/home/dhinton/test/build/CMakeFiles/main.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/dhinton/test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
make[2]: Entering directory '/home/dhinton/test/build'
make[2]: Nothing to be done for 'CMakeFiles/main.dir/build'.
make[2]: Leaving directory '/home/dhinton/test/build'
[100%] Built target main
make[1]: Leaving directory '/home/dhinton/test/build'
/usr/local/bin/cmake -E cmake_progress_start
/home/dhinton/test/build/CMakeFiles 0

$ objdump -x main | grep PATH
  RUNPATH  :$ORIGIN/../lib:/home/dhinton/usr/lib

$ make install
[100%] Built target main
Install the project...
-- Install configuration: ""
-- Installing: /home/dhinton/petsc-test/bin/main

$ objdump -x ~/petsc-test/bin/main | grep PATH
  RUNPATH  :$ORIGIN/../lib:/home/dhinton/usr/lib

hth...
don

On Thu, Jan 4, 2018 at 9:13 AM, Franck Houssen 
wrote:

> not working with the last cmakelist I have which is:
>
> >> 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})
>   message("target_link_libraries - lib is ${lib}")
> endforeach(lib)
>
> # 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 TRUE)
> SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;$
> {CMAKE_INSTALL_RPATH}")
> # 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;$
> {CMAKE_INSTALL_RPATH}")
> ENDIF("${isSystemDir}" STREQUAL "-1")
> foreach(dir ${PETSc_LIBRARY_DIRS})
>   link_directories(main PUBLIC ${dir})
>   message("link_directories - dir is ${dir}")
>   set(CMAKE_INSTALL_RPATH "${dir};${CMAKE_INSTALL_RPATH}")
> endforeach(dir)
> message("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")
>
> include(CTest)
> enable_testing()
> add_test(NAME main COMMAND "mpirun -n 2 ./main" WORKING_DIRECTORY
> "${CMAKE_CURRENT_BINARY_DIR}")
>
> --
>
> *De: *"Don Hinton" 
> *À: *"Franck Houssen" 
> *Cc: *"Andreas Naumann" , "CMake Mail List" <
> cmake@cmake.org>
> *Envoyé: *Jeudi 4 Janvier 2018 17:47:19
>
> *Objet: *Re: [CMake] RPATH for pkg-config
>
> Are you still doing this at the end

Re: [CMake] CPack per-component value for CPACK_PACKAGING_INSTALL_PREFIX when using RPM generator

2018-01-04 Thread Domen Vrankar
2018-01-03 22:40 GMT+01:00 Sam Lunt :

> I am trying to set a per-component value for
> CPACK_PACKAGING_INSTALL_PREFIX when using the RPM generator, but I
> haven't been able to do so.
>
> I would like to be able to:
> 1. Install using "make install" (or cmake --build ${BUILD_DIR}
> --target install) and have CMAKE_INSTALL_PREFIX control the install
> location
> 2. Generate an rpm file for each component such that the rpm is
> relocatable (i.e. --prefix and --relocate are supported) and each
> component has a different default installation location
>
> The documentation for CPACK_RPM__PACKAGE_PREFIX seems to
> indicate that it is the correct way to set a per-component install
> prefix, since it says that CPACK_RPM__PACKAGE_PREFIX "May
> be used to set per component CPACK_PACKAGING_INSTALL_PREFIX for
> relocatable RPM packages." However, I am only able to successfully use
> this if I provide an absolute path to the install command, but that
> inhibits the use of CMAKE_INSTALL_PREFIX.
>

How about using CPACK_RPM_RELOCATION_PATHS?
https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_RELOCATION_PATHS

install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/some_dir COMPONENT
libraries)
set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
  "${CMAKE_INSTALL_LIBDIR}")

You specify all the relocation paths for all components and if one or more
of them are found during package generation that path is written to the
package as a relocation path.
You can also use
https://cmake.org/cmake/help/v3.10/module/CPackRPM.html#variable:CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION
to discard CPACK_PACKAGING_INSTALL_PREFIX as a relocation path.

This feature can also (is prefered to) be used in combination with
GNUInstallDirs module (
https://cmake.org/cmake/help/v3.10/module/GNUInstallDirs.html?highlight=gnuinstalldirs
):

include(GNUInstallDirs)

Regards,
Domen
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Franck Houssen
not working with the last cmakelist I have which is: 

>> 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}) 
message("target_link_libraries - lib is ${lib}") 
endforeach(lib) 

# 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 TRUE) 
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_RPATH}") 
# 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;${CMAKE_INSTALL_RPATH}") 
ENDIF("${isSystemDir}" STREQUAL "-1") 
foreach(dir ${PETSc_LIBRARY_DIRS}) 
link_directories(main PUBLIC ${dir}) 
message("link_directories - dir is ${dir}") 
set(CMAKE_INSTALL_RPATH "${dir};${CMAKE_INSTALL_RPATH}") 
endforeach(dir) 
message("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}") 

include(CTest) 
enable_testing() 
add_test(NAME main COMMAND "mpirun -n 2 ./main" WORKING_DIRECTORY 
"${CMAKE_CURRENT_BINARY_DIR}") 

- Mail original -

> De: "Don Hinton" 
> À: "Franck Houssen" 
> Cc: "Andreas Naumann" , "CMake Mail List"
> 
> Envoyé: Jeudi 4 Janvier 2018 17:47:19
> Objet: Re: [CMake] RPATH for pkg-config

> Are you still doing this at the end? You are overwriting here, not adding.

> IF("${isSystemDir}" STREQUAL "-1")
> SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
> ENDIF("${isSystemDir}" STREQUAL "-1")

> Also, do not use ':', use ';' instead as a separator. Or use 'list(APPEND
> ...), to add to a list.

> On Thu, Jan 4, 2018 at 8:34 AM, Franck Houssen < franck.hous...@inria.fr >
> wrote:

> > nope !... :D
> 

> > > De: "Don Hinton" < hinto...@gmail.com >
> > 
> 
> > > À: "Franck Houssen" < franck.hous...@inria.fr >
> > 
> 
> > > Cc: "Andreas Naumann" < andreas-naum...@gmx.net >, cmake@cmake.org
> > 
> 
> > > Envoyé: Jeudi 4 Janvier 2018 16:52:53
> > 
> 
> > > Objet: Re: [CMake] RPATH for pkg-config
> > 
> 

> > > On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen < franck.hous...@inria.fr >
> > > wrote:
> > 
> 

> > > > > De: "Don Hinton" < hinto...@gmail.com >
> > > > 
> > > 
> > 
> 
> > > > > À: "Franck Houssen" < franck.hous...@inria.fr >
> > > > 
> > > 
> > 
> 
> > > > > Cc: "Andreas Naumann" < andreas-naum...@gmx.net >, cmake@cmake.org
> > > > 
> > > 
> > 
> 
> > > > > Envoyé: Jeudi 4 Janvier 2018 10:43:28
> > > > 
> > > 
> > 
> 
> > > > > Objet: Re: [CMake] RPATH for pkg-config
> > > > 
> > > 
> > 
> 

> > > > > The cmake rpath settings handle build/install directories more or
> > > > > less
> > > > > automatically, but you need to add a completely different path.
> > > > 
> > > 
> > 
> 

> > > > Yes. That's the problem: I need to add a completely different path.
> > > 
> > 
> 

> > > > > Try adding the additional path (pretty much every -L you added) to
> > > > > CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.
> > > > 
> > > 
> > 
> 

> > > > See does not work
> > > 
> > 
> 

> > > > >> more ../CMakeLists.txt
> > > 
> > 
> 
> > > > ...
> > > 
> > 
> 

> > > > foreach(dir ${PETSc_LIBRARY_DIRS})
> > > 
> > 
> 
> > > > link_directories(main PUBLIC ${dir})
> > > 
> > 
> 
> > > > message("link_directories - dir is ${dir}")
> > > 
> > 
> 
> > > > set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")
> > > 
> > 
> 
> > > > endforeach(dir)
> > > 
> > 
> 

> > > s/:/;/
> > 
> 

> > > You need to use a semicolon instead is a colon as a cmake list separator.
> > 
> 

> > I wish it could have worked. Don't understand.
> 

> > I added a message
> 

> > >> cmake ..; make VERBOSE=1
> 
> > ...
> 
> > target_link_libraries - lib is
> > -L/home/fghoussen/Documents/INRIA/petsc/local/lib
> 
> > target_link_libraries - lib is -lpetsc
> 
> > link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
> 
> > CMAKE_INSTALL_RPATH:
> > /home/fghoussen/Documents/INRIA/petsc/local/lib;/usr/local/lib;/usr/local/lib;
> 
> > ...
> 
> > >> ldd main
> 
> > linux-vdso.so.1 (0x7ffdec8e8000)
> 
> > libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
> > (0x7f429a28a000)
> 
> > libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x7f4299f94000)
> 
> > libpetsc.so.3.8 => 

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Don Hinton
Are you still doing this at the end?  You are overwriting here, not adding.

IF("${isSystemDir}" STREQUAL "-1")
   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")

Also, do not use ':', use ';' instead as a separator.  Or use 'list(APPEND
...), to add to a list.

On Thu, Jan 4, 2018 at 8:34 AM, Franck Houssen 
wrote:

> nope !... :D
>
> --
>
> *De: *"Don Hinton" 
> *À: *"Franck Houssen" 
> *Cc: *"Andreas Naumann" , cmake@cmake.org
> *Envoyé: *Jeudi 4 Janvier 2018 16:52:53
> *Objet: *Re: [CMake] RPATH for pkg-config
>
>
> On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen 
> wrote:
>
>> --
>>
>> *De: *"Don Hinton" 
>> *À: *"Franck Houssen" 
>> *Cc: *"Andreas Naumann" , cmake@cmake.org
>> *Envoyé: *Jeudi 4 Janvier 2018 10:43:28
>>
>>
>> *Objet: *Re: [CMake] RPATH for pkg-config
>>
>> The cmake rpath settings handle build/install directories more or less
>> automatically, but you need to add a completely different path.
>>
>>
>> Yes. That's the problem: I need to add a completely different path.
>>
>>
>> Try adding the additional path (pretty much every -L you added) to
>> CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.
>>
>>
>> See does not work
>>
>> >> more ../CMakeLists.txt
>> ...
>>
>> foreach(dir ${PETSc_LIBRARY_DIRS})
>>   link_directories(main PUBLIC ${dir})
>>   message("link_directories - dir is ${dir}")
>>   set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")
>> endforeach(dir)
>>
>
> s/:/;/
>
>
>> You need to use a semicolon instead is a colon as a cmake list separator.
>
>
>
> I wish it could have worked. Don't understand.
>
> I added a message
>
> >> cmake ..; make VERBOSE=1
> ...
> target_link_libraries - lib is -L/home/fghoussen/Documents/
> INRIA/petsc/local/lib
> target_link_libraries - lib is -lpetsc
> link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
> CMAKE_INSTALL_RPATH: /home/fghoussen/Documents/INRIA/petsc/local/lib;/usr/
> local/lib;/usr/local/lib;
> ...
> >> ldd main
> linux-vdso.so.1 (0x7ffdec8e8000)
> libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
> (0x7f429a28a000)
> libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20
> (0x7f4299f94000)
> libpetsc.so.3.8 => not found
>
>
>
>> ...
>> SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
>> ...
>>
>> >> cmake ..; make VERBOSE=1
>> ...
>> target_link_libraries - lib is -L/home/fghoussen/Documents/
>> INRIA/petsc/local/lib
>> target_link_libraries - lib is -lpetsc
>> link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
>> ...
>> [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
>> /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
>> [100%] Linking CXX executable main
>> /usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt
>> --verbose=1
>> /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
>> make[2]: Leaving directory '/home/fghoussen/Downloads/
>> cmake/rpath-pkgconfig/BUILD'
>> [100%] Built target main
>> make[1]: Leaving directory '/home/fghoussen/Downloads/
>> cmake/rpath-pkgconfig/BUILD'
>> /usr/bin/cmake -E cmake_progress_start /home/fghoussen/Downloads/
>> cmake/rpath-pkgconfig/BUILD/CMakeFiles 0
>>
>> >> ldd main
>> linux-vdso.so.1 (0x7ffcd876b000)
>> libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
>> (0x7f9eaba1f000)
>> libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20
>> (0x7f9eab729000)
>> libpetsc.so.3.8 => not found
>>
>>
>> Then run cmake with the ‘-v’ option and look at the link command to
>> verify rpath was passed correctly.
>>
>> You can also examine it in a library or executable with ‘objdump-x’.
>>
>> You may want to customize this for your project, but this should get you
>> started.
>>
>> hth...
>> don
>>
>> On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen 
>> wrote:
>>
>>> My understanding is that you need a local copy of FindPETSc.cmake: if
>>> this changes, you don't know it.
>>> That's why I tried to go with the pc file.
>>>
>>> - Mail original -
>>> > De: "Andreas Naumann" 
>>> > À: cmake@cmake.org
>>> > Envoyé: Mercredi 3 Janvier 2018 21:41:51
>>> > Objet: Re: [CMake] RPATH for pkg-config
>>> >
>>> > What about using a FindPETSC-Module? Some hints are
>>> >  *http://jacobmerson.com/2016/01/17/cmake-petsc

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Franck Houssen
nope !... :D 

- Mail original -

> De: "Don Hinton" 
> À: "Franck Houssen" 
> Cc: "Andreas Naumann" , cmake@cmake.org
> Envoyé: Jeudi 4 Janvier 2018 16:52:53
> Objet: Re: [CMake] RPATH for pkg-config

> On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen < franck.hous...@inria.fr >
> wrote:

> > > De: "Don Hinton" < hinto...@gmail.com >
> > 
> 
> > > À: "Franck Houssen" < franck.hous...@inria.fr >
> > 
> 
> > > Cc: "Andreas Naumann" < andreas-naum...@gmx.net >, cmake@cmake.org
> > 
> 
> > > Envoyé: Jeudi 4 Janvier 2018 10:43:28
> > 
> 
> > > Objet: Re: [CMake] RPATH for pkg-config
> > 
> 

> > > The cmake rpath settings handle build/install directories more or less
> > > automatically, but you need to add a completely different path.
> > 
> 

> > Yes. That's the problem: I need to add a completely different path.
> 

> > > Try adding the additional path (pretty much every -L you added) to
> > > CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.
> > 
> 

> > See does not work
> 

> > >> more ../CMakeLists.txt
> 
> > ...
> 

> > foreach(dir ${PETSc_LIBRARY_DIRS})
> 
> > link_directories(main PUBLIC ${dir})
> 
> > message("link_directories - dir is ${dir}")
> 
> > set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")
> 
> > endforeach(dir)
> 

> s/:/;/

> You need to use a semicolon instead is a colon as a cmake list separator.

I wish it could have worked. Don't understand. 

I added a message 

>> cmake ..; make VERBOSE=1 
... 
target_link_libraries - lib is 
-L/home/fghoussen/Documents/INRIA/petsc/local/lib 
target_link_libraries - lib is -lpetsc 
link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib 
CMAKE_INSTALL_RPATH: 
/home/fghoussen/Documents/INRIA/petsc/local/lib;/usr/local/lib;/usr/local/lib; 
... 
>> ldd main 
linux-vdso.so.1 (0x7ffdec8e8000) 
libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 
(0x7f429a28a000) 
libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x7f4299f94000) 
libpetsc.so.3.8 => not found 

> > ...
> 
> > SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
> 
> > ...
> 

> > >> cmake ..; make VERBOSE=1
> 
> > ...
> 
> > target_link_libraries - lib is
> > -L/home/fghoussen/Documents/INRIA/petsc/local/lib
> 
> > target_link_libraries - lib is -lpetsc
> 
> > link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
> 
> > ...
> 
> > [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
> 
> > /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
> 
> > [100%] Linking CXX executable main
> 
> > /usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt
> > --verbose=1
> 
> > /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
> 
> > make[2]: Leaving directory
> > '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'
> 
> > [100%] Built target main
> 
> > make[1]: Leaving directory
> > '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'
> 
> > /usr/bin/cmake -E cmake_progress_start
> > /home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD/CMakeFiles 0
> 

> > >> ldd main
> 
> > linux-vdso.so.1 (0x7ffcd876b000)
> 
> > libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
> > (0x7f9eaba1f000)
> 
> > libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x7f9eab729000)
> 
> > libpetsc.so.3.8 => not found
> 

> > > Then run cmake with the ‘-v’ option and look at the link command to
> > > verify
> > > rpath was passed correctly.
> > 
> 

> > > You can also examine it in a library or executable with ‘objdump-x’.
> > 
> 

> > > You may want to customize this for your project, but this should get you
> > > started.
> > 
> 

> > > hth...
> > 
> 
> > > don
> > 
> 

> > > On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen < franck.hous...@inria.fr >
> > > wrote:
> > 
> 

> > > > My understanding is that you need a local copy of FindPETSc.cmake: if
> > > > this
> > > > changes, you don't know it.
> > > 
> > 
> 
> > > > That's why I tried to go with the pc file.
> > > 
> > 
> 

> > > > - Mail original -
> > > 
> > 
> 
> > > > > De: "Andreas Naumann" < andreas-naum...@gmx.net >
> > > 
> > 
> 
> > > > > À: cmake@cmake.org
> > > 
> > 
> 
> > > > > Envoyé: Mercredi 3 Janvier 2018 21:41:51
> > > 
> > 
> 
> > > > > Objet: Re: [CMake] RPATH for pkg-config
> > > 
> > 
> 
> > > > >
> > > 
> > 
> 
> > > > > What about using a FindPETSC-Module? Some hints are
> > > 
> 

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Don Hinton
On Thu, Jan 4, 2018 at 3:57 AM Franck Houssen 
wrote:

> --
>
> *De: *"Don Hinton" 
> *À: *"Franck Houssen" 
> *Cc: *"Andreas Naumann" , cmake@cmake.org
> *Envoyé: *Jeudi 4 Janvier 2018 10:43:28
>
>
> *Objet: *Re: [CMake] RPATH for pkg-config
>
> The cmake rpath settings handle build/install directories more or less
> automatically, but you need to add a completely different path.
>
>
> Yes. That's the problem: I need to add a completely different path.
>
>
> Try adding the additional path (pretty much every -L you added) to
> CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.
>
>
> See does not work
>
> >> more ../CMakeLists.txt
> ...
>
> foreach(dir ${PETSc_LIBRARY_DIRS})
>   link_directories(main PUBLIC ${dir})
>   message("link_directories - dir is ${dir}")
>   set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")
> endforeach(dir)
>

s/:/;/

You need to use a semicolon instead is a colon as a cmake list separator.


> ...
> SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
> ...
>
> >> cmake ..; make VERBOSE=1
> ...
> target_link_libraries - lib is
> -L/home/fghoussen/Documents/INRIA/petsc/local/lib
> target_link_libraries - lib is -lpetsc
> link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
> ...
> [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
> /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
> [100%] Linking CXX executable main
> /usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt
> --verbose=1
> /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
> make[2]: Leaving directory
> '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'
> [100%] Built target main
> make[1]: Leaving directory
> '/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD'
> /usr/bin/cmake -E cmake_progress_start
> /home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD/CMakeFiles 0
>
> >> ldd main
> linux-vdso.so.1 (0x7ffcd876b000)
> libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20
> (0x7f9eaba1f000)
> libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20
> (0x7f9eab729000)
> libpetsc.so.3.8 => not found
>
>
> Then run cmake with the ‘-v’ option and look at the link command to verify
> rpath was passed correctly.
>
> You can also examine it in a library or executable with ‘objdump-x’.
>
> You may want to customize this for your project, but this should get you
> started.
>
> hth...
> don
>
> On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen 
> wrote:
>
>> My understanding is that you need a local copy of FindPETSc.cmake: if
>> this changes, you don't know it.
>> That's why I tried to go with the pc file.
>>
>> - Mail original -
>> > De: "Andreas Naumann" 
>> > À: cmake@cmake.org
>> > Envoyé: Mercredi 3 Janvier 2018 21:41:51
>> > Objet: Re: [CMake] RPATH for pkg-config
>> >
>> > What about using a FindPETSC-Module? Some hints are
>> >  *http://jacobmerson.com/2016/01/17/cmake-petsc2.html
>> >  *http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake
>> >
>> > Regards,
>> > Andreas
>> >
>> > Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:
>> > > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:
>> > >> 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 
>> > >>
>> > >> 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)
>> > > How does each ${lib} look like ?
>> > > Is it "-lpetsc" or does it have the full path 

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Franck Houssen
- Mail original -

> De: "Don Hinton" 
> À: "Franck Houssen" 
> Cc: "Andreas Naumann" , cmake@cmake.org
> Envoyé: Jeudi 4 Janvier 2018 10:43:28
> Objet: Re: [CMake] RPATH for pkg-config

> The cmake rpath settings handle build/install directories more or less
> automatically, but you need to add a completely different path.

Yes. That's the problem: I need to add a completely different path. 

> Try adding the additional path (pretty much every -L you added) to
> CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.

See does not work 

>> more ../CMakeLists.txt 
... 
foreach(dir ${PETSc_LIBRARY_DIRS}) 
link_directories(main PUBLIC ${dir}) 
message("link_directories - dir is ${dir}") 
set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}") 
endforeach(dir) 
... 
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 
... 

>> cmake ..; make VERBOSE=1 
... 
target_link_libraries - lib is 
-L/home/fghoussen/Documents/INRIA/petsc/local/lib 
target_link_libraries - lib is -lpetsc 
link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib 
... 
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o 
/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 
[100%] Linking CXX executable main 
/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1 
/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 
make[2]: Leaving directory 
'/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD' 
[100%] Built target main 
make[1]: Leaving directory 
'/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD' 
/usr/bin/cmake -E cmake_progress_start 
/home/fghoussen/Downloads/cmake/rpath-pkgconfig/BUILD/CMakeFiles 0 

>> ldd main 
linux-vdso.so.1 (0x7ffcd876b000) 
libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 
(0x7f9eaba1f000) 
libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x7f9eab729000) 
libpetsc.so.3.8 => not found 

> Then run cmake with the ‘-v’ option and look at the link command to verify
> rpath was passed correctly.

> You can also examine it in a library or executable with ‘objdump-x’.

> You may want to customize this for your project, but this should get you
> started.

> hth...
> don

> On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen < franck.hous...@inria.fr >
> wrote:

> > My understanding is that you need a local copy of FindPETSc.cmake: if this
> > changes, you don't know it.
> 
> > That's why I tried to go with the pc file.
> 

> > - Mail original -
> 
> > > De: "Andreas Naumann" < andreas-naum...@gmx.net >
> 
> > > À: cmake@cmake.org
> 
> > > Envoyé: Mercredi 3 Janvier 2018 21:41:51
> 
> > > Objet: Re: [CMake] RPATH for pkg-config
> 
> > >
> 
> > > What about using a FindPETSC-Module? Some hints are
> 
> > > * http://jacobmerson.com/2016/01/17/cmake-petsc2.html
> 
> > > * http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake
> 
> > >
> 
> > > Regards,
> 
> > > Andreas
> 
> > >
> 
> > > Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:
> 
> > > > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:
> 
> > > >> 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 
> 
> > > >>
> 
> > > >> 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)
> 
> > > > How does each ${lib} look like ?
> 
> > > > Is it "-lpetsc" or does it have the full path to th

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Don Hinton
The cmake rpath settings handle build/install directories more or less
automatically, but you need to add a completely different path.

Try adding the additional path (pretty much every -L you added) to
CMAKE_INSTALL_RPATH, and set CMAKE_BUILD_WITH_INSTALL_RPATH=TRUE.

Then run cmake with the ‘-v’ option and look at the link command to verify
rpath was passed correctly.

You can also examine it in a library or executable with ‘objdump-x’.

You may want to customize this for your project, but this should get you
started.

hth...
don

On Thu, Jan 4, 2018 at 1:25 AM Franck Houssen 
wrote:

> My understanding is that you need a local copy of FindPETSc.cmake: if this
> changes, you don't know it.
> That's why I tried to go with the pc file.
>
> - Mail original -
> > De: "Andreas Naumann" 
> > À: cmake@cmake.org
> > Envoyé: Mercredi 3 Janvier 2018 21:41:51
> > Objet: Re: [CMake] RPATH for pkg-config
> >
> > What about using a FindPETSC-Module? Some hints are
> >  *http://jacobmerson.com/2016/01/17/cmake-petsc2.html
> >  *http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake
> >
> > Regards,
> > Andreas
> >
> > Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:
> > > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:
> > >> 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 
> > >>
> > >> 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)
> > > How does each ${lib} look like ?
> > > Is it "-lpetsc" or does it have the full path to the libraries ?
> > > You should use the full path to the libraries, otherwise cmake doesn't
> know
> > > where they are and the RPATH computation will not work.
> > >
> > >> foreach(dir ${PETSc_LIBRARY_DIRS})
> > >> link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
> > >> endforeach(dir)
> > > no, link_directories() in general should not be used.
> > >
> > >> # 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")
> > > If the automatic computation fails, you could add the petsc lib dir
> here as
> > > INSTALL_RPATH
> > >
> > > Alex
> > >
> >
> > --
> >
> > Powered by www.kitware.com
> >
> > Please keep messages on-topic and check the CMake FAQ at:
> > http://www.cmake.org/Wiki/CMake_FAQ
> >
> > Kitware offers various services to support the CMake community. For more
> > information on each offering, please visit:
> >
> > CMake Support: http://cmake.org/cmake/help/support.html
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Follow this link to subscribe/unsubscribe:
> > https://cmake.org/mailman/listinfo/cmake
> >
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit ot

Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Franck Houssen
My understanding is that you need a local copy of FindPETSc.cmake: if this 
changes, you don't know it.
That's why I tried to go with the pc file.

- Mail original -
> De: "Andreas Naumann" 
> À: cmake@cmake.org
> Envoyé: Mercredi 3 Janvier 2018 21:41:51
> Objet: Re: [CMake] RPATH for pkg-config
> 
> What about using a FindPETSC-Module? Some hints are
>  *http://jacobmerson.com/2016/01/17/cmake-petsc2.html
>  *http://www.mcs.anl.gov/petsc/documentation/faq.html#cmake
> 
> Regards,
> Andreas
> 
> Am 03.01.2018 um 21:35 schrieb Alexander Neundorf:
> > On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:
> >> 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 
> >>
> >> 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)
> > How does each ${lib} look like ?
> > Is it "-lpetsc" or does it have the full path to the libraries ?
> > You should use the full path to the libraries, otherwise cmake doesn't know
> > where they are and the RPATH computation will not work.
> >
> >> foreach(dir ${PETSc_LIBRARY_DIRS})
> >> link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
> >> endforeach(dir)
> > no, link_directories() in general should not be used.
> >
> >> # 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")
> > If the automatic computation fails, you could add the petsc lib dir here as
> > INSTALL_RPATH
> >
> > Alex
> >
> 
> --
> 
> Powered by www.kitware.com
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
> 
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
> 
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] RPATH for pkg-config

2018-01-04 Thread Franck Houssen
- Mail original -
> De: "Alexander Neundorf" 
> À: cmake@cmake.org
> Envoyé: Mercredi 3 Janvier 2018 21:35:02
> Objet: Re: [CMake] RPATH for pkg-config
> 
> On 2018 M01 3, Wed 10:08:09 CET Franck Houssen wrote:
> > 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 
> > 
> > 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)
> 
> How does each ${lib} look like ?
> Is it "-lpetsc" or does it have the full path to the libraries ?

I added 2 message: one for target_link_libraries, one for link_directories.

>> more CMakeLists.txt
...
target_include_directories(main PUBLIC ${PETSc_INCLUDE_DIRS})
foreach(lib ${PETSc_LDFLAGS})
  target_link_libraries(main PUBLIC ${lib})
  message("target_link_libraries - lib is ${lib}")
endforeach(lib)

foreach(dir ${PETSc_LIBRARY_DIRS})
  link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
  message("link_directories - dir is ${dir}")
endforeach(dir)

This gives:

>> cmake ..; make
...
target_link_libraries - lib is -L/path/to/petsc/local/lib
target_link_libraries - lib is -lpetsc
link_directories - dir is /path/to/petsc/local/lib

> You should use the full path to the libraries, otherwise cmake doesn't know
> where they are and the RPATH computation will not work.

I expected the same behavior you describe ! That why I added the 
link_directories (with the associated comment) BEFORE setting 
CMAKE_SKIP_BUILD_RPATH and others.

> > 
> > foreach(dir ${PETSc_LIBRARY_DIRS})
> > link_directories(main PUBLIC ${dir}) # Not sure: is this needed ?
> > endforeach(dir)
> 
> no, link_directories() in general should not be used.
> 
> > # 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")
> 
> If the automatic computation fails, you could add the petsc lib dir here as
> INSTALL_RPATH
> 

Do you mean that ?

>> more CMakeLists.txt
...
foreach(dir ${PETSc_LIBRARY_DIRS})
  link_directories(main PUBLIC ${dir})
  message("link_directories - dir is ${dir}")
  set(CMAKE_INSTALL_RPATH "${dir}:${CMAKE_INSTALL_RPATH}")
endforeach(dir)


I've just tried but still not working:

>> cmake ..; make
...
target_link_libraries - lib is -L/home/fghoussen/Documents/INRIA/petsc/local/lib
target_link_libraries - lib is -lpetsc
link_directories - dir is /home/fghoussen/Documents/INRIA/petsc/local/lib
...
[100%] Built target main
>> ldd main
linux-vdso.so.1 (0x7ffebab8a000)
libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 
(0x7f36172e3000)
libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 
(0x7f3616fed000)
libpetsc.so.3.8 => not found


> Alex
> 
> --
> 
> Powered by www.kitware.com
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
> 
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
> 
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake