using cpack with install of auxiliary includes/libraries like those of ExternalProject_Add

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.

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.