Samuel
Samuel

Reputation: 6227

How can I package the installed files in CMAKE

I install some files into a folder with CMake Install command. Then I want to package the folder into a zip or tar. How can i do it in cmake. I mean thar after executing the make install I can also get the zip file

PS: I have tried

install(CODE "execute_process(COMMAND tar -cf ${CMAKE_PROJECT_NAME}.tar ${CMAKE_PROJECT_NAME}
                              WORKING_DIRECTORY ${CMAKE_BINARY_DIR})")

But the install order of CMake is undefined across different directories

Upvotes: 2

Views: 3600

Answers (2)

zaufi
zaufi

Reputation: 7119

You can use cpack. The easiest way just include(CPack) into your root CMakeLists.txt, then make package would be available. Default formats exactly what you asked (.zip for Windows, various .tar for *NIX). To make other packages (RPM, DEB, MSI, EXE) you better to get familiar with documentation.

Upvotes: 3

k0n3ru
k0n3ru

Reputation: 703

Since you the install order is undefined across the directories,you can try stating the dependency explicitly or make a list of all directories to be installed and use it in DEPENDS of your custom command which will install the package. cmake -P cmake_install.cmake will install the files to your directory.

    add_custom_command(
        OUTPUT ${tar_package}
        DEPENDS ${deps}

        # Install in a temporary dir
        COMMAND cmake
            -DCOMPONENT=${component}
            -DCMAKE_INSTALL_PREFIX=${install_dir}
            -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
        # make tar or whatever you want
        COMMAND tar -czf
            ${tar_package}
            -C ${install_dir} .
    )

Upvotes: 1

Related Questions