# find\_package\_handle\_standard\_args terminates though not REQUIRED

**URL:** https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382
**Category:** Usage
**Created:** [December 13, 2019, 6:25pm UTC](https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382 "2019-12-13T18:25:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [December 13, 2019, 6:25pm UTC](https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382/1 "2019-12-13T18:25:06Z")

</div>

Searching for library “Cerf”

```
# FindCerf.cmake:
...
find_path(Cerf_INCLUDE_DIR cerf.h)
find_library(Cerf_LIBRARIES NAMES cerf)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Cerf DEFAULT_MSG Cerf_LIBRARIES Cerf_INCLUDE_DIR)

```

terminates with error

```
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find Cerf (missing: Cerf_LIBRARIES)Call Stack (most recent call first): 
    C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
    cmake/FindCerf.cmake:19 (find_package_handle_standard_args)
    CMakeLists.txt:83 (find_package)

```

though I did not say `REQUIRED`. Why?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [December 14, 2019, 5:15pm UTC](https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382/2 "2019-12-14T17:15:42Z")

</div>

Unless I’m not looking at the right `CMakeLists.txt` file, there is the following written on [`CMakeLists.txt:83`](https://gitlab-public.fz-juelich.de/mlz/steca/blob/4433791912656e85566afd5a5b4217277f44697a/CMakeLists.txt#L83):

```auto
find_package(Cerf MODULE REQUIRED)

```

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [December 14, 2019, 5:24pm UTC](https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382/3 "2019-12-14T17:24:21Z")

</div>

Incredible - what a phantastic debugging help - you found indeed the pertinent calling `CMakeLists.txt` - thank you so much, Alain!

By what mechanism is the `REQUIRED` flag transmitted to the `find_package_handle_standard_args` function without explicitly appearing in the argument list?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [December 14, 2019, 5:35pm UTC](https://discourse.cmake.org/t/find-package-handle-standard-args-terminates-though-not-required/382/4 "2019-12-14T17:35:48Z")

</div>

When calling `find_package(Cerf MODULE REQUIRED)`, CMake defines several variables (the complete list is here: [https://cmake.org/cmake/help/latest/command/find\_package.html#package-file-interface-variables](https://cmake.org/cmake/help/latest/command/find_package.html#package-file-interface-variables)), including `Cerf_FIND_REQUIRED`.

Then `find_package_handle_standard_args` uses whether `<PackageName>_FIND_REQUIRED` is true to decide whether it should use `message(FATAL_ERROR)`, `message(STATUS)` or do nothing when the package is not found. See [https://gitlab.kitware.com/cmake/cmake/blob/v3.16.0/Modules/FindPackageHandleStandardArgs.cmake#L145-150](https://gitlab.kitware.com/cmake/cmake/blob/v3.16.0/Modules/FindPackageHandleStandardArgs.cmake#L145-150) for the actual code.
