diff --git a/cmake/OpenCVFindOpenEXR.cmake b/cmake/OpenCVFindOpenEXR.cmake index c0a46806e1..39a0c7dbce 100644 --- a/cmake/OpenCVFindOpenEXR.cmake +++ b/cmake/OpenCVFindOpenEXR.cmake @@ -20,55 +20,89 @@ if(WIN32) elseif(MSVC) SET(OPENEXR_LIBSEARCH_SUFFIXES Win32/Release Win32 Win32/Debug) endif() -else() - set(OPENEXR_ROOT "") endif() -SET(LIBRARY_PATHS - /usr/lib - /usr/local/lib - /sw/lib - /opt/local/lib - "${ProgramFiles_ENV_PATH}/OpenEXR/lib/static" - "${OPENEXR_ROOT}/lib") +SET(SEARCH_PATHS + "${OPENEXR_ROOT}" + /usr + /usr/local + /sw + /opt + "${ProgramFiles_ENV_PATH}/OpenEXR") -FIND_PATH(OPENEXR_INCLUDE_PATH ImfRgbaFile.h - PATH_SUFFIXES OpenEXR - PATHS - /usr/include - /usr/local/include - /sw/include - /opt/local/include - "${ProgramFiles_ENV_PATH}/OpenEXR/include" - "${OPENEXR_ROOT}/include") +MACRO(FIND_OPENEXR_LIBRARY LIBRARY_NAME LIBRARY_SUFFIX) + string(TOUPPER "${LIBRARY_NAME}" LIBRARY_NAME_UPPER) + FIND_LIBRARY(OPENEXR_${LIBRARY_NAME_UPPER}_LIBRARY + NAMES ${LIBRARY_NAME}${LIBRARY_SUFFIX} + PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} + NO_DEFAULT_PATH + PATHS "${SEARCH_PATH}/lib" "${SEARCH_PATH}/lib/static") +ENDMACRO() -FIND_LIBRARY(OPENEXR_HALF_LIBRARY - NAMES Half - PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} - PATHS ${LIBRARY_PATHS}) +FOREACH(SEARCH_PATH ${SEARCH_PATHS}) + FIND_PATH(OPENEXR_INCLUDE_PATH ImfRgbaFile.h + PATH_SUFFIXES OpenEXR + NO_DEFAULT_PATH + PATHS + "${SEARCH_PATH}/include") -FIND_LIBRARY(OPENEXR_IEX_LIBRARY - NAMES Iex - PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} - PATHS ${LIBRARY_PATHS}) + IF (OPENEXR_INCLUDE_PATH) + SET(OPENEXR_VERSION_FILE "${OPENEXR_INCLUDE_PATH}/OpenEXRConfig.h") + IF (EXISTS ${OPENEXR_VERSION_FILE}) + FILE (STRINGS ${OPENEXR_VERSION_FILE} contents REGEX "#define OPENEXR_VERSION_MAJOR ") + IF (${contents} MATCHES "#define OPENEXR_VERSION_MAJOR ([0-9]+)") + SET(OPENEXR_VERSION_MAJOR "${CMAKE_MATCH_1}") + ENDIF () + FILE (STRINGS ${OPENEXR_VERSION_FILE} contents REGEX "#define OPENEXR_VERSION_MINOR ") + IF (${contents} MATCHES "#define OPENEXR_VERSION_MINOR ([0-9]+)") + SET(OPENEXR_VERSION_MINOR "${CMAKE_MATCH_1}") + ENDIF () + ENDIF () + ENDIF () -FIND_LIBRARY(OPENEXR_IMATH_LIBRARY - NAMES Imath - PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} - PATHS ${LIBRARY_PATHS}) + IF (OPENEXR_VERSION_MAJOR AND OPENEXR_VERSION_MINOR) + set(OPENEXR_VERSION "${OPENEXR_VERSION_MAJOR}_${OPENEXR_VERSION_MINOR}") + ENDIF () -FIND_LIBRARY(OPENEXR_ILMIMF_LIBRARY - NAMES IlmImf - PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} - PATHS ${LIBRARY_PATHS}) + SET(LIBRARY_SUFFIXES + "-${OPENEXR_VERSION}" + "-${OPENEXR_VERSION}_s" + "-${OPENEXR_VERSION}_d" + "-${OPEXEXR_VERSION}_s_d" + "" + "_s" + "_d" + "_s_d") -FIND_LIBRARY(OPENEXR_ILMTHREAD_LIBRARY - NAMES IlmThread - PATH_SUFFIXES ${OPENEXR_LIBSEARCH_SUFFIXES} - PATHS ${LIBRARY_PATHS}) + FOREACH(LIBRARY_SUFFIX ${LIBRARY_SUFFIXES}) + FIND_OPENEXR_LIBRARY("Half" ${LIBRARY_SUFFIX}) + FIND_OPENEXR_LIBRARY("Iex" ${LIBRARY_SUFFIX}) + FIND_OPENEXR_LIBRARY("Imath" ${LIBRARY_SUFFIX}) + FIND_OPENEXR_LIBRARY("IlmImf" ${LIBRARY_SUFFIX}) + FIND_OPENEXR_LIBRARY("IlmThread" ${LIBRARY_SUFFIX}) + IF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY) + SET(OPENEXR_FOUND TRUE) + BREAK() + ENDIF() + UNSET(OPENEXR_IMATH_LIBRARY) + UNSET(OPENEXR_ILMIMF_LIBRARY) + UNSET(OPENEXR_IEX_LIBRARY) + UNSET(OPENEXR_ILMTHREAD_LIBRARY) + UNSET(OPENEXR_HALF_LIBRARY) + ENDFOREACH() -IF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY) - SET(OPENEXR_FOUND TRUE) + IF (OPENEXR_FOUND) + BREAK() + ENDIF() + + UNSET(OPENEXR_INCLUDE_PATH) + UNSET(OPENEXR_VERSION_FILE) + UNSET(OPENEXR_VERSION_MAJOR) + UNSET(OPENEXR_VERSION_MINOR) + UNSET(OPENEXR_VERSION) +ENDFOREACH() + +IF (OPENEXR_FOUND) SET(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATH} CACHE PATH "The include paths needed to use OpenEXR") 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) ENDIF ()