5

I have a project structured like below:

\build
\deps
\src
CMakeLists.txt
clean.cmake

There are some library dependencies located in deps. All these libraries have CMake install command.

After install, the output files will be put in build directory:

\build\fin\bin
\build\fin\lib
\build\fin\include

In my case, I will run cmake package to generate a binary install package, it generates something similar in _CPack_Packages.

The problem is I don't need lib and include to be included in the binary. But I haven't found a solution yet.

I tried the following methods:

  1. CPACK_SOURCE_IGNORE_FILES and CPACK_SOURCE_STRIP_FILES.

These are for packaging the source I think, not working for my case.

  1. Use post install script instal(SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/clean.cmake") to remove the unnecessary files/dirs.

In clean.cmake, if(EXISTS "${CMAKE_INSTALL_PREFIX}/bin/ProjectA.lib") returned FALSE, there is nothing in the ${CMAKE_INSTALL_PREFIX} directory when the script was running, but I can find the files after it finished.

  1. Try to modify install_manifest.txt. I haven't found a way to access this file correctly. I'm not sure this would work.

Thank you for your help!


Edit:

The install command like below:

install(TARGETS ${INS_TARGETS}
    RUNTIME DESTINATION bin COMPONENT applications
    LIBRARY DESTINATION lib COMPONENT libraries
    ARCHIVE DESTINATION lib COMPONENT libraries
)
Madwyn
  • 409
  • 3
  • 13

1 Answers1

7

Try to use component install.

  1. Add component label for each install command:

    install(TARGET app DESTINATION ... COMPONENT applications)
    install(TARGET library DESTINATION ... COMPONENT libraries)
    install(FILES <headers> DESTINATION ... COMPONENT headers)
    
  2. Turn on component install in CPack and list components you want to install:

    set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
    set(CPACK_COMPONENTS_ALL applications)
    include(CPack)
    

More information : http://www.cmake.org/Wiki/CMake:Component_Install_With_CPack

vinograd47
  • 6,320
  • 28
  • 30
  • 1
    I tried to avoid modify the CMake scripts because there are third-party libs. But so far it seems this would be a working solution. Thank you! – Madwyn Dec 23 '14 at 18:43
  • You can specify separate components for `RUNTIME` and for `ARCHIVE`: `install(TARGETS ... RUNTIME DESTINATION lib COMPONENT runtime ARCHIVE DESTINATION lib COMPONENT development)`. – vinograd47 Dec 23 '14 at 18:54
  • 1
    The usage of `set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)` creates a tar for each component. How do you tell it to put all required components into a single package? – Matthew Hoggan Apr 23 '19 at 15:11
  • @MatthewHoggan it creates the components that you set in CPACK_COMPONENTS_ALL. – Mert Mertce Jan 25 '22 at 17:47