How to get pseudo-target information when wrapping CMake

The file-api’s codemodel allows gathering information about targets but explicitly exclude INTERFACE libraries:

A JSON array of entries corresponding to the build system targets. Such targets are created by calls to add_executable(), add_library(), and add_custom_target(), excluding imported targets and interface libraries (which do not generate any build rules).

I understand the idea behind the fact that it doesn’t generate any build rules but I still need the information about the target_include_directories configuration of such target. Is there any way to get this information without resorting to parsing the CMake language?

I found this PR https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5078/ that will show INTERFACE target in the codemodel only if they have sources attach to them. Unfortunately, one sample project I’m looking at is not configured that way:

add_library(foo INTERFACE)
target_include_directories(foo
    INTERFACE
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

I cannot change the cmake file. What I’m interested in is the value for BUILD_INTERFACE, that is ${CMAKE_CURRENT_SOURCE_DIR}/include.

Cc: @brad.king

Prior to MR 5078, INTERFACE libraries were not allowed to have their own sources and never produced any rules in the generated buildsystem. Since they are not in the buildsystem, they are not reported in the file-api. MR 5078 added the ability for projects to opt-in to having INTERFACE libraries participate in the buildsystem by adding SOURCES to them. In that case such libraries are included by the file-api because they appear in the generated buildsystem.

If the project does not add SOURCES, there is no way to directly get the information you want from file-api because the interface library is not part of the buildsystem. However, some other target that is not an interface library links to foo in your example, then the INTERFACE_INCLUDE_DIRECTORIES from foo will be reported by the file-api as among the include directories for that other target.