[CMake] Why is this custom command run twice?

Michael Wild themiwi at gmail.com
Thu Apr 22 02:34:19 EDT 2010


On 22. Apr, 2010, at 5:12 , Aaron_Wright at selinc.com wrote:

> I'm trying to do something a little weird, and I'm almost there but not 
> quite. I'm trying to generate a file and then run a command based on that 
> file. I only want the command to run when the file changes and thus the 
> generated file changes. Instead the first build I get both custom commands 
> run, and then on a second build, the second custom command runs again, 
> which is not what I want. 
> 
> This is what I got (just an example):
> 
> 
> ADD_CUSTOM_COMMAND(
>   OUTPUT "${PROJECT_BINARY_DIR}/generated.txt"
>   COMMAND ${CMAKE_COMMAND} -E touch "${PROJECT_BINARY_DIR}/generated.txt"
>   DEPENDS "${PROJECT_SOURCE_DIR}/generated.txt")
> 
> ADD_CUSTOM_COMMAND(
>   OUTPUT "${PROJECT_BINARY_DIR}/generated_used.stamp"
>   COMMAND ${CMAKE_COMMAND} -E touch 
> "${PROJECT_BINARY_DIR}/generated_used.stamp"
>   DEPENDS "${PROJECT_BINARY_DIR}/generated.txt"
>   COMMENT "Using generated.txt")
> 
> ADD_CUSTOM_TARGET(
>   ${PROJECT_NAME}
>   DEPENDS "${PROJECT_BINARY_DIR}/generated_used.stamp")
> 
> 
> What I'm I missing? Thanks

Your example works fine for me (using CMake 2.8.1 and Unix Makefiles generator on Mac OS X 10.6.2).

Michael



More information about the CMake mailing list