# CMake ignores missing required package

**URL:** https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290
**Category:** Code
**Created:** [October 26, 2023, 9:56pm UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290 "2023-10-26T21:56:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![benschreiber](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benschreiber/32/3421_2.png) [@benschreiber](https://discourse.cmake.org/u/benschreiber)
#### Post date: [October 26, 2023, 9:56pm UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290/1 "2023-10-26T21:56:02Z")

</div>

I have a required dependency Bar. Even if Bar is not found, CMake finishes configuring without error.

CMakeLists.txt

```cmake
cmake_minimum_required(VERSION 3.27)
project(Foo)

set(CMAKE_MODULE_PATH "${Foo_SOURCE_DIR}")
find_package(Bar REQUIRED)
message(NOTICE "${Bar_FOUND}")

```

FindBar.cmake

```cmake
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
message(NOTICE "Set Bar not found")

```

CMake output:

```plaintext
$ cmake --fresh .
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Set Bar not found
FALSE
-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/foo

```

Is this expected? Is `FindPackageHandleStandardArgs` needed to check Bar\_FOUND? Does this behavior differ between Find Modules and config files?

---

<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 29, 2023, 12:29pm UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290/2 "2023-10-29T12:29:33Z")

</div>

Maybe CMake finds a different instance of `Bar`? Does configuring with the `--debug-find` provide any more information?

---

<div class="post-metadata">

### Author: ![benschreiber](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benschreiber/32/3421_2.png) [@benschreiber](https://discourse.cmake.org/u/benschreiber)
#### Post date: [October 30, 2023, 7:56pm UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290/3 "2023-10-30T19:56:19Z")

</div>

Using `--debug-find` confirms that CMake does not find the package.

```plaintext
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Set Bar not found
CMake Debug Log at CMakeLists.txt:5 (find_package):
  find_package considered the following paths for FindBar.cmake:

    /usr/local/share/cmake-3.27/Modules/FindBar.cmake

  The file was found at

    /tmp/foo/FindBar.cmake

  The module is considered not found due to Bar_FOUND being FALSE.

FALSE
-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/foo

```

Changing `Bar` to a different string throughout also does not help.

---

<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 31, 2023, 12:20am UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290/4 "2023-10-31T00:20:57Z")

</div>

This is certainly interesting. I’ll look into it…

---

<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 31, 2023, 12:32am UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290/5 "2023-10-31T00:32:03Z")

</div>

Ah. The “standard” behavior is actually implemented by a call to `find_package_handle_standard_args` (called FPHSA) for `Find` modules. I hadn’t expected that, but it seems that is how it works…
