Cpack ingnore or overwite install options from external dependencies

I have the following issue:

I am building an SDK. It includes an external project (specifically: GitHub - ouster-lidar/ouster-sdk: Cross-platform C++ and Python SDK for Ouster LiDAR sensors. Includes tools for visualization, data recording/replay, and sensor configuration · GitHub) It is included through:

include(FetchContent)
FetchContent_Declare(
    ouster-sdk
    GIT_REPOSITORY https://github.com/ouster-lidar/ouster-sdk.git
    GIT_TAG v0.16.2a
    EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(ouster-sdk)

This works, it builds, it runs, …
Specifically it builds this external library as static and includes it into my own libraries.

But now I want to create the distribution package I need to send to my customers, and here things go wrong. What I need is a zip file or equivalent with only my own shared library, its headers and all the cmake code to get it into the customers project. That’s it, just the basics.

My packaging.cmake file:

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# Install the 4 public library targets
install(TARGETS my libraries
    EXPORT abcTargets
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    COMPONENT abc
)

# allow users to use abc:: namespace
install(EXPORT abcTargets
    FILE abcTargets.cmake
    NAMESPACE abc::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/abc
    COMPONENT abc
)

# Generate and install package version and config files
write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/abcConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/abcConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/abcConfig.cmake"
    INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/abc
)

install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/abcConfig.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/abcConfigVersion.cmake"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/abc
    COMPONENT abc
)

# CPack archive configuration
set(CPACK_PROJECT_NAME "abc")
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_NAME "abc")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_STRIP_FILES TRUE)

include(CPack)

And to be fully open, the main CMakeLists.txt is ordered as:

# project definition and project wide settings

# options

# including of third party libraries
Here I include the external library using FetchContent_Declare and FetchContent_MakeAvailable

# Defining my own targets
add_subdirectory(myLibrary)
# each library contains its own install rules for the header files

# packaging
See the other code block for the content of what happens here.

On windows, this creates the expected .zip file. But this zip file still includes all the headers and libraries, and cmake config files from the external library. I don’t want or need those, but I cannot get cpack to stop including them.

On linux, things are worse. It does not create my archive at all. instead, I get an archive called after the external package, with only the contents of the external dependencies. My own libraries are not even included.
Here is some commandline feedback from cpack on linux:

> cpack -G TGZ
CPack: Create package using TGZ
CPack: Install projects
CPack: - Install project: abc []
CPack: Create package
CPack: - package: install/ouster-sdk-Release-0.16.2-Linux-5.15.148-tegra-aarch64.tar.gz generated.

I have tried different things like components and no components, excluding the external library from the all target, setting CPACK_INSTALLED_DIRECTORIES to specific libraries, using claude, … but I cannot seem to make it work.

Can anybody explain to me how I need to setup things to get this to work properly?

Take a look at the CPACK_COMPONENTS_ALL variable from the CPack module. You should be able to restrict which components are installed by modifying the contents of that variable (it must be set before you call include(CPack)).

I don’t know what’s happening on Linux in your case. That sounds like something else is going on.

@craig.scott , yes, this solved indeed the windows issue. Thanks. It now only creates my own libraries as I wanted.

For future reference, what I did in my case, I added the line:

set(CPACK_COMPONENTS_ALL "abc")

just before calling include(CPack).

In my case, the “abc” tag marked all the components I needed, otherwise you must list everything, or, as the documentation suggest, get the full list and remove components you don’t need.

I still have to check the linux issue, but I can only do that in the office. I will report here on that later.
But thanks again Craig.

EDIT: I wanted to point out, that apparently, for this to work correctly, it is important that the FetchContent_Declare call has EXCLUDE_FROM_ALL for the external library. Omitting this will still run the install commands of the external library, even if the components are not included in CPACK_COMPONENTS_ALL . At least for me.

For completeness, I found the error on linux. It was indeed something unrelated. Due to a missing variable in my presets, the install and cpack commands were not even included in the configuration.