2

Once CMake has successfully built an executable which requires some shared libraries, by using 'ldd', we can easily get the list of shared library dependencies and where we can find them.

For instance, libstdc++ is here: /usr/lib64/libstdc++.so.6

Now we want to make a package (e.g. a .tgz package), we need to include those shared libraries with no doubt.

We can do:

set(DEPENDENCIES /usr/lib64/libstdc++.so.6 /usr/lib64/[libname2] /usr/lib64/[libname3])
foreach(DEPENDENCY ${DEPENDENCIES})
   install(PROGRAMS "${DEPENDENCY}" DESTINATION lib)
endforeach()

Is there a smarter way to achieve the same purpose?

Instead of manually specifying path to all libraries, can we make it an automatic process? Given CMake already knows all the dependencies and the according library path in the link stage, should it be straightforward?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Changfei Deng
  • 21
  • 1
  • 3
  • 1
    Installing **3d-party shared libraries** (like `libstdc++`) is not a thing which packages usually do. Instead, packages assume these libraries being already installed, and install only the libraries created by the project itself. So, your intention seems bad. – Tsyvarev Oct 29 '15 at 11:00
  • 2
    Sometimes - and especially for the system libraries - CMake does not give or know the path of the libraries. It deliberately let the linker choose the correct one. For the shared libraries in your example I share @Tsyvarev concerns. Generally speaking you could use [`GET_PREREQUISITES()`](https://cmake.org/cmake/help/v3.4/module/GetPrerequisites.html) macro to get the installation dependencies. For more details see e.g. [how to use the cmake functions get_prerequisites and get_filename_component for target dependency installation?](http://stackoverflow.com/questions/24367033) – Florian Oct 29 '15 at 12:38

0 Answers0