OpenCVFindOpenEXR.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # The script is taken from http://code.google.com/p/nvidia-texture-tools/
  2. #
  3. # Try to find OpenEXR's libraries, and include path.
  4. # Once done this will define:
  5. #
  6. # OPENEXR_FOUND = OpenEXR found.
  7. # OPENEXR_INCLUDE_PATHS = OpenEXR include directories.
  8. # OPENEXR_LIBRARIES = libraries that are needed to use OpenEXR.
  9. #
  10. if(NOT OPENCV_SKIP_OPENEXR_FIND_PACKAGE)
  11. find_package(OpenEXR 3 QUIET)
  12. #ocv_cmake_dump_vars(EXR)
  13. if(OpenEXR_FOUND)
  14. if(TARGET OpenEXR::OpenEXR) # OpenEXR 3+
  15. set(OPENEXR_LIBRARIES OpenEXR::OpenEXR)
  16. set(OPENEXR_INCLUDE_PATHS "")
  17. set(OPENEXR_VERSION "${OpenEXR_VERSION}")
  18. set(OPENEXR_FOUND 1)
  19. return()
  20. else()
  21. message(STATUS "Unsupported find_package(OpenEXR) - missing OpenEXR::OpenEXR target (version ${OpenEXR_VERSION})")
  22. endif()
  23. endif()
  24. endif()
  25. SET(OPENEXR_LIBRARIES "")
  26. SET(OPENEXR_LIBSEARCH_SUFFIXES "")
  27. file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH)
  28. if(WIN32)
  29. SET(OPENEXR_ROOT "C:/Deploy" CACHE STRING "Path to the OpenEXR \"Deploy\" folder")
  30. if(X86_64)
  31. SET(OPENEXR_LIBSEARCH_SUFFIXES x64/Release x64 x64/Debug)
  32. elseif(MSVC)
  33. SET(OPENEXR_LIBSEARCH_SUFFIXES Win32/Release Win32 Win32/Debug)
  34. endif()
  35. elseif(UNIX)
  36. SET(OPENEXR_LIBSEARCH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE})
  37. endif()
  38. SET(SEARCH_PATHS
  39. "${OPENEXR_ROOT}"
  40. /usr
  41. /usr/local
  42. /sw
  43. /opt
  44. "${ProgramFiles_ENV_PATH}/OpenEXR")
  45. MACRO(FIND_OPENEXR_LIBRARY LIBRARY_NAME LIBRARY_SUFFIX)
  46. string(TOUPPER "${LIBRARY_NAME}" LIBRARY_NAME_UPPER)
  47. FIND_LIBRARY(OPENEXR_${LIBRARY_NAME_UPPER}_LIBRARY
  48. NAMES ${LIBRARY_NAME}${LIBRARY_SUFFIX}
  49. PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES}
  50. NO_DEFAULT_PATH
  51. PATHS "${SEARCH_PATH}/lib" "${SEARCH_PATH}/lib/static")
  52. ENDMACRO()
  53. MACRO(ocv_find_openexr LIBRARY_SUFFIX)
  54. IF(NOT OPENEXR_FOUND)
  55. FIND_OPENEXR_LIBRARY("Half" "${LIBRARY_SUFFIX}")
  56. FIND_OPENEXR_LIBRARY("Iex" "${LIBRARY_SUFFIX}")
  57. FIND_OPENEXR_LIBRARY("Imath" "${LIBRARY_SUFFIX}")
  58. FIND_OPENEXR_LIBRARY("IlmImf" "${LIBRARY_SUFFIX}")
  59. FIND_OPENEXR_LIBRARY("IlmThread" "${LIBRARY_SUFFIX}")
  60. IF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY AND OPENEXR_ILMTHREAD_LIBRARY)
  61. SET(OPENEXR_FOUND TRUE)
  62. ELSE()
  63. UNSET(OPENEXR_IMATH_LIBRARY)
  64. UNSET(OPENEXR_ILMIMF_LIBRARY)
  65. UNSET(OPENEXR_IEX_LIBRARY)
  66. UNSET(OPENEXR_ILMTHREAD_LIBRARY)
  67. UNSET(OPENEXR_HALF_LIBRARY)
  68. ENDIF()
  69. ENDIF()
  70. ENDMACRO()
  71. FOREACH(SEARCH_PATH ${SEARCH_PATHS})
  72. FIND_PATH(OPENEXR_INCLUDE_PATH ImfRgbaFile.h
  73. PATH_SUFFIXES OpenEXR
  74. NO_DEFAULT_PATH
  75. PATHS
  76. "${SEARCH_PATH}/include")
  77. IF (OPENEXR_INCLUDE_PATH)
  78. SET(OPENEXR_VERSION_FILE "${OPENEXR_INCLUDE_PATH}/OpenEXRConfig.h")
  79. IF (EXISTS ${OPENEXR_VERSION_FILE})
  80. FILE (STRINGS ${OPENEXR_VERSION_FILE} contents REGEX "#define OPENEXR_VERSION_MAJOR ")
  81. IF (${contents} MATCHES "#define OPENEXR_VERSION_MAJOR ([0-9]+)")
  82. SET(OPENEXR_VERSION_MAJOR "${CMAKE_MATCH_1}")
  83. ENDIF ()
  84. FILE (STRINGS ${OPENEXR_VERSION_FILE} contents REGEX "#define OPENEXR_VERSION_MINOR ")
  85. IF (${contents} MATCHES "#define OPENEXR_VERSION_MINOR ([0-9]+)")
  86. SET(OPENEXR_VERSION_MINOR "${CMAKE_MATCH_1}")
  87. ENDIF ()
  88. ENDIF ()
  89. ENDIF ()
  90. IF (OPENEXR_VERSION_MAJOR AND OPENEXR_VERSION_MINOR)
  91. set(OPENEXR_VERSION "${OPENEXR_VERSION_MAJOR}_${OPENEXR_VERSION_MINOR}")
  92. ENDIF ()
  93. ocv_find_openexr("-${OPENEXR_VERSION}")
  94. ocv_find_openexr("-${OPENEXR_VERSION}_s")
  95. ocv_find_openexr("-${OPENEXR_VERSION}_d")
  96. ocv_find_openexr("-${OPENEXR_VERSION}_s_d")
  97. ocv_find_openexr("")
  98. ocv_find_openexr("_s")
  99. ocv_find_openexr("_d")
  100. ocv_find_openexr("_s_d")
  101. IF (OPENEXR_FOUND)
  102. BREAK()
  103. ENDIF()
  104. UNSET(OPENEXR_INCLUDE_PATH)
  105. UNSET(OPENEXR_VERSION_FILE)
  106. UNSET(OPENEXR_VERSION_MAJOR)
  107. UNSET(OPENEXR_VERSION_MINOR)
  108. UNSET(OPENEXR_VERSION)
  109. ENDFOREACH()
  110. IF (OPENEXR_FOUND)
  111. SET(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATH} CACHE PATH "The include paths needed to use OpenEXR")
  112. SET(OPENEXR_LIBRARIES ${OPENEXR_IMATH_LIBRARY} ${OPENEXR_ILMIMF_LIBRARY} ${OPENEXR_IEX_LIBRARY} ${OPENEXR_HALF_LIBRARY} ${OPENEXR_ILMTHREAD_LIBRARY} CACHE STRING "The libraries needed to use OpenEXR" FORCE)
  113. ENDIF ()
  114. IF(OPENEXR_FOUND)
  115. IF(NOT OPENEXR_FIND_QUIETLY)
  116. MESSAGE(STATUS "Found OpenEXR: ${OPENEXR_ILMIMF_LIBRARY}")
  117. ENDIF()
  118. if(PKG_CONFIG_FOUND AND NOT OPENEXR_VERSION)
  119. get_filename_component(OPENEXR_LIB_PATH "${OPENEXR_ILMIMF_LIBRARY}" PATH)
  120. if(EXISTS "${OPENEXR_LIB_PATH}/pkgconfig/OpenEXR.pc")
  121. execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --modversion "${OPENEXR_LIB_PATH}/pkgconfig/OpenEXR.pc"
  122. RESULT_VARIABLE PKG_CONFIG_PROCESS
  123. OUTPUT_VARIABLE OPENEXR_VERSION
  124. OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  125. if(NOT PKG_CONFIG_PROCESS EQUAL 0)
  126. SET(OPENEXR_VERSION "Unknown")
  127. endif()
  128. endif()
  129. endif()
  130. if(NOT OPENEXR_VERSION)
  131. SET(OPENEXR_VERSION "Unknown")
  132. endif()
  133. ELSE()
  134. IF(OPENEXR_FIND_REQUIRED)
  135. MESSAGE(FATAL_ERROR "Could not find OpenEXR library")
  136. ENDIF()
  137. ENDIF()
  138. MARK_AS_ADVANCED(
  139. OPENEXR_INCLUDE_PATHS
  140. OPENEXR_LIBRARIES
  141. OPENEXR_ILMIMF_LIBRARY
  142. OPENEXR_IMATH_LIBRARY
  143. OPENEXR_IEX_LIBRARY
  144. OPENEXR_HALF_LIBRARY
  145. OPENEXR_ILMTHREAD_LIBRARY)