[CMake] CPack and configure_file
Eric Noulard
eric.noulard at gmail.com
Tue Jan 11 03:48:27 EST 2011
2011/1/11 Michael Hertling <mhertling at online.de>:
> On 01/11/2011 12:55 AM, Tobias Ellinghaus wrote:
>>
>> Because some information (like latest git commit as version string) is no
>> longer available when using a source package. Of course I can put the
>> generated files into the source tree, but that's kind of against the idea of
>> out-of-source builds.
>
> You might use "cmake --build" in conjunction with a custom target:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
> PROJECT(PKGSRC NONE)
> IF(EXISTS ${CMAKE_SOURCE_DIR}/manifest.txt)
> # In packaged source tree.
> FILE(COPY ${CMAKE_SOURCE_DIR}/manifest.txt
> DESTINATION ${CMAKE_BINARY_DIR})
> ELSE()
> # In original source tree.
> FILE(WRITE ${CMAKE_BINARY_DIR}/manifest.txt "...\n")
> INCLUDE(CPack)
> ADD_CUSTOM_TARGET(pkgsrc
> COMMAND ${CMAKE_COMMAND}
> -E copy ${CMAKE_BINARY_DIR}/manifest.txt
> ${CMAKE_SOURCE_DIR}/manifest.txt
> COMMAND ${CMAKE_COMMAND}
> --build ${CMAKE_BINARY_DIR}
> --target package_source
> COMMAND ${CMAKE_COMMAND}
> -E remove ${CMAKE_SOURCE_DIR}/manifest.txt
> )
> ENDIF()
Nice solution.
> The pkgsrc target prepares the source tree for packaging, builds the
> source package via "cmake --build" and cleans up. AFAICS, writing to
> the source tree is unavoidable in order to achieve your aim,
in fact I think the "real" source for this is the fact the CPack lacks
the notion
of "EXTRA" distribution file which is available with autoconf, EXTRA_DIST var
http://www.gnu.org/software/hello/manual/automake/Basics-of-Distribution.html
or the dist-hook:
http://www.gnu.org/software/hello/manual/automake/The-dist-Hook.html#The-dist-Hook
The fact is CPack doesn't know much about "source package" and
in fact it package source using the CPACK_INSTALLED_DIRECTORIES directory list.
(look at the generated CPackSourceConfig.cmake)
I think you can "emulate" the extra thing of autoconf.
If you want ot package "more" than the source tree with
"package_source" you can try
the following in your main CMakeLists.txt (before include(CPack))
SET(CPACK_SOURCE_INSTALLED_DIRECTORIES
"${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/extra;/extra")
then the content of the directory
${CMAKE_BINARY_DIR}/extra will added in the package source archive
inside "extra" dir.
it should work.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
More information about the CMake
mailing list