Search code examples
cmakepackagingdebcpack

How to add files to debian package with CPack?


I am using Cmake with Cpack to create debian package.

I would like to use Cpack to generate a package that will install that files to specific location. (ex. /usr/lib /usr/include/aaa)

each library and header files are specified in a install command, and I write CPack options and include CPack into root CMakeLists.txt

(sure root and middle CMakeList.txt have only set or add_subdirectory command)

project directory looks like follows.

root(CMakeLists.txt CPack) ┬AAA(CMakeLists.txt)─┬─AAA2(CMakeLists.txt install)-src-include
                           │                    └─AAA3(CMakeLists.txt install)-src-include
                           ├BBB(CMakeLists.txt)─┬─BBB2(CMakeLists.txt install)-src-include
...

install command seems to like:

ADD_LIBRARY(${AAA2} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/${AAA2_SOURCE_DIR}/AAA.c)
INSTALL(TARGETS ${AAA2} DESTINATION /usr/lib)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${AAA_INCLUDE_DIR}/AAA2.h DESTINATION /usr/include/AAA)

I have tried make package with "make install" command with cmake

cpack made debian package but that does not have any file.

what did I do wrong? how can I add files to debian package with cpack?


Solution

  • You're using absolute paths for your install rule DESTINATION values: (i.e., "/usr/lib")

    Use just "lib" instead. Which will be placed underneath CMAKE_INSTALL_PREFIX, since it is not an absolute path.

    You can control the "/usr" part with CMAKE_INSTALL_PREFIX, or with some CPACK_ generator-specific variables, like CPACK_PACKAGING_PREFIX, as needed, later. (Hopefully, you won't even need to, as the default behavior should be largely sufficient based on which type of CPack package you're creating.)

    You should avoid using absolute paths in CMake install rules unless the file must always be installed in that location on all platforms.