add_custom_command from target does not add dependency on targets dependencies
I have a custom command using a target defined like this:
add_custom_command(OUTPUT cpp_generated.cpp
COMMAND cpp_generator ${CMAKE_CURRENT_LIST_DIR}/index.txt
DEPENDS index.txt)
add_executable(codegenerator main.cpp cpp_generated.cpp)
I noticed that changing cpp_generator.cpp does not result in cpp_generated.cpp
getting re-generated or codegenerator getting rebuild. That is strange, as cmake knows that there is a dependency here. I need to repeat the sources of cpp_generator as dependencies for add_custom_command for this to work, which is not intuitive.