Permalink
Browse files

Simplify & modernize build finding of IlmBase.

Copy build logic from OIIO, and remove unused OpenEXR finding.
  • Loading branch information...
1 parent d0ba9c1 commit 838db3e4a700b39b2dea6cc9429d23ae2f20973e @lgritz lgritz committed Sep 21, 2012
Showing with 219 additions and 80 deletions.
  1. +5 −0 Makefile
  2. +0 −2 site/spi/Makefile-bits
  3. +6 −78 src/cmake/externalpackages.cmake
  4. +207 −0 src/cmake/modules/FindIlmBase.cmake
  5. +1 −0 src/liboslexec/CMakeLists.txt
View
@@ -75,6 +75,10 @@ ifneq (${USE_BOOST_WAVE},)
MY_CMAKE_FLAGS += -DUSE_BOOST_WAVE:BOOL=${USE_BOOST_WAVE}
endif
+ifneq (${ILMBASE_HOME},)
+MY_CMAKE_FLAGS += -DILMBASE_HOME:STRING=${ILMBASE_HOME}
+endif
+
ifdef DEBUG
MY_CMAKE_FLAGS += -DCMAKE_BUILD_TYPE:STRING=Debug
endif
@@ -221,4 +225,5 @@ help:
@echo " make NAMESPACE=name Wrap OSL APIs in another namespace"
@echo " make HIDE_SYMBOLS=1 Hide symbols not in the public API"
@echo " make USE_BOOST_WAVE=1 Use Boost 'wave' insted of cpp"
+ @echo " make ILMBASE_HOME=path ... Custom Ilmbase installation"
@echo ""
@@ -25,8 +25,6 @@ ifeq ($(SP_ARCH), spinux1_x86_64)
MY_CMAKE_FLAGS += \
-DILMBASE_CUSTOM=1 \
-DILMBASE_CUSTOM_LIBRARIES="SpiImath SpiHalf SpiIlmThread SpiIex" \
- -DOPENEXR_CUSTOM=1 \
- -DOPENEXR_CUSTOM_LIBRARY="SpiIlmImf" \
-DLLVM_CUSTOM=1 \
-DLLVM_STATIC=1 \
-DEXTRA_OSLEXEC_LIBRARIES="/usr/lib64/libpthread.so" \
@@ -33,9 +33,7 @@ endif ()
###########################################################################
-# IlmBase and OpenEXR setup
-
-# TODO: Place the OpenEXR stuff into a separate FindOpenEXR.cmake module.
+# IlmBase setup
# example of using setup_var instead:
#setup_var (ILMBASE_VERSION 1.0.1 "Version of the ILMBase library")
@@ -45,90 +43,20 @@ mark_as_advanced (ILMBASE_VERSION)
setup_path (ILMBASE_HOME "${THIRD_PARTY_TOOLS_HOME}"
"Location of the ILMBase library install")
mark_as_advanced (ILMBASE_HOME)
-find_path (ILMBASE_INCLUDE_AREA OpenEXR/half.h
- ${ILMBASE_HOME}/include/ilmbase-${ILMBASE_VERSION}
- ${ILMBASE_HOME}/include
- )
-if (ILMBASE_CUSTOM)
- set (IlmBase_Libraries ${ILMBASE_CUSTOM_LIBRARIES})
- separate_arguments(IlmBase_Libraries)
-else ()
- set (IlmBase_Libraries Imath Half IlmThread Iex)
-endif ()
-foreach (_lib ${IlmBase_Libraries})
- find_library (current_lib ${_lib}
- PATHS ${ILMBASE_HOME}/lib ${ILMBASE_HOME}/lib64
- ${ILMBASE_LIB_AREA}
- )
- list(APPEND ILMBASE_LIBRARIES ${current_lib})
- # this effectively unsets ${current_lib} so that find_library()
- # won't use the previous search results from the cache
- set (current_lib current_lib-NOTFOUND)
-endforeach ()
+find_package (IlmBase REQUIRED)
-message (STATUS "ILMBASE_INCLUDE_AREA = ${ILMBASE_INCLUDE_AREA}")
-message (STATUS "ILMBASE_LIBRARIES = ${ILMBASE_LIBRARIES}")
-
-if (ILMBASE_INCLUDE_AREA AND ILMBASE_LIBRARIES)
- set (ILMBASE_FOUND true)
- include_directories ("${ILMBASE_INCLUDE_AREA}")
- include_directories ("${ILMBASE_INCLUDE_AREA}/OpenEXR")
-else ()
- message (FATAL_ERROR "ILMBASE not found!")
-endif ()
+include_directories ("${ILMBASE_INCLUDE_DIR}")
+include_directories ("${ILMBASE_INCLUDE_DIR}/OpenEXR")
macro (LINK_ILMBASE target)
target_link_libraries (${target} ${ILMBASE_LIBRARIES})
endmacro ()
-setup_string (OPENEXR_VERSION 1.6.1 "OpenEXR version number")
-setup_string (OPENEXR_VERSION_DIGITS 010601 "OpenEXR version preprocessor number")
-mark_as_advanced (OPENEXR_VERSION)
-mark_as_advanced (OPENEXR_VERSION_DIGITS)
-# FIXME -- should instead do the search & replace automatically, like this
-# way it was done in the old makefiles:
-# OPENEXR_VERSION_DIGITS ?= 0$(subst .,0,${OPENEXR_VERSION})
-setup_path (OPENEXR_HOME "${THIRD_PARTY_TOOLS_HOME}"
- "Location of the OpenEXR library install")
-mark_as_advanced (OPENEXR_HOME)
-find_path (OPENEXR_INCLUDE_AREA OpenEXR/OpenEXRConfig.h
- ${OPENEXR_HOME}/include
- ${ILMBASE_HOME}/include/openexr-${OPENEXR_VERSION}
- )
-if (OPENEXR_CUSTOM)
- find_library (OPENEXR_LIBRARY ${OPENEXR_CUSTOM_LIBRARY}
- PATHS ${OPENEXR_HOME}/lib
- ${OPENEXR_HOME}/lib64
- ${OPENEXR_LIB_AREA}
- )
-else ()
- find_library (OPENEXR_LIBRARY IlmImf
- PATHS ${OPENEXR_HOME}/lib
- ${OPENEXR_HOME}/lib64
- ${OPENEXR_LIB_AREA}
- )
-endif ()
-
-message (STATUS "OPENEXR_INCLUDE_AREA = ${OPENEXR_INCLUDE_AREA}")
-message (STATUS "OPENEXR_LIBRARY = ${OPENEXR_LIBRARY}")
-if (OPENEXR_INCLUDE_AREA AND OPENEXR_LIBRARY)
- set (OPENEXR_FOUND true)
- include_directories (${OPENEXR_INCLUDE_AREA})
- include_directories (${OPENEXR_INCLUDE_AREA}/OpenEXR)
-else ()
- message (STATUS "OPENEXR not found!")
-endif ()
-add_definitions ("-DOPENEXR_VERSION=${OPENEXR_VERSION_DIGITS}")
-find_package (ZLIB)
-macro (LINK_OPENEXR target)
- target_link_libraries (${target} ${OPENEXR_LIBRARY} ${ZLIB_LIBRARIES})
-endmacro ()
-
-
-# end IlmBase and OpenEXR setup
+# end IlmBase setup
###########################################################################
+
###########################################################################
# Boost setup
@@ -0,0 +1,207 @@
+# Module to find IlmBase
+#
+# This module will first look into the directories defined by the variables:
+# - ILMBASE_HOME, ILMBASE_VERSION, ILMBASE_LIB_AREA
+#
+# It also supports non-standard names for the library components.
+#
+# To use a custom IlmBase:
+# - Set the variable ILMBASE_CUSTOM to True
+# - Set the variable ILMBASE_CUSTOM_LIBRARIES to a list of the libraries to
+# use, e.g. "SpiImath SpiHalf SpiIlmThread SpiIex"
+#
+# This module defines the following variables:
+#
+# ILMBASE_INCLUDE_DIR - where to find half.h, IlmBaseConfig.h, etc.
+# ILMBASE_LIBRARIES - list of libraries to link against when using IlmBase.
+# ILMBASE_FOUND - True if IlmBase was found.
+
+# Other standarnd issue macros
+include (FindPackageHandleStandardArgs)
+include (FindPackageMessage)
+include (SelectLibraryConfigurations)
+
+
+# Macro to assemble a helper state variable
+macro (SET_STATE_VAR varname)
+ set (tmp_ilmbaselibs ${ILMBASE_CUSTOM_LIBRARIES})
+ separate_arguments (tmp_ilmbaselibs)
+ set (tmp_lst
+ ${ILMBASE_CUSTOM} | ${tmp_ilmbaselibs} |
+ ${ILMBASE_HOME} | ${ILMBASE_VERSION} | ${ILMBASE_LIB_AREA}
+ )
+ set (${varname} "${tmp_lst}")
+ unset (tmp_ilmbaselibs)
+ unset (tmp_lst)
+endmacro ()
+
+
+# Macro to search for an include directory
+macro (PREFIX_FIND_INCLUDE_DIR prefix includefile libpath_var)
+ string (TOUPPER ${prefix}_INCLUDE_DIR tmp_varname)
+ find_path(${tmp_varname} ${includefile}
+ PATHS ${${libpath_var}}
+ PATH_SUFFIXES include
+ NO_DEFAULT_PATH
+ )
+ if (${tmp_varname})
+ mark_as_advanced (${tmp_varname})
+ endif ()
+ unset (tmp_varname)
+endmacro ()
+
+
+# Macro to search for the given library and adds the cached
+# variable names to the specified list
+macro (PREFIX_FIND_LIB prefix libname libpath_var liblist_var cachelist_var)
+ string (TOUPPER ${prefix}_${libname} tmp_prefix)
+ find_library(${tmp_prefix}_LIBRARY_RELEASE
+ NAMES ${libname}
+ PATHS ${${libpath_var}}
+ PATH_SUFFIXES lib
+ NO_DEFAULT_PATH
+ )
+ find_library(${tmp_prefix}_LIBRARY_DEBUG
+ NAMES ${libname}d ${libname}_d ${libname}debug ${libname}_debug
+ PATHS ${${libpath_var}}
+ PATH_SUFFIXES lib
+ NO_DEFAULT_PATH
+ )
+ # Properly define ${tmp_prefix}_LIBRARY (cached) and ${tmp_prefix}_LIBRARIES
+ select_library_configurations (${tmp_prefix})
+ list (APPEND ${liblist_var} ${tmp_prefix}_LIBRARIES)
+
+ # Add to the list of variables which should be reset
+ list (APPEND ${cachelist_var}
+ ${tmp_prefix}_LIBRARY
+ ${tmp_prefix}_LIBRARY_RELEASE
+ ${tmp_prefix}_LIBRARY_DEBUG)
+ mark_as_advanced (
+ ${tmp_prefix}_LIBRARY
+ ${tmp_prefix}_LIBRARY_RELEASE
+ ${tmp_prefix}_LIBRARY_DEBUG)
+ unset (tmp_prefix)
+endmacro ()
+
+
+# Encode the current state of the external variables into a string
+SET_STATE_VAR (ILMBASE_CURRENT_STATE)
+
+# If the state has changed, clear the cached variables
+if (ILMBASE_CACHED_STATE AND
+ NOT ILMBASE_CACHED_STATE STREQUAL ILMBASE_CURRENT_STATE)
+
+ foreach (libvar ${ILMBASE_CACHED_VARS})
+ unset (${libvar} CACHE)
+ endforeach ()
+endif ()
+
+if (ILMBASE_CUSTOM)
+ if (NOT ILMBASE_CUSTOM_LIBRARIES)
+ message (FATAL_ERROR "Custom IlmBase libraries requested but ILMBASE_CUSTOM_LIBRARIES is not set.")
+ endif()
+ set (IlmBase_Libraries ${ILMBASE_CUSTOM_LIBRARIES})
+ separate_arguments(IlmBase_Libraries)
+else ()
+ set (IlmBase_Libraries Half Iex Imath IlmThread)
+endif ()
+
+# Generic search paths
+set (IlmBase_generic_include_paths
+ /usr/include
+ /usr/local/include
+ /sw/include
+ /opt/local/include)
+set (IlmBase_generic_library_paths
+ /usr/lib
+ /usr/local/lib
+ /sw/lib
+ /opt/local/lib)
+
+# Search paths for the IlmBase files
+if (ILMBASE_HOME)
+ if (ILMBASE_VERSION)
+ set (IlmBase_include_paths
+ ${ILMBASE_HOME}/ilmbase-${ILMBASE_VERSION}/include
+ ${ILMBASE_HOME}/include/ilmbase-${ILMBASE_VERSION})
+ set (IlmBase_library_paths
+ ${ILMBASE_HOME}/ilmbase-${ILMBASE_VERSION}/lib
+ ${ILMBASE_HOME}/lib/ilmbase-${ILMBASE_VERSION})
+ endif()
+ list (APPEND IlmBase_include_paths ${ILMBASE_HOME}/include)
+ set (IlmBase_library_paths
+ ${ILMBASE_HOME}/lib
+ ${ILMBASE_HOME}/lib64
+ ${ILMBASE_LIB_AREA}
+ ${IlmBase_library_paths})
+endif ()
+list (APPEND IlmBase_include_paths ${IlmBase_generic_include_paths})
+list (APPEND IlmBase_library_paths ${IlmBase_generic_library_paths})
+
+# Locate the header files
+PREFIX_FIND_INCLUDE_DIR (IlmBase
+ OpenEXR/IlmBaseConfig.h IlmBase_include_paths)
+
+# If the headers were found, add its parent to the list of lib directories
+if (ILMBASE_INCLUDE_DIR)
+ get_filename_component (tmp_extra_dir "${ILMBASE_INCLUDE_DIR}/../" ABSOLUTE)
+ list (APPEND IlmBase_library_paths ${tmp_extra_dir})
+ unset (tmp_extra_dir)
+endif ()
+
+# Locate the IlmBase libraries
+set (IlmBase_libvars "")
+set (IlmBase_cachevars "")
+foreach (ilmbase_lib ${IlmBase_Libraries})
+ PREFIX_FIND_LIB (IlmBase ${ilmbase_lib}
+ IlmBase_library_paths IlmBase_libvars IlmBase_cachevars)
+endforeach ()
+
+# Create the list of variables that might need to be cleared
+set (ILMBASE_CACHED_VARS
+ ILMBASE_INCLUDE_DIR ${IlmBase_cachevars}
+ CACHE INTERNAL "Variables set by FindIlmBase.cmake" FORCE)
+
+# Store the current state so that variables might be cleared if required
+set (ILMBASE_CACHED_STATE ${ILMBASE_CURRENT_STATE}
+ CACHE INTERNAL "State last seen by FindIlmBase.cmake" FORCE)
+
+# Link with pthreads if required
+if (NOT WIN32 AND EXISTS ${ILMBASE_INCLUDE_DIR}/OpenEXR/IlmBaseConfig.h)
+ file (STRINGS ${ILMBASE_INCLUDE_DIR}/OpenEXR/IlmBaseConfig.h
+ ILMBASE_HAVE_PTHREAD
+ REGEX "^[ \\t]*#define[ \\t]+HAVE_PTHREAD[ \\t]1[ \\t]*\$"
+ )
+ if (ILMBASE_HAVE_PTHREAD)
+ find_package (Threads)
+ if (CMAKE_USE_PTHREADS_INIT)
+ set (ILMBASE_PTHREADS ${CMAKE_THREAD_LIBS_INIT})
+ endif ()
+ endif ()
+endif ()
+
+# Use the standard function to handle ILMBASE_FOUND
+FIND_PACKAGE_HANDLE_STANDARD_ARGS (IlmBase DEFAULT_MSG
+ ILMBASE_INCLUDE_DIR ${IlmBase_libvars})
+
+if (ILMBASE_FOUND)
+ set (ILMBASE_LIBRARIES "")
+ foreach (tmplib ${IlmBase_libvars})
+ list (APPEND ILMBASE_LIBRARIES ${${tmplib}})
+ endforeach ()
+ list (APPEND ILMBASE_LIBRARIES ${ILMBASE_PTHREADS})
+ FIND_PACKAGE_MESSAGE (ILMBASE
+ "Found IlmBase: ${ILMBASE_LIBRARIES}"
+ "[${ILMBASE_INCLUDE_DIR}][${ILMBASE_LIBRARIES}][${ILMBASE_CURRENT_STATE}]"
+ )
+endif ()
+
+# Unset the helper variables to avoid pollution
+unset (ILMBASE_CURRENT_STATE)
+unset (IlmBase_include_paths)
+unset (IlmBase_library_paths)
+unset (IlmBase_generic_include_paths)
+unset (IlmBase_generic_library_paths)
+unset (IlmBase_libvars)
+unset (IlmBase_cachevars)
+unset (ILMBASE_PTHREADS)
@@ -43,6 +43,7 @@ MACRO ( LLVM_COMPILE llvm_src srclist )
SET ( ${srclist} ${${srclist}} ${llvm_bc_cpp} )
EXEC_PROGRAM ( ${LLVM_DIRECTORY}/bin/llvm-config ARGS --cxxflags OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
set (LLVM_COMPILE_FLAGS "${LLVM_COMPILE_FLAGS} -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O3 --combine")
+ LIST (APPEND LLVM_COMPILE_FLAGS "-I${ILMBASE_INCLUDE_DIR}")
if (OSL_NAMESPACE)
LIST (APPEND LLVM_COMPILE_FLAGS "-DOSL_NAMESPACE=${OSL_NAMESPACE}")
endif ()

0 comments on commit 838db3e

Please sign in to comment.