[CMake] Why is this custom command run twice?

Brad King brad.king at kitware.com
Fri Apr 23 14:59:25 EDT 2010


Aaron_Wright at selinc.com wrote:
> This builds ok the first time, but then change the "generated.txt.in"
> and run the build twice and the second time you'll see "Using
> generated.txt" again, which I don't want to see. I've tried VS 2008 and
> NMake, using CMake 2.8 and 2.8.1.

I was able to reproduce this.  There is nothing wrong with the project
that CMake generates in VS.  The problem seems to be with the windows
filesystem timestamp granularity.  The code below changes the touch
into a copy, and the problem goes away.

The code can actually be simpler, too.  CMake 2.8 (and 2.6 I think)
automatically handles relative output files with respect to the
build tree.

-Brad


CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(quick_test)

ADD_CUSTOM_COMMAND(
  OUTPUT generated.txt
  COMMAND ${CMAKE_COMMAND} -E copy
   ${PROJECT_SOURCE_DIR}/generated.txt.in
   ${PROJECT_BINARY_DIR}/generated.txt
  DEPENDS generated.txt.in
  )

ADD_CUSTOM_COMMAND(
  OUTPUT generated_used.stamp
  COMMAND ${CMAKE_COMMAND} -E copy
   ${PROJECT_BINARY_DIR}/generated.txt
   ${PROJECT_BINARY_DIR}/generated_used.stamp
  DEPENDS generated.txt
  COMMENT "Using generated.txt"
  )

ADD_CUSTOM_TARGET(${PROJECT_NAME} DEPENDS generated_used.stamp)


More information about the CMake mailing list