# CPack Dependencies Shared Library

**URL:** https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687
**Category:** Usage
**Tags:** os:linux
**Created:** [August 11, 2020, 6:30pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687 "2020-08-11T18:30:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [August 11, 2020, 6:30pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687/1 "2020-08-11T18:30:46Z")

</div>

Hello,

I’m trying to package my shared library with dependencies and I’m using the below code:

```cmake
#
# CPack Properties
#
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "2")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACKAGE_AUTOREQ YES)
set(CPACK_RPM_PACKAGE_AUTOREQPROV YES)
set(CPACK_RPM_PACKAGE_AUTOPROV YES)

include(CPack)

add_library(sharedlib_ SHARED ${PROJECT_SRCS})
target_link_libraries(sharedlib_ ${PROJECT_LIBS})
target_link_libraries(sharedlib_ ${OpenCV_LIBS} )
target_link_libraries(sharedlib_ amqpcpp )
target_link_libraries(sharedlib_ ssl ev)
set_target_properties(sharedlib_ PROPERTIES VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}" OUTPUT_NAME ${PROJECT_BIN} CLEAN_DIRECT_OUTPUT 1)

install(TARGETS sharedlib_ DESTINATION lib)

```

What i need for to add .so dependencies to rpm file? like:

```auto
 	linux-vdso.so.1 (0x00007ffc35937000)
	libamqpcpp.so.4.1 => not found
	libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007fa39b27d000)
	libev.so.4 => /lib64/libev.so.4 (0x00007fa39b26a000)
	libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007fa39b1a8000)
	libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x00007fa39b0c6000)

```

Thanks!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 4, 2021, 3:09pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687/2 "2021-01-04T15:09:07Z")

</div>

There is a mechanism in RPM to discover and add `.so` dependencies automatically. Why would you need to put them into your package directly? If you do, you can use `file(GET_RUNTIME_DEPENDENCIES)` to find and put them into your package as well. Depending on your install prefix, an rpath of `$ORIGIN` would likely be helpful.

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [January 4, 2021, 3:33pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687/3 "2021-01-04T15:33:44Z")

</div>

Ben,

I implemented something like this:

```auto
install(TARGETS ${BIN} DESTINATION bin)

include(GetPrerequisites)

set(BINARY_LOCATION "${MAINFOLDER}/bin/${BIN}")
get_prerequisites(${BINARY_LOCATION} DEPENDENCIES 0 0 "" "")

foreach(DEPENDENCY_FILE ${DEPENDENCIES})
  get_filename_component(DEPENDENCY_NAME "${DEPENDENCY_FILE}" NAME)
  get_filename_component(DEPENDENCY "${DEPENDENCY_FILE}" REALPATH)
  get_filename_component(DEPENDENCY_PATH "${DEPENDENCY}" DIRECTORY)
  install(FILES ${DEPENDENCY} DESTINATION "${DEPENDENCY_PATH}" )
endforeach()

```

This work fine! but I don’t know if I’m on the right track

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 4, 2021, 7:14pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687/4 "2021-01-04T19:14:28Z")

</div>

It looks sufficient to me. You might want to filter that `${DEPENDENCIES}` list to avoid installing something like `libc.so`, but I don’t know your deployment.

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [January 4, 2021, 9:36pm UTC](https://discourse.cmake.org/t/cpack-dependencies-shared-library/1687/5 "2021-01-04T21:36:53Z")

</div>

You are right I’ll need to filter some dependencies like `libc.so`, I need to do that.
