[CMake] 'make dist' like target
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Mon Nov 13 12:52:00 EST 2006
On 2006-11-13 11:13+0100 Enrico Scholz wrote:
> I am looking for something which works like 'make dist' and/or 'make
> distcheck' from automake.
cpack (still apparently in beta state) provides this functionality. See
http://www.cmake.org/Wiki/CMake:Packaging_With_CPack for some limited
documentation. There, the emphasis is on the package target which generates
(I am told) a binary distribution. However, there is also the
package_source target which provides (with some help setting up targets to
generate prebuilt files) the same functionality as "make dist" from autotools.
Here are the cpack-related cmake variables we set for the PLplot project.
(You should do something similar in your top-level CMakeLists.txt.)
# Packing stuff
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Scientific Plotting Library
set(CPACK_PACKAGE_VENDOR "PLplot development team")
CACHE INTERNAL "tarball basename"
# The following components are regex's to match anywhere (unless anchored)
# in absolute path + filename to find files or directories to be excluded
# from source tarball.
The effect of the include(CPack) command is to generate
CPackSourceConfig.cmake and do other cpack setup. You can consult that file
for other variables you might want to change.
After the cmake step, then to get the equivalent of "make dist" by running
which runs cpack to generate a source tarball.
The PLplot specifics above are all pretty much consistent with the above
Wiki item except for forcing the CPACK_SOURCE_PACKAGE_FILE_NAME value which
changes the name of the generated tarball from plplot-5.6.1-Source.tar.gz to
plplot-5.6.1.tar.gz.) If you want to force other cpack-related variables,
consult the generated CPackSourceConfig.cmake file.
We have used CPACK_SOURCE_IGNORE_FILES to ignore all backup (*~) files, all
CVS directories, and some directories that are specific to our project.
These regex's (not file globs) are a powerful means of deciding exactly what
you want to go into your source tarball from the source tree. We have a
relatively simple list of excludes above since we always use a separate
build tree and thus always have a relatively clean source tree. Because of
that separate build tree, we also have to establish a custom target to (a)
generate the pre-built files we want to go into the tarball (e.g., built
documentation) and (b) copy those files from the build tree to the source
tree. If you want to see the specifics of how we do that, have a look at
In my opinion, keeping track of all the dist-related stuff (e.g.,
EXTRA_DIST) for automake is a maintenance nightmare so I was extremely happy
to move to the cpack way of creating a source tarball where you merely
specify a list of what is excluded. On the other hand, for CMake/CPack you
do have to make a specific custom target for the pre-built files you want to
go into your source tarball, but that is straightforward if you have some
fundamental knowledge of cmake target and file dependencies.
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
More information about the CMake