find_package(Foo MODULE REQUIRED) doesn't fail if Foo_FOUND is set to FALSE inside the module file
Sample project:
cmake_minimum_required(VERSION 3.16.0)
project(required_find_module LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}")
set(find_module "${CMAKE_CURRENT_BINARY_DIR}/FindFoo.cmake")
file(WRITE "${find_module}" "set(Foo_FOUND FALSE)")
find_package(Foo MODULE REQUIRED)
message(STATUS "Foo found ${Foo_FOUND}")
set(config_file "${CMAKE_CURRENT_BINARY_DIR}/BarConfig.cmake")
file(WRITE "${config_file}" "set(Bar_FOUND FALSE)")
find_package(Bar CONFIG REQUIRED)
message(STATUS "Bar found ${Bar_FOUND}")
Configure output:
-- Foo found FALSE
CMake Error at CMakeLists.txt:17 (find_package):
Found package configuration file:
/Volumes/T3/Dev/projects/cmake/general/find_paackage_required/build/BarConfig.cmake
but it set Bar_FOUND to FALSE so package "Bar" is considered to be NOT
FOUND.
-- Configuring incomplete, errors occurred!
Is it intended behaviour that in the module case, configuration doesn't fail automagically? Because the way the docs are worded, I'd expect it to fail.
Under the Module Mode signature -> https://cmake.org/cmake/help/latest/command/find_package.html#id2
The REQUIRED option stops processing with an error message if the package cannot be found.