Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / FindPackageMessage.cmake
blob7efbe18d24142fb8567bf52df8f46a728b39143f
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindPackageMessage
6 ------------------
8 .. code-block:: cmake
10   find_package_message(<name> "message for user" "find result details")
12 This function is intended to be used in FindXXX.cmake modules files.
13 It will print a message once for each unique find result.  This is
14 useful for telling the user where a package was found.  The first
15 argument specifies the name (XXX) of the package.  The second argument
16 specifies the message to display.  The third argument lists details
17 about the find result so that if they change the message will be
18 displayed again.  The macro also obeys the QUIET argument to the
19 find_package command.
21 Example:
23 .. code-block:: cmake
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 #]=======================================================================]
33 function(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       string(STRIP "${msg}" msg)
41       message(STATUS "${msg}")
43       # Save the find details in the cache to avoid printing the same
44       # message again.
45       set("${DETAILS_VAR}" "${details}"
46         CACHE INTERNAL "Details about finding ${pkg}")
47     endif()
48   endif()
49 endfunction()