# pkg\_check\_modules() imported target does not propagate

**URL:** <https://discourse.cmake.org/t/pkg-check-modules-imported-target-does-not-propagate/12777>\
**Category:** Code\
**Created:** [October 15, 2024, 9:51am UTC](https://discourse.cmake.org/t/pkg-check-modules-imported-target-does-not-propagate/12777 "2024-10-15T09:51:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anik01ic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anik01ic/32/5018_2.png) [@anik01ic](https://discourse.cmake.org/u/anik01ic)\
**Post date:** [October 15, 2024, 9:51am UTC](https://discourse.cmake.org/t/pkg-check-modules-imported-target-does-not-propagate/12777/1 "2024-10-15T09:51:31Z")

</div>

Greetings,

I have an issue with `pkg_check_modules()` (cmake version 3.22.3) and I seem not to be able to solve it (been trying for more than a week).

I have two CMake projects, lets call them A and B.

### Project A

```auto
add_library(targetA SHARED ...)
pkg_check_modules(GST REQUIRED IMPORTED_TARGET GLOBAL gstreamer-1.0)
target_link_libraries(targetA PUBLIC PkgConfig::GST)

# here comes installing the ATargets.cmake and AConfig.cmake

```

### Project B

Project B depends on Project A by using the targetA. Basically, it does the following:

```auto
find_package(A)

```

### Issue

The issue I am having is that the generated `ATargets.cmake` file contains the following line:

```auto
set_target_properties(A::targetA PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "PkgConfig::GST"
)

```

…so when building project B, the `find_package(A)` call fails with the error message:

```auto
The link interface of target "A::targetA" contains:
|
| PkgConfig::GST
|
| but the target was not found. Possible reasons include:
|
| * There is a typo in the target name.
| * A find_package call is missing for an IMPORTED target.
| * An ALIAS target is missing.

```

According to the pkg\_check\_modules [documentation](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#command:pkg_check_modules), the call creates the `PkgConfig::GST` imported target, but I don’t quite understand what this means. Where is the target, I can’t seem to find any files being generated. I was trying to install this created `PkgConfig::GST` target, but with no luck.

Thanks for any support on this.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [October 15, 2024, 10:00am UTC](https://discourse.cmake.org/t/pkg-check-modules-imported-target-does-not-propagate/12777/2 "2024-10-15T10:00:11Z")

</div>

I’ve never used `pkg_check_modules()`, but I would assume the logic is the same, and so in your **Project B** before you do `find_package(A)` there should be that same line with finding `gstreamer-1.0` using `pkg_check_modules()`, or alternatively your `AConfig.cmake` should contain something of the sort (_with CMake packages it would be `find_dependency()`_).

---

<div class="post-metadata">

**Author:** ![anik01ic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anik01ic/32/5018_2.png) [@anik01ic](https://discourse.cmake.org/u/anik01ic)\
**Post date:** [October 16, 2024, 7:40am UTC](https://discourse.cmake.org/t/pkg-check-modules-imported-target-does-not-propagate/12777/3 "2024-10-16T07:40:33Z")

</div>

Thanks for the reply, I went into this direction and believe this is a right solution. I’ll describe it below, maybe someone wants to chime in or will find it useful.

The issue I had (`PkgConfig::GST` target is missing) was because when Project A is imported by another project, this target does not exist anymore and must be re-generated. That’s why I added the below line to the `AConfig.cmake` file (during the build):

```auto
find_package(PkgConfig)
pkg_check_modules(GST REQUIRED IMPORTED_TARGET GLOBAL gstreamer-1.0)

```

This means that every project which calls `find_package(A)` indirectly creates the `PkgConfig::GST` target, so using this target through `ATargets.cmake` won’t fail.

PS: If you have mulitple `pkg_check_modules` calls, don’t forget that the second call will invalidate the `PkgConfig::GST` target created by the first call.

Aleksandar
