Hi all,

I thought it would be interesting to share what I found about CPack.

I am trying to use CPack to package my source files. Some of our headers are 
generated at compilation time from scripts. I am trying to take the generated 
headers (from the binary defs folder) instead of the scripts in my source defs 
folder using cpack source package functionality. The client folder contains 
some different CMake files to use when the headers are present instead of 
generated, this folder should be used instead of the source defs folder too.
 
To do so one has to use a variable that is not in the documentation (or that I 
did not find) that I found by chance: CPACK_SOURCE_INSTALLED_DIRECTORIES. This 
variable expects a pair of folder names. But for it to work one needs to 
include the top-level folder too.
The other variable to use is CPACK_SOURCE_IGNORE_FILE to ignore the source 
folder (this variable is documented).

Top level CMakeLists:

set(CPACK_SOURCE_IGNORE_FILE "~$" "${CMAKE_CURRENT_SOURCE_DIR}/defs/")
set(CPACK_SOURCE_INSTALLED_DIRECTORIES 
   "${CMAKE_CURRENT_SOURCE_DIR}" "."
   "${CMAKE_CURRENT_BINARY_DIR}/defs/generated/" "defs/include/"
   "${CMAKE_CURRENT_SOURCE_DIR}/defs/client/" "defs/"
)
 include(CPack)

# add subfolders and things

# as the headers are generated at compile time we need an extra rule to insure 
they are generated before packing
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
add_dependencies(dist defs) # dist depends on the generation of the headers

So now I can run "make dist" and it will use my binary files instead of the 
source files when creating the package.

I hope this will help other people that may have struggle searching on the web 
on how to replace a file when packaging sources with CPack.

Thomas RICHARD


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to