[CMake] Cmake + ninja and OBJECT_OUTPUTS

wouter.van at kleunen.nl wouter.van at kleunen.nl
Tue Aug 21 04:02:41 EDT 2012


I use the following rule to generate a precompiled header:

# Macro for creating precompiled headers
macro(add_precompiled_header HEADERFILE TRIGGERFILE SOURCESVAR)
set_source_files_properties(${${SOURCESVAR}}
  PROPERTIES
  COMPILE_FLAGS "/Yu${HEADERFILE}
/Fp${CMAKE_CURRENT_BINARY_DIR}/precompiled.pch"
  OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/precompiled.pch"
)
set_source_files_properties(${TRIGGERFILE}
  PROPERTIES
  COMPILE_FLAGS "/Yc${HEADERFILE}
/Fp${CMAKE_CURRENT_BINARY_DIR}/precompiled.pch"
  OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/precompiled.pch"
)
set(${SOURCESVAR} ${${SOURCESVAR}} ${TRIGGERFILE})
endmacro(add_precompiled_header)

The precompiled header file is generated as an extra output of the
triggerfile compilation, using the OBJECT_OUTPUTS. However this second
output of the build rule is not handled correctly.

When I delete the precompiled header file, it is not generated again. The
compilation of the triggerfile is not done again.

Within the ninja build file, a rule such as this is added for the
OBJECT_OUTPUTS:

build precompiled.pch: phony ..\precompiled_h.cpp.obj

So the precompiled.pch depends on the object file of the trigger file.
However when I delete precompiled.pch manually, it is not generated again.




More information about the CMake mailing list