xref: /aosp_15_r20/external/pytorch/cmake/Modules_CUDA_fix/upstream/FindPackageMessage.cmake (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
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:
5# FindPackageMessage
6# ------------------
7#
8#
9#
10# FIND_PACKAGE_MESSAGE(<name> "message for user" "find result details")
11#
12# This macro is intended to be used in FindXXX.cmake modules files.  It
13# will print a message once for each unique find result.  This is useful
14# for telling the user where a package was found.  The first argument
15# 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.
20#
21# Example:
22#
23# ::
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
32function(FIND_PACKAGE_MESSAGE pkg msg details)
33  # Avoid printing a message repeatedly for the same find result.
34  if(NOT ${pkg}_FIND_QUIETLY)
35    string(REPLACE "\n" "" details "${details}")
36    set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
37    if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
38      # The message has not yet been printed.
39      message(STATUS "${msg}")
40
41      # Save the find details in the cache to avoid printing the same
42      # message again.
43      set("${DETAILS_VAR}" "${details}"
44        CACHE INTERNAL "Details about finding ${pkg}")
45    endif()
46  endif()
47endfunction()
48