CMake cleanup: Move OSL detection code into FindOpenShadingLanguage.cmake
Should be no functional changes.
This commit is contained in:
@@ -928,38 +928,18 @@ if(UNIX AND NOT APPLE)
|
|||||||
|
|
||||||
if(WITH_CYCLES_OSL)
|
if(WITH_CYCLES_OSL)
|
||||||
set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
|
set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
|
||||||
|
if(NOT OSL_ROOT)
|
||||||
message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
|
set(OSL_ROOT ${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()
|
endif()
|
||||||
|
find_package_wrapper(OpenShadingLanguage)
|
||||||
|
if(OSL_FOUND)
|
||||||
if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
|
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,
|
# Note: --whole-archive is needed to force loading of all symbols in liboslexec,
|
||||||
# otherwise LLVM is missing the osl_allocate_closure_component function
|
# 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})
|
set(OSL_LIBRARIES ${OSL_OSLCOMP_LIBRARY} -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY} -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY})
|
||||||
else()
|
|
||||||
list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
|
|
||||||
set(OSL_FOUND TRUE)
|
|
||||||
else()
|
else()
|
||||||
message(STATUS "OSL not found")
|
message(STATUS "OSL not found, disabling it from Cycles")
|
||||||
set(WITH_CYCLES_OSL OFF)
|
set(WITH_CYCLES_OSL OFF)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
98
build_files/cmake/Modules/FindOpenShadingLanguage.cmake
Normal file
98
build_files/cmake/Modules/FindOpenShadingLanguage.cmake
Normal file
@@ -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()
|
Reference in New Issue
Block a user