FindPackageMessage.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # FIND_PACKAGE_MESSAGE(<name> "message for user" "find result details")
  2. #
  3. # This macro is intended to be used in FindXXX.cmake modules files.
  4. # It will print a message once for each unique find result.
  5. # This is useful for telling the user where a package was found.
  6. # The first argument specifies the name (XXX) of the package.
  7. # The second argument specifies the message to display.
  8. # The third argument lists details about the find result so that
  9. # if they change the message will be displayed again.
  10. # The macro also obeys the QUIET argument to the find_package command.
  11. #
  12. # Example:
  13. #
  14. # if(X11_FOUND)
  15. # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}"
  16. # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
  17. # else()
  18. # ...
  19. # endif()
  20. #=============================================================================
  21. # Copyright 2008-2009 Kitware, Inc.
  22. #
  23. # Distributed under the OSI-approved BSD License (the "License");
  24. # see accompanying file Copyright.txt for details.
  25. #
  26. # This software is distributed WITHOUT ANY WARRANTY; without even the
  27. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28. # See the License for more information.
  29. #=============================================================================
  30. # (To distribute this file outside of CMake, substitute the full
  31. # License text for the above reference.)
  32. function(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(REGEX 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. # Save the find details in the cache to avoid printing the same
  41. # message again.
  42. set("${DETAILS_VAR}" "${details}"
  43. CACHE INTERNAL "Details about finding ${pkg}")
  44. endif()
  45. endif()
  46. endfunction()