FindOpenEXR.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # - Find OpenEXR library
  2. # Find the native OpenEXR includes and library
  3. # This module defines
  4. # OPENEXR_INCLUDE_DIRS, where to find ImfXdr.h, etc. Set when
  5. # OPENEXR_INCLUDE_DIR is found.
  6. # OPENEXR_LIBRARIES, libraries to link against to use OpenEXR.
  7. # OPENEXR_ROOT_DIR, The base directory to search for OpenEXR.
  8. # This can also be an environment variable.
  9. # OPENEXR_FOUND, If false, do not try to use OpenEXR.
  10. #
  11. # For individual library access these advanced settings are available
  12. # OPENEXR_HALF_LIBRARY, Path to Half library
  13. # OPENEXR_IEX_LIBRARY, Path to Half library
  14. # OPENEXR_ILMIMF_LIBRARY, Path to Ilmimf library
  15. # OPENEXR_ILMTHREAD_LIBRARY, Path to IlmThread library
  16. # OPENEXR_IMATH_LIBRARY, Path to Imath library
  17. #
  18. # also defined, but not for general use are
  19. # OPENEXR_LIBRARY, where to find the OpenEXR library.
  20. #=============================================================================
  21. # Copyright 2011 Blender Foundation.
  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. # If OPENEXR_ROOT_DIR was defined in the environment, use it.
  31. IF(NOT OPENEXR_ROOT_DIR AND NOT $ENV{OPENEXR_ROOT_DIR} STREQUAL "")
  32. SET(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR})
  33. ENDIF()
  34. # Old versions (before 2.0?) do not have any version string, just assuming this should be fine though.
  35. SET(_openexr_libs_ver_init "2.0")
  36. SET(_openexr_FIND_COMPONENTS
  37. Half
  38. Iex
  39. IlmImf
  40. IlmThread
  41. Imath
  42. )
  43. SET(_openexr_SEARCH_DIRS
  44. ${OPENEXR_ROOT_DIR}
  45. /usr/local
  46. /sw # Fink
  47. /opt/local # DarwinPorts
  48. /opt/csw # Blastwave
  49. /opt/lib/openexr
  50. )
  51. FIND_PATH(OPENEXR_INCLUDE_DIR
  52. NAMES
  53. OpenEXR/ImfXdr.h
  54. HINTS
  55. ${_openexr_SEARCH_DIRS}
  56. PATH_SUFFIXES
  57. include
  58. )
  59. # If the headers were found, get the version from config file, if not already set.
  60. IF(OPENEXR_INCLUDE_DIR)
  61. IF(NOT OPENEXR_VERSION)
  62. FIND_FILE(_openexr_CONFIG
  63. NAMES
  64. OpenEXRConfig.h
  65. PATHS
  66. "${OPENEXR_INCLUDE_DIR}"
  67. "${OPENEXR_INCLUDE_DIR}/OpenEXR"
  68. NO_DEFAULT_PATH
  69. )
  70. IF(_openexr_CONFIG)
  71. FILE(STRINGS "${_openexr_CONFIG}" OPENEXR_BUILD_SPECIFICATION
  72. REGEX "^[ \t]*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
  73. ELSE()
  74. MESSAGE(WARNING "Could not find \"OpenEXRConfig.h\" in \"${OPENEXR_INCLUDE_DIR}\"")
  75. ENDIF()
  76. IF(OPENEXR_BUILD_SPECIFICATION)
  77. MESSAGE(STATUS "${OPENEXR_BUILD_SPECIFICATION}")
  78. STRING(REGEX REPLACE ".*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
  79. "\\1" _openexr_libs_ver_init ${OPENEXR_BUILD_SPECIFICATION})
  80. ELSE()
  81. MESSAGE(WARNING "Could not determine ILMBase library version, assuming ${_openexr_libs_ver_init}.")
  82. ENDIF()
  83. UNSET(_openexr_CONFIG CACHE)
  84. ENDIF()
  85. ENDIF()
  86. SET("OPENEXR_VERSION" ${_openexr_libs_ver_init} CACHE STRING "Version of OpenEXR lib")
  87. UNSET(_openexr_libs_ver_init)
  88. STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION})
  89. SET(_openexr_LIBRARIES)
  90. FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
  91. STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
  92. FIND_LIBRARY(OPENEXR_${UPPERCOMPONENT}_LIBRARY
  93. NAMES
  94. ${COMPONENT}-${_openexr_libs_ver} ${COMPONENT}
  95. HINTS
  96. ${_openexr_SEARCH_DIRS}
  97. PATH_SUFFIXES
  98. lib64 lib
  99. )
  100. LIST(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}")
  101. ENDFOREACH()
  102. UNSET(_openexr_libs_ver)
  103. # handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if
  104. # all listed variables are TRUE
  105. INCLUDE(FindPackageHandleStandardArgs)
  106. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR DEFAULT_MSG
  107. _openexr_LIBRARIES OPENEXR_INCLUDE_DIR)
  108. IF(OPENEXR_FOUND)
  109. SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
  110. # Both include paths are needed because of dummy OSL headers mixing #include <OpenEXR/foo.h> and #include <foo.h> :(
  111. SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR_INCLUDE_DIR}/OpenEXR)
  112. ENDIF()
  113. MARK_AS_ADVANCED(
  114. OPENEXR_INCLUDE_DIR
  115. OPENEXR_VERSION
  116. )
  117. FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
  118. STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
  119. MARK_AS_ADVANCED(OPENEXR_${UPPERCOMPONENT}_LIBRARY)
  120. ENDFOREACH()
  121. UNSET(COMPONENT)
  122. UNSET(UPPERCOMPONENT)
  123. UNSET(_openexr_FIND_COMPONENTS)
  124. UNSET(_openexr_LIBRARIES)
  125. UNSET(_openexr_SEARCH_DIRS)