# include vs find\_package rules of thumb

**URL:** https://discourse.cmake.org/t/include-vs-find-package-rules-of-thumb/6713
**Category:** Usage
**Created:** [October 24, 2022, 9:20pm UTC](https://discourse.cmake.org/t/include-vs-find-package-rules-of-thumb/6713 "2022-10-24T21:20:08Z")
**Posts on this page:** 2
**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: [October 24, 2022, 9:20pm UTC](https://discourse.cmake.org/t/include-vs-find-package-rules-of-thumb/6713/1 "2022-10-24T21:20:08Z")

</div>

Looking for what other people use as rules of thumb for using include() vs find\_package().

I was reviewing a PR and a coworker wanted to use `find_package()` to pull in a CMake module that defined some helpful functions. The rationale was that to use `include()` would be tricky because most likely the module would be pulled in not only by the project but also by the project’s dependencies. In this example all projects are our own.

My objection was that `find_package()`, in module mode, brings in a FindXYZ.cmake file not just to define functions but to find something other than itself - i.e. an executable or library. A CMake module that exists to define functions is also a module, but if it’s not there to find something external to itself it IMO doesn’t meet the criteria for being brought in with a `find_package()` call.

It seems like `include(repeatedly_used_module)` would make more sense if we just added `include_guard(GLOBAL)` to the module itself. Is this the right way to think about this? Is using `include_guard` a code smell in any way?

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [October 25, 2022, 12:45am UTC](https://discourse.cmake.org/t/include-vs-find-package-rules-of-thumb/6713/2 "2022-10-25T00:45:00Z")

</div>

You are 100% right. Just put an include guard in the module and use `include()`.

find\_package is usually used to import targets. You could have a package of all cmake modules, but that would still imply a _separate_ package/distribution, not simply a module distributed as part of your source tree.
