# If find\_package not support some library

**URL:** https://discourse.cmake.org/t/if-find-package-not-support-some-library/9575
**Category:** Usage
**Tags:** os:windows
**Created:** [December 7, 2023, 1:20am UTC](https://discourse.cmake.org/t/if-find-package-not-support-some-library/9575 "2023-12-07T01:20:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sea\_Sea](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sea_sea/32/4025_2.png) [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)
#### Post date: [December 7, 2023, 1:20am UTC](https://discourse.cmake.org/t/if-find-package-not-support-some-library/9575/1 "2023-12-07T01:20:22Z")

</div>

If xxlib is not the modules listed here are part of the CMake distribution.

I want to write a FindXXlib.cmake to find the library.  
For the begin, should it use `find_package` (like FindXXlib\_1.cmake)?  
Or directly use `find_library` and `find_path` (like FindXXlib\_2.cmake) ?

FindXXlib\_1.cmake

```auto
find_package(xxlib REQUIRED)

find_library(XX_LIB
    NAMES XX
)
find_path(XX_INCLUDE_DIR
    NAMES XX.h
)

```

FindXXlib\_2.cmake

```auto

find_library(XX_LIB
    NAMES XX
)
find_path(XX_INCLUDE_DIR
    NAMES XX.h
)

```

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [December 8, 2023, 10:34am UTC](https://discourse.cmake.org/t/if-find-package-not-support-some-library/9575/2 "2023-12-08T10:34:35Z")

</div>

First off, the preferred approach would be for xxlib to provide an `xxlibConfig.cmake` file as part of its distribution or installation, as package config files are preferred to find modules. If you can add it to the library or convince its maintainers to add it, that is the best route to take.

Only if that is not an option does it make sense to create a find module. If you find you need to go the find module route, it means xxlib doesn’t provide a package config file, so in that case there is nothing for `find_package(xxlib)` to find (that command looks for find modules and package config files only). A find module for xxlib effectively defines the package xxlib for CMake, so it makes no sense for it to `find_package(xxlib)`
