add_custom_target(blah) + add_dependencies(blah some_interface) does not build the interface's dependencies when built
This sample cmakelists file demonstrates
add_library(some_interface INTERFACE)
target_link_library(some_interface INTERFACE some collection of real libraries)
add_custom_target(my_build_target)
add_dependencies(my_build_target some_interface)
add_executable(some_exe PRIVATE some_interface)
When configured and built with
cmake -S folder -B build-folder
cmake --build build-folder --target my_build_target
The expectation of the end user is that any non-imported, non-interface, libraries that are transitively depended on by my_build_target
will be built.
This expectation is justified because
cmake -S folder -B build-folder
cmake --build build-folder --target some_exe
will cause all of the libraries transitively depended upon by some_interface to be compiled, and the documentation for add_dependencies
says
https://cmake.org/cmake/help/latest/command/add_dependencies.html
Dependencies added to an imported target or an interface library are followed transitively in its place since the target itself does not build.
Which shows that the user expectation to get their code to build via the custom target is substantiated.
Instead, what has to be done to achieve this is the following:
add_library(some_interface INTERFACE)
set(MY_INTERFACE_LIBS some collection of real libraries)
target_link_library(some_interface INTERFACE ${MY_INTERFACE_LIBS})
add_custom_target(my_build_target)
add_dependencies(my_build_target ${MY_INTERFACE_LIBS})
add_executable(some_exe PRIVATE some_interface)