FindXXX semantic: _FIND_REQUIRED and _FIND_QUIETLY

.

Sometimes I face the following semantics in the findXXX modules. And to be honestly not quite understand what happens here:

include(FindPackageHandleStandardArgs)

set(_pkg ${CMAKE_FIND_PACKAGE_NAME)

if(${_pkg}_FIND_REQUIRED AND NOT ${_pkg}_FIND_QUIETLY)

  find_package_handle_standard_args(
    ${CMAKE_FIND_PACKAGE_NAME}
    REQUIRED_VARS
      SPDLOG_INCLUDE_DIR
      SPDLOG_LIBRARY)

else()

  find_package_handle_standard_args(
    ${CMAKE_FIND_PACKAGE_NAME} 
    DEFAULT_MSG
    SPDLOG_INCLUDE_DIR
    SPDLOG_LIBRARY)

endif()

When the ${CMAKE_FIND_PACKAGE_NAME)_FIND_QUIETLY variable will be set to TRUE ? Should I use such approach in my own modules? The two branches look pretty similar, isn’t. Is this a generally valid example? When and in what situations is this approach justified?

I have not seen mention of such a tricks ( if(XXX_FIND_REQUIRED AND NOT XXX_FIND_QUIETLY)) in the documentation. That’s why it became interesting to me what kind of use cases needs such checks.

Thank you

This seems like a very odd pattern. I think I’ve always just seen a straight call to FPHSA (which handles QUIETLY properly already).

1 Like