Skip to content

ninja: absolute path to source breaks rebuild with generated header

I stumbled over an issue that seems to be related to https://public.kitware.com/Bug/view.php?id=14167. I use cmake 3.7.2 and ninja 1.7.2 together with gcc on Windows and Linux.

The following CMakeList.txt requires ninja to be called twice in order to rebuild the executable after modifications of header.txt. The first call of ninja only regenerates header.h from header.txt but doesn't rebuild the executable. Only if I call ninja a second time, it recognizes the modification and triggers the rebuild.

When using make instead of ninja, everything works correctly. This seems to be a bug in cmake 3.7.2 since ninja build files generated with cmake 3.6.2 work correctly too.

cmake_minimum_required(VERSION 3.5)
project(testproject)

add_executable(testproject
	header.h
	main.c
)

add_custom_command(
	OUTPUT header.h
	DEPENDS header.txt
	COMMAND ${CMAKE_COMMAND} -E copy header.txt header.h
	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

testproject.zip

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information