# With modern cmake, does transtive dependency needs \`find\_package\`?

**URL:** https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073
**Category:** Usage
**Created:** [September 12, 2021, 9:50am UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073 "2021-09-12T09:50:16Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 12, 2021, 9:50am UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/1 "2021-09-12T09:50:16Z")

</div>

A

```cmake
find_package(CURL REQUIRED)
target_link_libraries(A PUBLIC CURL::libcurl)

```

B

```cmake
target_link_libraries(B PRIVATE A)

```

When configure for B

```auto
CMake Error at CMakeLists.txt:53 (add_executable):
  Target "B" links to target "CURL::libcurl" but the target was not
  found. Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

```

Does B have to `find_package(CURL REQUIRED)`?

BTW, if not using modern cmake, i.e. using `CURL_INCLUDE_DIRS` and `CURL_LIBRARIES`, no such a problem.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 12, 2021, 1:54pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/2 "2021-09-12T13:54:40Z")

</div>

It depends on where `find_package(CURL ...)` is called. The imported target created is not global, so only visible in the directory, and any sub-directories, where `find_package(...)` call occurred.

To solve your problem, a new call to `find_package(CURL ...)` can be done.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 12, 2021, 2:04pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/3 "2021-09-12T14:04:15Z")

</div>

> [@marc.chevrier](#):
>
> To solve your problem, a new call to `find_package(CURL ...)` can be done.

In traditional way, i.e. `CURL_INCLUDE_DIRS` and `CURL_LIBRARIES`, a new call to `find_package(CURL ...)` is not necesary, it is expected, isn’t it?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 12, 2021, 2:10pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/4 "2021-09-12T14:10:41Z")

</div>

It depends on the module you are using. In your case, it works because `CURL_INCLUDE_DIRS` and `CURL_LIBRARIES` are defined as cache variables (so with a global visibility), but it is perfectly valid that result variables are defined as standard variables. In this case, you have the same problem as the imported target.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 12, 2021, 2:20pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/5 "2021-09-12T14:20:42Z")

</div>

It’s about properties of `INTERFACE_INCLUDE_DIRECTORIES` and `INTERFACE_LINK_LIBRARIES`.

`CURL::libcurl` literally in `INTERFACE_LINK_LIBRARIES` needs extra `find_package(CURL ...)` for it to make sense.

`CURL_INCLUDE_DIRS` and `CURL_LIBRARIES` in `INTERFACE_LINK_LIBRARIES` have concrete paths and names, so no extra `find_package(CURL ...)` is needed.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 12, 2021, 2:23pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/6 "2021-09-12T14:23:44Z")

</div>

No, it is not a problem with properties, but with artifact visibility : the imported target is not **global** so does not exist everywhere as clearly described in the error message!

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 12, 2021, 2:37pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/7 "2021-09-12T14:37:30Z")

</div>

OK, it’s about both.

For `CURL_INCLUDE_DIRS` and `CURL_LIBRARIES`, when the values are assigned to `INTERFACE_INCLUDE_DIRECTORIES` and `INTERFACE_LINK_LIBRARIES`,  
`CURL_INCLUDE_DIRS` and `CURL_LIBRARIES` are not needs anymore.

But for `CURL::libcurl` as a target, it should be visible when referenced.

---

<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: [September 14, 2021, 2:05pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/8 "2021-09-14T14:05:07Z")

</div>

The imported target doesn’t need to be global (I haven’t needed to make any imported target global in my usage). It comes from `A`'s usage requirements, so `A`'s scope is used to look up the imported target.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 15, 2021, 4:33am UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/9 "2021-09-15T04:33:35Z")

</div>

> [@ben.boeckel](#):
>
> `A`’s scope is used to look up the imported target.

Is there any way for the result of `find_package(CURL REQUIRED)` in `A`’s scope so that no need for `find_package(CURL REQUIRED)` in B’s `CMakeLists`?

---

<div class="post-metadata">

### Author: ![bbrown105](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bbrown105/32/1737_2.png) [@bbrown105](https://discourse.cmake.org/u/bbrown105)
#### Post date: [September 16, 2021, 7:52pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/10 "2021-09-16T19:52:27Z")

</div>

I do basically the opposite and make every imported target global. I don’t have the need for directory-specific dependencies, `-l` flags already have global name semantics, and it’s just less confusing that way.

I’d set a `CMAKE_ALL_IMPORTS_ARE_GLOBAL=1` flag if I could.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 16, 2021, 9:36pm UTC](https://discourse.cmake.org/t/with-modern-cmake-does-transtive-dependency-needs-find-package/4073/11 "2021-09-16T21:36:46Z")

</div>

Have a look at [IMPORTED\_GLOBAL](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_GLOBAL.html) property.
