add_custom_target() sometimes builds SOURCES for Visual Studio generators but never for Makefiles
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
With the Visual Studio generator the file another_file.c
is created before target_update_files
is run. With Makefiles another_file.c
is never created even though the Makefile does contain rules to generate the file but the dependencies are incorrect and the build fails with an error.
cmake_minimum_required(VERSION 3.13)
set(WORKS_IN_VS 1)
add_custom_target(target_update_files ALL
DEPENDS genc_do_not_list.txt
SOURCES another_file.c
BYPRODUCTS junkit.txt
COMMAND ${CMAKE_COMMAND} -E copy another_file.c junkit.txt
COMMENT "Processing target_update_files")
add_custom_command(
OUTPUT another_file.c
COMMAND ${CMAKE_COMMAND} -E echo "//auto-gen file" > another_file.c
COMMENT "generate C file another_file"
)
if (WORKS_IN_VS)
add_custom_command(
OUTPUT force_rebuild genc_do_not_list.txt
COMMAND ${CMAKE_COMMAND} -E echo "genc" > genc_do_not_list.txt
COMMENT "generate text files C"
)
endif()
Edited by Fred Baksik