[CMake] Generated files...
Brad King
brad.king at kitware.com
Thu Oct 21 18:46:47 EDT 2004
Lars Pechan wrote:
> Hello,
> I'm having some issues with generated files.
>
> This is the example from the FAQ:
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.c
> COMMAND ${CMAKE_COMMAND}
> ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/bar.c
> ${CMAKE_CURRENT_BINARY_DIR}/foo.c
> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bar.c
> )
> ADD_EXECUTABLE(foo foo.c)
>
> I thought I could do ARGS -E copy_if_different as another means of
> setting up the dependency. Ie if bar.c has changed a new copy operation
> will be done. I tested my theory by doing 'touch' on the original file
> and that didn't have any effect at all. It appears that
> copy_if_different requires more than just a newer timestamp to trigger?
It acutally compares the file contents and copies only if things have
changed. This is not suitable for a custom command because if bar.c
changes its time but not contents then foo.c will not be updated and the
rule will run every time the build is performed.
> The FAQ entry as it is written does trigger on a 'touch'ed source file
> so there is no immediate drama.
>
> However, I have a cvs:ed source tree where I copy some files from
> various directories to build in my out-of-source tree. This means the
> original files are read-only (as they clearly should be). When I do the
> 'touch' test CMake correctly tries to re-copy the touched file but that
> fails since the original copy has been copied as a read-only file. Is
> there any way around this?
This is a known bug in 2.0.3 and will be fixed in 2.0.4.
> Finally, I thought I'd be paranoid and ADDITIONAL_MAKE_CLEAN_FILES to
> blow the sources away. Regardless of whether I do
>
> SET(tlSources init.c chomp.c last.c)
>
> SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
> ${tlSources}) or
>
> FOREACH(srcFile ${tlSources})
> SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${srcFile})
> ENDFOREACH(srcFile)
>
> I end up with a ADDITIONAL_MAKE_CLEAN_FILES in the Makefile consisting
> of the sole entry last.c?
There is only one property and the command "SET"s it. You need to give
it one value:
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
"${tlSources}")
With the double quotes the value becomes one argument and will be set as
the property. Without double quotes the value expands into a list of
arguments to SET_DIRECTORY_PROPERTIES, so only one entry is paired with
the ADDITIONAL_MAKE_CLEAN_FILES property.
-Brad
More information about the CMake
mailing list