Allow a custom target to have the same name as the output of add_custom_command
Currently:
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.bin COMMAND touch ARGS ${CMAKE_CURRENT_BINARY_DIR}/foo.bin)
add_custom_target(foo.bin DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/foo.bin)
Results in:
Scanning dependencies of target foo.bin
make[2]: Circular CMakeFiles/foo.bin <- foo.bin dependency dropped.
make[2]: Circular foo.bin <- foo.bin dependency dropped.
Interestingly, the target gets built anyway, albeit every time, whether it's out of date or not.
Targets created with add_executable
and add_library
, by default, generate a file with the name of the target, albeit possibly, though not necessarily, with a prefix (e.g. lib
) and possibly a suffix (e.g. .so
, .exe
, et cetera). This is not possible with custom targets, however, as demonstrated above. This means that the above CMake code would have to be something such as:
add_custom_target(foo_bin DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/foo.bin)
Which means that if one wants to build foo.bin
, they must type make foo_bin
, whereas if they want to make bar.elf
they can use the filename itself: make bar.elf
, creating inconsistency.