[CMake] linking cmake targets to cpack targets

Eric Noulard eric.noulard at gmail.com
Fri Feb 27 10:36:40 EST 2009


2009/2/27 Aaron Turner <synfinatic at gmail.com>:
> When I was using autotools, I'd hook up a target "version" to
> "dist-gzip" so that my version.c (which was auto-generated and had my
> svn repo revision in it) was always up to date when I built my source
> tarball.  Is there a way to do that with cpack's package_source
> target?
>
> Doing the obvious:
>
> add_dependencies(package_source version)
>
> Doesn't work since I'm guessing package_source is another one of those "fake" targets.

Yes I think this is worth a feature request regarding
how to "add_dependencies" on builtin target
(install, package_source,  package, etc....)

> Unfortunately, since package_source doesn't depend on
> the ALL target, I can't hook it up that way nor does there seem to be
> anything like a CPACK_SOURCE_INCLUDE_FILES (which would be the
> opposite of CPACK_SOURCE_IGNORE_FILES).

A possible way to do what you want is to create
your own

package_source_cleanly target

with something like:

ADD_CUSTOM_TARGET(package_source_cleanly
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/PackageSourceCleanly.cmake
)

The PackageSourceCleanly.cmake file  is your custom CMake script, which
may force an extra CMake execution before calling cpack itself, for example:

MESSAGE(STATUS "Enforce CMake re-run...")
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} .
                TIMEOUT 3600
                WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
MESSAGE(STATUS "Enforce CMake re-run...Done.")

MESSAGE(STATUS "Package Source running cpack...")
EXECUTE_PROCESS(COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
                TIMEOUT 3600
                WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

MESSAGE(STATUS "Copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz -->
${CPACK_SOURCE_PACKAGE_FILE_NAME}-${WHO_OUT}-${DATE_OUT}.tar.gz")
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy
${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
${CPACK_SOURCE_PACKAGE_FILE_NAME}-clean.tar.gz)
MESSAGE(STATUS "Package backup done in:
${CPACK_SOURCE_PACKAGE_FILE_NAME}-clean.tar.gz")

I do use this kind of "trick" for building dated package backup.
see
http://www.cmake.org/pipermail/cmake/2008-November/025246.html
You'll find a modified version of the scripts sent by Ioan at that time.



-- 
Erk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PackageSnapshot.cmake
Type: application/octet-stream
Size: 1569 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090227/5b769722/attachment-0001.obj>


More information about the CMake mailing list