On 2013-04-17 12:41, Skippy VonDrake wrote:
Thought I understood this - but alas my implementation is wrong.
Here's my test case with a top-level cmake file and 3 subdirectories:
'src', 'bin' and 'outdir'.
Top level CMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (copyFile)
set (TARGETNAME fooCopy)
set (TARGETDEST ${PROJECT_SOURCE_DIR}/bin)
add_subdirectory (src)
src/CMakeLists.txt
add_executable (${TARGETNAME} main.cpp)
set (input ${CMAKE_CURRENT_SOURCE_DIR}/bin/config.cfg)
set (output ${CMAKE_CURRENT_SOURCE_DIR}/outdir/config.cfg)
add_dependencies(${TARGETNAME} ${output})
add_custom_command(
OUTPUT "${output}"
DEPENDS "${input}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${input}" "${output}"
)
install (TARGETS ${TARGETNAME} DESTINATION ${TARGETDEST})
The config file (config.cfg) is just some text and cpp file is just a
"hello world"
example.
Since the config file is not source included as a dependency in the
add_executable command, I assume my problem is making the target
properly depend on it? Specifically ${TARGETNAME} should depend
on "${output}"?
Hmm... yes, I'm not sure if add_dependencies can be used to add a file
dependency to a target (the documentation only talks about adding other
targets as dependencies).
Usually things like configured files are used as source files, i.e. as
inputs to add_executable, etc.
If for some reason that doesn't work, I believe you can make your
executable dependent on a custom target, which in turn depends on the
output file from your custom command. IOW:
add_custom_command(OUTPUT out DEPENDS in COMMAND stuff)
add_executable(exe sources)
add_custom_target(exe_config DEPENDS out)
add_dependencies(exe exe_config)
If you only have one custom command, you can probably use
add_custom_target to run the command instead, i.e.:
add_custom_target(exe_config DEPENDS in COMMAND stuff)
add_executable(exe sources)
add_dependencies(exe exe_config)
Hope that helps,
--
Matthew
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake