# abuse / misuse of find\_package?

**URL:** https://discourse.cmake.org/t/abuse-misuse-of-find-package/1887
**Category:** Usage
**Created:** [September 22, 2020, 3:55pm UTC](https://discourse.cmake.org/t/abuse-misuse-of-find-package/1887 "2020-09-22T15:55:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [September 22, 2020, 3:55pm UTC](https://discourse.cmake.org/t/abuse-misuse-of-find-package/1887/1 "2020-09-22T15:55:57Z")

</div>

I am reviewing at my work some code that a developer submitted and a big red flag went up for me. I wanted to make sure I’m not the one misunderstanding find\_package before I really dig in with my objections to some changes. I want to be sure our project uses CMake in an idiomatic way as much as possible.

In essence this person is using CMake and find\_package in the following way. Executable target A has in its CMakeLists.txt a call to find\_package(B). Dependency B has a B.cmake file located in some folder that was added to the project via CMAKE\_MODULE\_PATH. B.cmake internally does an add\_subdirectory(B). In B’s subdirectory it has a regular CMakeLists.txt which builds itself.

My understanding of idiomatic usage of find\_package is stuff like this:

find\_package(Qt5 COMPONENTS Core QuickCompiler REQUIRED)  
or  
find\_package(Boost)

neither of the above two lines would attempt to _build_ Qt or Boost. Maybe this whole question is stupid, but my understanding of find\_package is that it tries to _find_, not _build_.

Am I right to object to the proposed usage?

---

<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 22, 2020, 4:02pm UTC](https://discourse.cmake.org/t/abuse-misuse-of-find-package/1887/2 "2020-09-22T16:02:55Z")

</div>

Yes, you are right.

To achieve what you describe, you have to manage a `super-build` using [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) or [ExternalProject](https://cmake.org/cmake/help/latest/module/ExternalProject.html).

Or more simply, include directly `add_subdirectory(B)` in your `CMake` project.

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [September 22, 2020, 4:19pm UTC](https://discourse.cmake.org/t/abuse-misuse-of-find-package/1887/3 "2020-09-22T16:19:42Z")

</div>

Ultimately I think it might be a good idea to use a package manager like Conan or vcpkg to create recipes for building dependencies and the projects that depend on them reliably. We’re on windows, so those seem like to the two most commonly used options. Before the proposed changes, we were simply doing  
add\_subdirectory(B)  
but there is a desire to make things more granular so B should probably be built separately.
