# forcing find\_package to search only for the exact same build type than the calling target

**URL:** https://discourse.cmake.org/t/forcing-find-package-to-search-only-for-the-exact-same-build-type-than-the-calling-target/9177
**Category:** Usage
**Created:** [October 11, 2023, 2:03pm UTC](https://discourse.cmake.org/t/forcing-find-package-to-search-only-for-the-exact-same-build-type-than-the-calling-target/9177 "2023-10-11T14:03:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [October 11, 2023, 2:03pm UTC](https://discourse.cmake.org/t/forcing-find-package-to-search-only-for-the-exact-same-build-type-than-the-calling-target/9177/1 "2023-10-11T14:03:28Z")

</div>

Hi, I build targets with different possible build types:

- Debug (with my own flags)
- Release (with my own flags)
- Custom, with a given name

I observed the following behavior, which, as far as I understand, is the default CMake one.

Let say I have a target A which is a static library and a target B that is an application, linking A.  
  
If I build and install A in Debug with a proper configuration file, I get a ATargets-debug.cmake file, that references /Debug/libA.a.  
  
Now I build B in Release, using find\_package(A) in my CMakeLists.txt.  
  
B, compiled in Release, gets linked with A compiled in Debug, which I’d like not to.

Actually I stumbled on that from an error I got when I had deleted /Debug/libA.a but forgot to delete also ATargets-debug.cmake. Even if /Release/libA.a exists, I cannot configure for B anymore as the find\_package is looking for /Release/libA.a AND /Debug/libA.a.

Thus my question is: is there a way, when using find\_package to look only for the exact same build type? (based solely on its name, for simplification)?

(NB I exhumed an old question slightly related to the subject: [find\_package and build configuration](https://discourse.cmake.org/t/find-package-and-build-configuration/4530)).

Regards,  
A.

---

<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: [October 11, 2023, 4:15pm UTC](https://discourse.cmake.org/t/forcing-find-package-to-search-only-for-the-exact-same-build-type-than-the-calling-target/9177/2 "2023-10-11T16:15:24Z")

</div>

[`MAP_IMPORTED_CONFIG_CONFIG`](https://cmake.org/cmake/help/latest/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.html) might be able to help? I’m not sure if there’s a way here though off hand.
