Custom command run in source directory builds target every time
Custom command run in source directory builds target every time regardless whether output exists and whether it is newer than dependency:
add_custom_command(
OUTPUT two
COMMAND grep train one > two
DEPENDS one
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(
dummy
DEPENDS two
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
If WORKING_DIRECTORY parameters are removed - then everything works as expected: custom command is run only if output file(s) aren't present, or if dependency is updated. CMake version 3.19.1.