Aurélien Gâteau

CMake and "make dist", the simpler version

written on Sunday, August 9, 2009

I wrote about using CPack to create a make dist target earlier today, but it turns out there is a much simpler way to do this, thanks to Christophe Fergeau for pointing me to it.

Note that this won't work if your project is not using a version control system (but if you are not, then you are asking for trouble!).

Here are the necessary lines to add to your CMakeLists.txt file if your project is using Git:

set(PROJECT_VERSION "0.2.3")
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${PROJECT_VERSION})
add_custom_target(dist
    COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
        | bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

If your project uses Bazaar, replace the "add_custom_target" line with:

add_custom_target(dist
    COMMAND bzr export --root=${ARCHIVE_NAME}
        ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

If you know how to do this with another version control system, please add a comment!

This post was tagged cmake, make, make dist and tips