1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindPackageMessage
6------------------
7
8.. code-block:: cmake
9
10  find_package_message(<name> "message for user" "find result details")
11
12This function is intended to be used in FindXXX.cmake modules files.
13It will print a message once for each unique find result.  This is
14useful for telling the user where a package was found.  The first
15argument specifies the name (XXX) of the package.  The second argument
16specifies the message to display.  The third argument lists details
17about the find result so that if they change the message will be
18displayed again.  The macro also obeys the QUIET argument to the
19find_package command.
20
21Example:
22
23.. code-block:: cmake
24
25  if(X11_FOUND)
26    find_package_message(X11 "Found X11: ${X11_X11_LIB}"
27      "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
28  else()
29   ...
30  endif()
31#]=======================================================================]
32
33function(find_package_message pkg msg details)
34  # Avoid printing a message repeatedly for the same find result.
35  if(NOT ${pkg}_FIND_QUIETLY)
36    string(REPLACE "\n" "" details "${details}")
37    set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
38    if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
39      # The message has not yet been printed.
40      message(STATUS "${msg}")
41
42      # Save the find details in the cache to avoid printing the same
43      # message again.
44      set("${DETAILS_VAR}" "${details}"
45        CACHE INTERNAL "Details about finding ${pkg}")
46    endif()
47  endif()
48endfunction()
49