Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-02-10 00:39:00 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-02-10 00:45:59 +0300
commit53c4033b5b20ab652653446407d2b2cf910c30b3 (patch)
tree47f5113e8afca6c6697931b2c623b8f688932229
parent4ca4f04c75c456d3614855ebaa70bab9a92eb36a (diff)
CMake cleanup: Move OSL detection code into FindOpenShadingLanguage.cmake
Should be no functional changes.
-rw-r--r--CMakeLists.txt42
-rw-r--r--build_files/cmake/Modules/FindOpenShadingLanguage.cmake98
2 files changed, 109 insertions, 31 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 15356e3445c..026386a876b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -928,38 +928,18 @@ if(UNIX AND NOT APPLE)
if(WITH_CYCLES_OSL)
set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
-
- message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
-
- # TODO(sergey): Move to dedicated FindOpenShadingLanguage.cmake
- find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
- find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
- find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
- find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
- find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
- if(EXISTS ${OSL_INCLUDE_DIR})
- file(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MAJOR
- REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+[0-9]+.*$")
- file(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MINOR
- REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+[0-9]+.*$")
- string(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+([.0-9]+).*"
- "\\1" OSL_LIBRARY_VERSION_MAJOR ${OSL_LIBRARY_VERSION_MAJOR})
- string(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+([.0-9]+).*"
- "\\1" OSL_LIBRARY_VERSION_MINOR ${OSL_LIBRARY_VERSION_MINOR})
- endif()
-
- if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
- # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
- # otherwise LLVM is missing the osl_allocate_closure_component function
- list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
- else()
- list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
- endif()
-
- if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
- set(OSL_FOUND TRUE)
+ if(NOT OSL_ROOT)
+ set(OSL_ROOT ${CYCLES_OSL})
+ endif()
+ find_package_wrapper(OpenShadingLanguage)
+ if(OSL_FOUND)
+ if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
+ # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
+ # otherwise LLVM is missing the osl_allocate_closure_component function
+ set(OSL_LIBRARIES ${OSL_OSLCOMP_LIBRARY} -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY} -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY})
+ endif()
else()
- message(STATUS "OSL not found")
+ message(STATUS "OSL not found, disabling it from Cycles")
set(WITH_CYCLES_OSL OFF)
endif()
endif()
diff --git a/build_files/cmake/Modules/FindOpenShadingLanguage.cmake b/build_files/cmake/Modules/FindOpenShadingLanguage.cmake
new file mode 100644
index 00000000000..824d0f90597
--- /dev/null
+++ b/build_files/cmake/Modules/FindOpenShadingLanguage.cmake
@@ -0,0 +1,98 @@
+# - Find OpenShadingLanguage library
+# Find the native OpenShadingLanguage includes and library
+# This module defines
+# OSL_INCLUDE_DIRS, where to find OSL headers, Set when
+# OSL_INCLUDE_DIR is found.
+# OSL_LIBRARIES, libraries to link against to use OSL.
+# OSL_ROOT_DIR, the base directory to search for OSL.
+# This can also be an environment variable.
+# OSL_COMPILER, full path to OSL script compiler.
+# OSL_FOUND, if false, do not try to use OSL.
+# OSL_LIBRARY_VERSION_MAJOR, OSL_LIBRARY_VERSION_MINOR, the major
+# and minor versions of OSL library if found.
+#
+#=============================================================================
+# Copyright 2014 Blender Foundation.
+#
+# 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.
+#=============================================================================
+
+# If OSL_ROOT_DIR was defined in the environment, use it.
+IF(NOT OSL_ROOT_DIR AND NOT $ENV{OSL_ROOT_DIR} STREQUAL "")
+ SET(OSL_ROOT_DIR $ENV{OSL_ROOT_DIR})
+ENDIF()
+
+SET(_osl_FIND_COMPONENTS
+ oslcomp
+ oslexec
+ oslquery
+)
+
+SET(_osl_SEARCH_DIRS
+ ${OSL_ROOT_DIR}
+ /usr/local
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt/lib/osl
+)
+
+FIND_PATH(OSL_INCLUDE_DIR
+ NAMES
+ OSL/oslversion.h
+ HINTS
+ ${_osl_SEARCH_DIRS}
+ PATH_SUFFIXES
+ include
+)
+
+SET(_osl_LIBRARIES)
+FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
+ STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+ FIND_LIBRARY(OSL_${UPPERCOMPONENT}_LIBRARY
+ NAMES
+ ${COMPONENT}
+ HINTS
+ ${_osl_SEARCH_DIRS}
+ PATH_SUFFIXES
+ lib64 lib
+ )
+ LIST(APPEND _osl_LIBRARIES "${OSL_${UPPERCOMPONENT}_LIBRARY}")
+ENDFOREACH()
+
+FIND_PROGRAM(OSL_COMPILER oslc
+ HINTS ${_osl_SEARCH_DIRS}
+ PATH_SUFFIXES bin)
+
+# handle the QUIETLY and REQUIRED arguments and set OSL_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OSL DEFAULT_MSG _osl_LIBRARIES OSL_INCLUDE_DIR OSL_COMPILER)
+
+IF(OSL_FOUND)
+ SET(OSL_LIBRARIES ${_osl_LIBRARIES})
+ SET(OSL_INCLUDE_DIRS ${OSL_INCLUDE_DIR})
+
+ FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MAJOR
+ REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+[0-9]+.*$")
+ FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MINOR
+ REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+[0-9]+.*$")
+ STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+([.0-9]+).*"
+ "\\1" OSL_LIBRARY_VERSION_MAJOR ${OSL_LIBRARY_VERSION_MAJOR})
+ STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+([.0-9]+).*"
+ "\\1" OSL_LIBRARY_VERSION_MINOR ${OSL_LIBRARY_VERSION_MINOR})
+ENDIF(OSL_FOUND)
+
+MARK_AS_ADVANCED(
+ OSL_INCLUDE_DIR
+)
+FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
+ STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+ MARK_AS_ADVANCED(OSL_${UPPERCOMPONENT}_LIBRARY)
+ENDFOREACH()