How to exclude files/dirs from CPack binary using CMake

7k views Asked by At

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
)
1

There are 1 answers

4
vinograd47 On BEST ANSWER

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