Invalid dependencies in Ninja Multi-Config with add_dependency() and generated source file
cmake_minimum_required(VERSION 3.17)
project(test C)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.c.in [[int main(void)
{
return 0;
}
]])
add_executable(test ${CMAKE_CURRENT_BINARY_DIR}/main.c)
add_custom_target(gen
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/main.c.in ${CMAKE_CURRENT_BINARY_DIR}/main.c)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/main.c PROPERTIES
GENERATED TRUE)
add_dependencies(test gen)
yields the following error:
ninja: error: 'cmake_object_order_depends_target_test_RELEASE', needed by 'main.c', missing and no known rule to make it
The example should use a BYPRODUCTS
argument inside its add_custom_target()
call, which should fix the issue.