# How to get pseudo-target information when wrapping CMake

**URL:** https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737
**Category:** Usage
**Created:** [August 22, 2020, 8:21am UTC](https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737 "2020-08-22T08:21:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lacasseio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lacasseio/32/796_2.png) [@lacasseio](https://discourse.cmake.org/u/lacasseio)
#### Post date: [August 22, 2020, 8:21am UTC](https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737/1 "2020-08-22T08:21:42Z")

</div>

The [file-api’s codemodel allows gathering information about targets but explicitly exclude INTERFACE libraries](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#codemodel-version-2):

> 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?

---

<div class="post-metadata">

### Author: ![lacasseio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lacasseio/32/796_2.png) [@lacasseio](https://discourse.cmake.org/u/lacasseio)
#### Post date: [August 22, 2020, 8:52am UTC](https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737/2 "2020-08-22T08:52:30Z")

</div>

I found this PR [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/5078/](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:

```auto
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`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 15, 2020, 2:26pm UTC](https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737/3 "2020-11-15T14:26:01Z")

</div>

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [November 16, 2020, 2:51pm UTC](https://discourse.cmake.org/t/how-to-get-pseudo-target-information-when-wrapping-cmake/1737/4 "2020-11-16T14:51:16Z")

</div>

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.
