find_package REQUIRED flag has no effect when FindXXX module is found but XXX_FOUND is returned as false
I find myself writing this like this in my CMakeLists.txt file:
find_package(Xyzzy REQUIRED)
if (NOT ${XYZZY_FOUND})
message(FATAL_ERROR "A REQUIRED package was not found")
endif()
It's confusing that this should be necessary, since I'm passing the REQUIRED flag to find_package(). I'd expect find_package() or the FindXxx module to raise the error for me.
This is the pattern I use for FindXxx modules:
include(FindPackageHandleStandardArgs)
find_path(XYZZY_INCLUDE_DIR NAMES xyzzy.h)
find_library(XYZZY_LIBRARY NAMES libxyzzy)
find_package_handle_standard_args(
XYZZY
REQUIRED_VARS XYZZY_INCLUDE_DIR XYZZY_LIBRARY)
if(XYZZY_FOUND)
add_library(Xyzzy::Xyzzy SHARED IMPORTED)
set_target_properties(Xyzzy:Xyzzy PROPERTIES
IMPORTED_LOCATION ${XYZZY_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${XYZZY_INCLUDE_DIR}
INTERFACE_LIBRARIES ${XYZZY_LIBRARY}
)
endif()