replace own inline cmake include search logic for a typical FindXXX.cmake module.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 15 Jun 2011 12:09:02 +0000 (12:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 15 Jun 2011 12:09:02 +0000 (12:09 +0000)
CMakeLists.txt
build_files/cmake/Modules/FindOpenEXR.cmake [new file with mode: 0644]
build_files/cmake/macros.cmake
source/blender/imbuf/intern/openexr/CMakeLists.txt

index 2c27076c10ef1c6304385035ce6991e34cafe423..cca34fca36e9b02f95ea089f2a51d1d3507be36c 100644 (file)
@@ -342,23 +342,8 @@ if(UNIX AND NOT APPLE)
        endif()
 
        if(WITH_IMAGE_OPENEXR)
        endif()
 
        if(WITH_IMAGE_OPENEXR)
-               set(OPENEXR /usr CACHE FILEPATH "OPENEXR Directory")
-               mark_as_advanced(OPENEXR)
-               find_path(OPENEXR_INC
-                       ImfXdr.h
-                       PATHS
-                       ${OPENEXR}/include/OpenEXR
-                       /usr/local/include/OpenEXR
-                       /sw/include/OpenEXR
-                       /opt/local/include/OpenEXR
-                       /opt/csw/include/OpenEXR
-                       /opt/include/OpenEXR
-               )
-               mark_as_advanced(OPENEXR_INC)
-
-               set(OPENEXR_LIB Half IlmImf Iex Imath)
-               
-               if(NOT OPENEXR_INC)
+               find_package(OpenEXR)  # our own module
+               if(NOT OPENEXR_FOUND)
                        set(WITH_IMAGE_OPENEXR OFF)
                endif()
        endif()
                        set(WITH_IMAGE_OPENEXR OFF)
                endif()
        endif()
@@ -657,10 +642,10 @@ elseif(WIN32)
                                set(MSVC_INC)
                        endif()
                        set(OPENEXR ${LIBDIR}/openexr)                  
                                set(MSVC_INC)
                        endif()
                        set(OPENEXR ${LIBDIR}/openexr)                  
-                       set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
+                       set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
                        set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
                        set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
-                       set(OPENEXR_INC ${OPENEXR_INCUDE}/ ${OPENEXR_INCUDE}/IlmImf ${OPENEXR_INCUDE}/Iex ${OPENEXR_INCUDE}/Imath)
+                       set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCUDE}/ ${OPENEXR_INCUDE}/IlmImf ${OPENEXR_INCUDE}/Iex ${OPENEXR_INCUDE}/Imath)
                endif()
 
                if(WITH_IMAGE_TIFF)
                endif()
 
                if(WITH_IMAGE_TIFF)
@@ -759,8 +744,8 @@ elseif(WIN32)
 
                if(WITH_IMAGE_OPENEXR)
                        set(OPENEXR ${LIBDIR}/gcc/openexr)
 
                if(WITH_IMAGE_OPENEXR)
                        set(OPENEXR ${LIBDIR}/gcc/openexr)
-                       set(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/OpenEXR)
-                       set(OPENEXR_LIB Half IlmImf Imath IlmThread)
+                       set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include ${OPENEXR}/include/OpenEXR)
+                       set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread)
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib)
 
                        # TODO, gives linking errors, force off
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib)
 
                        # TODO, gives linking errors, force off
@@ -892,8 +877,8 @@ elseif(APPLE)
 
        if(WITH_IMAGE_OPENEXR)
                set(OPENEXR ${LIBDIR}/openexr)
 
        if(WITH_IMAGE_OPENEXR)
                set(OPENEXR ${LIBDIR}/openexr)
-               set(OPENEXR_INC ${OPENEXR}/include/OpenEXR ${OPENEXR}/include)
-               set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
+               set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR ${OPENEXR}/include)
+               set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
                set(OPENEXR_LIBPATH ${OPENEXR}/lib)
        endif()
 
                set(OPENEXR_LIBPATH ${OPENEXR}/lib)
        endif()
 
diff --git a/build_files/cmake/Modules/FindOpenEXR.cmake b/build_files/cmake/Modules/FindOpenEXR.cmake
new file mode 100644 (file)
index 0000000..8ddd3ca
--- /dev/null
@@ -0,0 +1,76 @@
+# - Find OpenEXR library (copied from FindTIFF.cmake, v 2.8.5)
+# Find the native OpenEXR includes and library
+# This module defines
+#  OPENEXR_INCLUDE_DIRS, where to find ImfXdr.h, etc. Set when
+#                        OPENEXR_INCLUDE_DIR is found.
+#  OPENEXR_LIBRARIES, libraries to link against to use OpenEXR.
+#  OPENEXR_ROOT_DIR, The base directory to search for OpenEXR.
+#                    This can also be an environment variable.
+#  OPENEXR_FOUND, If false, do not try to use OpenEXR.
+# also defined, but not for general use are
+#  OPENEXR_LIBRARY, where to find the OpenEXR library.
+
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# If OPENEXR_ROOT_DIR was defined in the environment, use it.
+IF(NOT OPENEXR_ROOT_DIR AND NOT $ENV{OPENEXR_ROOT_DIR} STREQUAL "")
+  SET(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR})
+ENDIF()
+
+SET(_openexr_FIND_COMPONENTS
+  Half
+  IlmImf
+  Iex
+  Imath
+)
+
+SET(_openexr_SEARCH_DIRS
+  ${OPENEXR_ROOT_DIR}
+  /usr/local
+  /opt/csw
+)
+
+FIND_PATH(OPENEXR_INCLUDE_DIR ImfXdr.h
+  HINTS
+    ${_openexr_SEARCH_DIRS}
+  PATH_SUFFIXES
+    include/OpenEXR
+)
+
+SET(_openexr_LIBRARIES)
+FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
+  STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+  FIND_LIBRARY(OPENEXR_${UPPERCOMPONENT}_LIBRARY NAMES ${COMPONENT}
+      HINTS ${_openexr_SEARCH_DIRS}
+      PATH_SUFFIXES lib
+      )
+  LIST(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}")
+ENDFOREACH()
+
+# handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if 
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR  DEFAULT_MSG
+    ${_openexr_LIBRARIES} OPENEXR_INCLUDE_DIR)
+
+IF(OPENEXR_FOUND)
+  SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
+  SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR})
+ENDIF(OPENEXR_FOUND)
+
+MARK_AS_ADVANCED(
+  ${_openexr_LIBRARIES}
+  OPENEXR_INCLUDE_DIR
+)
index 8189769cbbcf38af3c4a493e9ca76fc829b3a786..a862034c002c290881993b9514f020a8dd5560e9 100644 (file)
@@ -205,13 +205,13 @@ macro(setup_liblinks
        endif()
        if(WITH_IMAGE_OPENEXR)
                if(WIN32 AND NOT UNIX)
        endif()
        if(WITH_IMAGE_OPENEXR)
                if(WIN32 AND NOT UNIX)
-                       foreach(_LOOP_VAR ${OPENEXR_LIB})
+                       foreach(_LOOP_VAR ${OPENEXR_LIBRARIES})
                                target_link_libraries(${target} debug ${_LOOP_VAR}_d)
                                target_link_libraries(${target} optimized ${_LOOP_VAR})
                        endforeach()
                        unset(_LOOP_VAR)
                else()
                                target_link_libraries(${target} debug ${_LOOP_VAR}_d)
                                target_link_libraries(${target} optimized ${_LOOP_VAR})
                        endforeach()
                        unset(_LOOP_VAR)
                else()
-                       target_link_libraries(${target} ${OPENEXR_LIB})
+                       target_link_libraries(${target} ${OPENEXR_LIBRARIES})
                endif()
        endif()
        if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
                endif()
        endif()
        if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
index c1140bc59a97a0c0d99f7e6b6839d409928cbebc..9ca4dff5bc851917692dbae7d324c06e87856072 100644 (file)
@@ -44,7 +44,7 @@ set(SRC
 )
 
 if(WITH_IMAGE_OPENEXR)
 )
 
 if(WITH_IMAGE_OPENEXR)
-       list(APPEND INC_SYS ${OPENEXR_INC})
+       list(APPEND INC_SYS ${OPENEXR_INCLUDE_DIRS})
        add_definitions(-DWITH_OPENEXR)
 endif()
 
        add_definitions(-DWITH_OPENEXR)
 endif()