[cmake-developers] [CMake 0013559]: Ninja: Wrong dependency with PCH support

Mathias Gaunard mathias.gaunard at ens-lyon.org
Wed Oct 3 10:47:19 EDT 2012


On 09/25/2012 03:22 PM, Peter Kümmel wrote:
> On 25.09.2012 14:53, Mantis Bug Tracker wrote:
>>
>> The following issue has been SUBMITTED.
>> ======================================================================
>> http://public.kitware.com/Bug/view.php?id=13559
>> ======================================================================
>
> There is the code below in the ninja generator, which doesn't use "real"
> but "order-only" dependency
> (order-only dependency: "build when needed, don't rebuild on changes"
> http://martine.github.com/ninja/manual.html#ref_dependencies)
>
> Isn't this wrong at all?

Somewhat related:

Things like the following

add_custom_command(OUTPUT foo2.cpp
                    COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp ${CMAKE_CURRENT_BINARY_DIR}/foo2.cpp
                    DEPENDS foo.cpp
                   )
set_source_files_properties(foo2.cpp PROPERTIES GENERATED ON)

add_executable(foo foo2.cpp)

Will also add an order-only dependency on the custom command, meaning 
that if foo.cpp changed, we will run the custom command to copy it to 
foo2.cpp, but foo2.cpp won't get recompiled.

Testcase attached, touch foo.cpp and run ninja, foo2.cpp is regenerated 
but not rebuilt.
Manually setting foo2.cpp to OBJECT_DEPENDS on foo.cpp seems to work 
(change set_source_files_properties line with the commented one in 
testcase), but I don't think this should be necessary.

Maybe changing the GENERATED special case in the generator to use 
implicit dependencies would fix it? I'm not sure.

I ran into this problem because in my PCH setup I need to compile the 
same files with different flags, and thus depend on different PCH files 
for each. Since OBJECT_DEPENDS is fixed for a given file, I have to copy 
the source files like above.
-------------- next part --------------
cmake_minimum_required(VERSION 2.8)

file(WRITE foo.cpp "int main() {}")
add_custom_command(OUTPUT foo2.cpp
                   COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp ${CMAKE_CURRENT_BINARY_DIR}/foo2.cpp
                   DEPENDS foo.cpp
                  )

set_source_files_properties(foo2.cpp PROPERTIES GENERATED ON)
#set_source_files_properties(foo2.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp" GENERATED ON)

add_executable(foo foo2.cpp)


More information about the cmake-developers mailing list