# using cpack with install of auxiliary includes/libraries like those of ExternalProject\_Add

**URL:** <https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669>\
**Category:** Code\
**Created:** [October 14, 2022, 10:47pm UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669 "2022-10-14T22:47:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gonzalo\_Garramuno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gonzalo_garramuno/32/265_2.png) [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Post date:** [October 14, 2022, 10:47pm UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/1 "2022-10-14T22:47:56Z")

</div>

I have a project that depends on a git submodule and several static libraries that are built with add\_subdirectory and they all have install commands to install the libraries and header files in CMAKE\_INSTALL\_PREFIX/lib, /include. I invoke the main cmake command CMakeLists.txt, with:

$ cd build  
$ cmake … -DCMAKE\_BUILD\_TYPE=Release -DCMAKE\_INSTALL\_PREFIX=$PWD/install -DCMAKE\_PREFIX\_PATH=$PWD/install (+ flags for the submodule )l  
$ cmake --build . -j 4 -config Release

This works perfectly and it creates a executable binary, .h files, .so and .a libraries in the right places (build/bin/, build/include and build/lib/ respectively).  
My problem now is trying to pack the binary into a tar.gz or similar package. My problem is two fold:

1. It packs alll the .h files, .a files and all that is in the bin directory, in the binary distribution when I only need to pack the main executable, a shell start up script and the .so files. I need a way to set a regex in some variable to exclude the unwanted files and directories.

2. It installs it into a path that mimics my CMAKE\_INSTALL\_PREFIX (the full $PWD/install inside the tar.gz file, which is /home/$USER/code/ directory and leaves the CPACK\_INSTALL\_PREFIX path empty),. This is me probably using CPACK\_INSTALL\_PREFIX wrong, my guess.

---

<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:** [October 16, 2022, 2:50pm UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/2 "2022-10-16T14:50:18Z")

</div>

> [@Gonzalo\_Garramuno](#):
>
> It packs alll the .h files, .a files and all that is in the bin directory, in the binary distribution when I only need to pack the main executable, a shell start up script and the .so files. I need a way to set a regex in some variable to exclude the unwanted files and directories.

If you run just the install, does the install tree look like what you want? If not, you’ll probably have to fix `install()` commands (or the variables that feed into them) in the tree. As for excluding files, `COMPONENTS` can be used to tell CPack to only install certain parts of the project.

I’m also not sure that `CMAKE_PREFIX_PATH` is something you need to set; that is usually for dependencies as it mostly help `find_*` commands search more places.

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Garramuno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gonzalo_garramuno/32/265_2.png) [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Post date:** [January 4, 2023, 2:31am UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/3 "2023-01-04T02:31:56Z")

</div>

Thanks for your help, Ben. I managed to solve the issue indeed with COMPONENT for Linux and Windows. However it seems it does not work for macOS Bundle CPack generator.

I have, for example:

add\_library(mrvCore STATIC ${SOURCES} ${HEADERS})

install(TARGETS mrvCore  
ARCHIVE DESTINATION lib  
LIBRARY DESTINATION lib  
RUNTIME DESTINATION bin  
PUBLIC\_HEADER DESTINATION include/mrv/mrvCore  
COMPONENT libraries )

…etc…

add\_executable(mrViewer WIN32 ${SOURCES} ${HEADERS})

install(TARGETS mrViewer  
RUNTIME DESTINATION bin COMPONENT applications  
LIBRARY DESTINATION lib COMPONENT libraries  
ARCHIVE DESTINATION lib COMPONENT libraries )

…etc…  
set(CPACK\_COMPONENTS\_ALL applications )  
set(CPACK\_COMPONENT\_APPLICATIONS\_DISPLAY\_NAME “mrViewer2 Application”)

include(CPack)

---

<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, 2023, 4:08am UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/4 "2023-01-04T04:08:01Z")

</div>

I’m not that familiar with any interop between components and the bundle generator (I’ve used `DragNDrop`); macOS packaging is certainly an outlier though, so there’s probably some detail that is useful (though I don’t know what it is off hand).

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Garramuno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gonzalo_garramuno/32/265_2.png) [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Post date:** [January 4, 2023, 9:41am UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/5 "2023-01-04T09:41:54Z")

</div>

I looked at the source code. The Bundle generator does not support COMPONENT installation, while DragNDrop does.  
Do you have a sample of DragNDrop? Idealy, I am looking for a way to deal with dylibs. Currently, I have a bash script used to start the application that sets the environment’s DYLD\_FALLBACK\_LIBRARY\_PATH to look for my dylib libraries in the local install location, but I read there’s a fixup\_bundle() script.

---

<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, 2023, 2:08pm UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669/6 "2023-01-04T14:08:21Z")

</div>

I’d avoid CMake’s `fixup_bundle()` as it has…limitations (especially on macOS) both in performance and handling complex rpath setups. Rather than `DYLD_FALLBACK_LIBRARY_PATH`, I recommend using `@executable_path` and/or `@loader_path` as makes sense (either in library IDs or as rpath entries), but this requires editing all of the library metadata consistently. The `*.apple.*` code in [this directory](https://gitlab.kitware.com/paraview/common-superbuild/-/tree/master/cmake/scripts) has much better performance and behavior if you want to adapt it. Note that the script prefers to write direct library IDs rather than using `@rpath` at all because of how complicated the latter can get.
