So, there are numerous ways to copy files (and directories) at CMake
runtime (file(COPY ...)
, configure_file(...)
and add_custom_command()
all work*), but I haven't yet found out how to make a file or directory copied from the source to build directory appear in an archive generated by CPack. I though that this SO answer would fix it, as it actually links the copying to a target which will then have an install linked to it:
install(TARGET mytarget DESTINATION bin)
whereas I did recognise that the file()
and configure_file()
commands don't have an obvious way to be added to a target. But, this didn't work. So, given a simple CMakeLists.txt, such as the one below, how do I make all of the files (including the exmaple
directory) appear in the archive?!
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
enable_language(FORTRAN)
add_executable(mytarget ${PROJECT_SOURCE_DIR}/myprog.for)
install(TARGETS mytarget DESTINATION bin)
add_custom_command(TARGET mytarget PREBUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/examplefiles ${PROJECT_BINARY_DIR}/examplefiles)
set(CPACK_GENERATOR "TGZ")
include(CPack)
* I haven't yet found out which one of these 3 methods is actually (most?) correct - so any advice on this too will be hugely appreciated