FindPackageMessage.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #
  7. #
  8. #
  9. # FIND_PACKAGE_MESSAGE(<name> "message for user" "find result details")
  10. #
  11. # This macro is intended to be used in FindXXX.cmake modules files. It
  12. # will print a message once for each unique find result. This is useful
  13. # for telling the user where a package was found. The first argument
  14. # specifies the name (XXX) of the package. The second argument
  15. # specifies the message to display. The third argument lists details
  16. # about the find result so that if they change the message will be
  17. # displayed again. The macro also obeys the QUIET argument to the
  18. # find_package command.
  19. #
  20. # Example:
  21. #
  22. # ::
  23. #
  24. # if(X11_FOUND)
  25. # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
  26. # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
  27. # else()
  28. # ...
  29. # endif()
  30. function(FIND_PACKAGE_MESSAGE pkg msg details)
  31. # Avoid printing a message repeatedly for the same find result.
  32. if(NOT ${pkg}_FIND_QUIETLY)
  33. string(REPLACE "\n" "" details "${details}")
  34. set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
  35. if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
  36. # The message has not yet been printed.
  37. message(STATUS "${msg}")
  38. # Save the find details in the cache to avoid printing the same
  39. # message again.
  40. set("${DETAILS_VAR}" "${details}"
  41. CACHE INTERNAL "Details about finding ${pkg}")
  42. endif()
  43. endif()
  44. endfunction()