FindOSMesa.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Try to find Mesa off-screen library and include dir.
  2. # Once done this will define
  3. #
  4. # OSMesa_FOUND - true if OSMesa has been found
  5. # OSMesa_INCLUDE_DIRS - where the GL/osmesa.h can be found
  6. # OSMesa_LIBRARIES - Link this to use OSMesa
  7. # OSMesa_VERSION - Version of OSMesa found
  8. # OSMesa::OSMesa - Imported target
  9. find_path(OSMESA_INCLUDE_DIR
  10. NAMES GL/osmesa.h
  11. PATHS "${OSMESA_ROOT}/include"
  12. "$ENV{OSMESA_ROOT}/include"
  13. /usr/openwin/share/include
  14. /opt/graphics/OpenGL/include
  15. DOC "OSMesa include directory")
  16. mark_as_advanced(OSMESA_INCLUDE_DIR)
  17. find_library(OSMESA_LIBRARY
  18. NAMES OSMesa OSMesa16 OSMesa32
  19. PATHS "${OSMESA_ROOT}/lib"
  20. "$ENV{OSMESA_ROOT}/lib"
  21. /opt/graphics/OpenGL/lib
  22. /usr/openwin/lib
  23. DOC "OSMesa library")
  24. mark_as_advanced(OSMESA_LIBRARY)
  25. if (OSMESA_INCLUDE_DIR AND EXISTS "${OSMESA_INCLUDE_DIR}/GL/osmesa.h")
  26. file(STRINGS "${OSMESA_INCLUDE_DIR}/GL/osmesa.h" _OSMesa_version_lines
  27. REGEX "OSMESA_[A-Z]+_VERSION")
  28. string(REGEX REPLACE ".*# *define +OSMESA_MAJOR_VERSION +([0-9]+).*" "\\1" _OSMesa_version_major "${_OSMesa_version_lines}")
  29. string(REGEX REPLACE ".*# *define +OSMESA_MINOR_VERSION +([0-9]+).*" "\\1" _OSMesa_version_minor "${_OSMesa_version_lines}")
  30. string(REGEX REPLACE ".*# *define +OSMESA_PATCH_VERSION +([0-9]+).*" "\\1" _OSMesa_version_patch "${_OSMesa_version_lines}")
  31. set(OSMesa_VERSION "${_OSMesa_version_major}.${_OSMesa_version_minor}.${_OSMesa_version_patch}")
  32. unset(_OSMesa_version_major)
  33. unset(_OSMesa_version_minor)
  34. unset(_OSMesa_version_patch)
  35. unset(_OSMesa_version_lines)
  36. endif ()
  37. include(FindPackageHandleStandardArgs)
  38. find_package_handle_standard_args(OSMesa
  39. REQUIRED_VARS OSMESA_INCLUDE_DIR OSMESA_LIBRARY
  40. VERSION_VAR OSMesa_VERSION)
  41. if (OSMesa_FOUND)
  42. set(OSMesa_INCLUDE_DIRS "${OSMESA_INCLUDE_DIR}")
  43. set(OSMesa_LIBRARIES "${OSMESA_LIBRARY}")
  44. if (NOT TARGET OSMesa::OSMesa)
  45. add_library(OSMesa::OSMesa UNKNOWN IMPORTED)
  46. set_target_properties(OSMesa::OSMesa PROPERTIES
  47. IMPORTED_LOCATION "${OSMESA_LIBRARY}"
  48. INTERFACE_INCLUDE_DIRECTORIES "${OSMESA_INCLUDE_DIR}")
  49. endif ()
  50. endif ()