FindPackageMessage.cmake 1.7 KB

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