# What is the proper way of using IMPORTED\_TARGET

**URL:** https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156
**Category:** Usage
**Created:** [May 6, 2020, 6:34pm UTC](https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156 "2020-05-06T18:34:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)
#### Post date: [May 6, 2020, 6:34pm UTC](https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156/1 "2020-05-06T18:34:20Z")

</div>

Following up on the [What is the proper way to use FindPkgConfig](https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-pkg-config-from-cmake)  
and [FindPkgConfig](https://cmake.org/cmake/help/v3.17/module/FindPkgConfig.html?highlight=pkg_search_module#command:pkg_search_module)[https://cmake.org/cmake/help/v3.17/module/FindPkgConfig.html?highlight=pkg\_search\_module#command:pkg\_search\_module](https://cmake.org/cmake/help/v3.17/module/FindPkgConfig.html?highlight=pkg_search_module#command:pkg_search_module)  
Could you please advise what is the use case for IMPORTED\_TARGET.  
The prefix (e,g, SDL2) variable (eg. SDL2\_LIBRARIES ) is accepted by the target\_link\_libraries so what functionality is added by IMPORTED\_TARGET named `PkgConfig::<prefix>` ( e.g. PkgConfig::SDL2, see snippet below) ?  
IMPORTED targets are not allowed to be installed and I doubt this could be circumvented by somehow exporting \_LIBRARIES, right?

include(FindPkgConfig)  
pkg\_search\_module(SDL2 REQUIRED sdl2)  
target\_include\_directories(app SYSTEM PUBLIC ${SDL2\_INCLUDE\_DIRS}  
target\_link\_libraries(app ${SDL2\_LIBRARIES})  
is there a case when both \_XXXX and PkgConfig:: are used?

---

<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: [May 7, 2020, 3:21pm UTC](https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156/2 "2020-05-07T15:21:07Z")

</div>

Why not just link to `Pkgconfig::SDL2` here? I recommend ignoring the variables when an imported target exists; modern CMake is more geared towards making these targets the main way of doing things.

---

<div class="post-metadata">

### Author: ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)
#### Post date: [May 10, 2020, 1:06am UTC](https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156/3 "2020-05-10T01:06:30Z")

</div>

Does this mean use of IMPORTED\_TARGET reflects pre-modern cmake and is no longer recommended and there no any scenarios with modern cmake where it could be useful?  
Also PkgConfig::SDL2 is a target, not just variable, right? So can this target be an target argument in install(TARGETS PkgConfig::SDL2 ?

---

<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: [May 10, 2020, 2:10pm UTC](https://discourse.cmake.org/t/what-is-the-proper-way-of-using-imported-target/1156/4 "2020-05-10T14:10:57Z")

</div>

> [@yisseamake](#):
>
> Does this mean use of IMPORTED\_TARGET reflects pre-modern cmake and is no longer recommended

No? Use the target. Ignore the variables (`_INCLUDE_DIRS` and `_LIBRARIES`).

> [@yisseamake](#):
>
> Also PkgConfig::SDL2 is a target, not just variable, right?

It is a target, not a variable.

> [@yisseamake](#):
>
> So can this target be an target argument in install(TARGETS PkgConfig::SDL2 ?

No, as I said in the other thread, you cannot install imported targets.
