CMP0116 Does not properly rewrite depfiles with multiple outputs
I am converting my custom command from invoking a code generator once per output file to generating multiple output files at once.
The end result of this is that instead of calling
CodeGenerator --header-A Foo.idl -o Bindings/FooA.h
CodeGenerator --implementation-A Foo.idl -o Bindings/FooA.cpp
CodeGenerator --header-B Foo.idl -o Bindings/FooB.h
CodeGenerator --implementation-B Foo.idl -o Bindings/FooB.cpp
I will just call
CodeGenerator Foo.idl -o Bindings
And it will figure out that it needs to generate Bindings/FooA.h, Bindings/FooA.cpp, Bindings/FooB.h and Bindings/FooB.cpp
Previously, we had a depfile for each command:
add_custom_command(
OUTPUT "${bindings_src}"
COMMAND "$<TARGET_FILE:Lagom::BindingsGenerator>" "--${bindings_type}" -o "${bindings_src}.tmp" --depfile "${bindings_src}.d"
${include_paths} "${LIBWEB_INPUT_FOLDER}/${class}.idl" "${LIBWEB_INPUT_FOLDER}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${bindings_src}.tmp" "${bindings_src}"
COMMAND "${CMAKE_COMMAND}" -E remove "${bindings_src}.tmp"
VERBATIM
DEPENDS Lagom::BindingsGenerator
MAIN_DEPENDENCY ${class}.idl
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${bindings_src}.d
)
Which looks like so:
Bindings/XMLHttpRequestEventTargetConstructor.h: \
/home/andrew/serenity/Userland/Libraries/LibWeb/XHR/XMLHttpRequestEventTarget.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventHandler.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/AbortSignal.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventTarget.idl
This gets transformed into the proper generated depfile via the policy like so:
Userland/Libraries/LibWeb/Bindings/XMLHttpRequestEventTargetConstructor.h: \
/home/andrew/serenity/Userland/Libraries/LibWeb/XHR/XMLHttpRequestEventTarget.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventHandler.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/AbortSignal.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventTarget.idl
However my new depfile that's generated ends up looking like this, from this custom command:
Bindings/XMLHttpRequestEventTargetConstructor.h Bindings/XMLHttpRequestEventTargetConstructor.cpp Bindings/XMLHttpRequestEventTargetPrototype.h Bindings/XMLHttpRequestEventTargetPrototype.cpp: \
/home/andrew/serenity/Userland/Libraries/LibWeb/XHR/XMLHttpRequestEventTarget.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventHandler.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/AbortSignal.idl \
/home/andrew/serenity/Userland/Libraries/LibWeb/DOM/EventTarget.idl
The generated depfile ends up being an empty file. It seems that the depfile rewriter doesn't understand the multiple output format?
This might be user error, but looking at the BNF from https://cmake.org/cmake/help/latest/command/add_custom_command.html#grammar-token-depfile-targets I should be able to specify multiple outputs like this.
As a workaround, I can just disable CMP0116 and manually fix up the paths.