CMake-CPack Package Installation Path Nightmare

10,664

Solution 1

I didn't find any documentation to support this, but I did find some bug reports and email archives that seem to suggest that the following is what you should be doing:

set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX /opt/MySuperAwesomePrefix-v.1.2.3)

If CPACK_INSTALL_PREFIX is not set, it will default to CMAKE_INSTALL_PREFIX. Now relative paths from install(... DESTINATION dest) will end up as CPACK_INSTALL_PREFIX/dest inside your package file. This worked when I tried to generate a deb file.

Solution 2

The paths used by the CPACK are taken from the INSTALL directives in your CMakeLists.txt files. This allows the result package to mirror what a 'make install' would do. This keeps the CPACK configuration to a minimum.

So, from an example CMakeLists.txt file:

INSTALL(TARGETS ${APPLICATION} DESTINATION bin)

This will install to /usr/bin or /usr/local/bin. If you wanted to place it in a subdirectory you could do it here:

INSTALL(TARGETS ${APPLICATION} DESTINATION bin/myappdir)

Or entirely different directory:

INSTALL(TARGETS ${APPLICATION} DESTINATION /opt/foo/bar)
Share:
10,664
Peter Lee
Author by

Peter Lee

Peter Lee (Yuefeng Li) owner of leestime.com

Updated on June 06, 2022

Comments

  • Peter Lee
    Peter Lee almost 2 years

    I've been frustrated by the the CMake-CPack for almost one week.

    The bad thing is the CMake-CPack online documentation does not document this part well.

    After googling, I found this variables to use:

    CPACK_PACKAGING_PREFIX          # NOT documented
    CMAKE_INSTALL_PREFIX            # Documented, but the behavior seems weird
    CPACK_INSTALL_PREFIX            # NOT documented
    CPACK_PACKAGE_INSTALL_DIRECTORY # Documented, but this variable does NOT work as the online document described
    CPACK_PACKAGING_INSTALL_PREFIX  # NOT documented
    

    What I am trying to do is: package a Debian package using fakeroot make package, when the package is installed by sudo dpkg -i MyProgramPackageName, install it to /usr/local, with a subdirectory MyProgramPackageName. That is, all files should be installed under /usr/local/MyProgramPackageName-V.1.2.3.

    I've been trying (CMake 2.8.3 and CMake 2.8.5) to tune these variables. I tried so many combinations, but failed.

    The only way succeeded is:

    Set(CPACK_PACKAGING_INSTALL_PREFIX /usr/local/MyProgramPackageName-V.1.2.3)
    

    But this variable is NOT even documented, and the behavior cannot be guaranteed. If you are confused with my question, please advise me when to use CPACK_PACKAGE_INSTALL_DIRECTORY? because the documentation description about this variable is really attractive, and it is really what I want, but I just could not make it working.

    Please advise me.

    Peter

  • Peter Lee
    Peter Lee over 12 years
    I'm confused. I'm using CPACK to package it, so that it will install the app to where I want. In the INSTALL directive, I'm always installing a folder or files to a relative path to the INSTALL_PREFIX/DIRECTORY.
  • Peter Lee
    Peter Lee over 12 years
    I will try your suggestion next Monday, and let you know the results. Thanks.
  • Ryan Pavlik
    Ryan Pavlik over 11 years
    You only want a relative path in the install destination - it will install relative to the CMAKE_INSTALL_PREFIX automatically, no need to specify. Specifying an absolute path is a convenient way to get all this installing stuff messed up.