1
0
OpenShadingLanguage/0001-Generalize-lookup-of-stdosl.h-in-install-directory-a.patch
Stefan Brüns 1d8ebb2e7a Accepting request 746037 from home:StefanBruens:branches:graphics
- Properly rebase 0001-Generalize-lookup-of-stdosl.h-in-install-directory-a.patch
  avoid workarounds in the spec file.
- Remove conditional code for Leap 42.x
- Reflect required versions of OpenIIO and Clang in the spec file.

OBS-URL: https://build.opensuse.org/request/show/746037
OBS-URL: https://build.opensuse.org/package/show/graphics/OpenShadingLanguage?expand=0&rev=9
2019-11-06 16:00:11 +00:00

148 lines
5.7 KiB
Diff

From b01c5510a1bc825a5bf90155ca926844fd679430 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Sun, 13 Jan 2019 01:50:59 +0100
Subject: [PATCH] Generalize lookup of stdosl.h in install directory, allow
customization
Currently, shaders are installed in <PREFIX>/shaders, which does not
fit the needs of most Linux distributions, where <PREFIX> is typically
/usr/, and architecture independent data like the shaders should be
installed in e.g. /usr/share/OpenShadingLanguage/shaders/.
Typically, CMAKE_INSTALL_DATADIR is used for this case, but this would
break the current scheme. Introduce an OSL specific option instead,
OSL_INSTALL_SHADERDIR (default ""), which can be used to specify an
absolute or relative path for the shader installation.
Usage (relative to CMAKE_INSTALL_PREFIX):
$> cmake -DCMAKE_INSTALL_PREFIX=/usr/ \
-DOSL_INSTALL_SHADERDIR=share/OpenShadingLanguage
Same effect, using absolute paths:
$> cmake -DCMAKE_INSTALL_PREFIX=/usr/ \
-DOSL_INSTALL_SHADERDIR=/usr/share/OpenShadingLanguage
The configured path is added to the stdosl.h path lookup, i.e. for
the example above "/usr/share/OpenShadingLanguage/shaders/stdosl.h".
---
CMakeLists.txt | 9 +++++++++
src/liboslcomp/CMakeLists.txt | 3 +++
src/liboslcomp/oslcomp.cpp | 9 +++++++++
src/liboslcomp/oslcomp_shaders_dir.h.in | 7 +++++++
src/liboslexec/CMakeLists.txt | 1 +
src/shaders/CMakeLists.txt | 2 +-
src/shaders/MaterialX/CMakeLists.txt | 2 +-
7 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 src/liboslcomp/oslcomp_shaders_dir.h.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3722d68..cb5320e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,15 @@ if (CMAKE_USE_FOLDERS)
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
endif ()
+option (OSL_INSTALL_SHADERDIR "Shader install directory, absolute or relative (to CMAKE_INSTALL_PREFIX)" "")
+mark_as_advanced (OSL_INSTALL_SHADERDIR)
+if (IS_ABSOLUTE ${OSL_INSTALL_SHADERDIR})
+ set (INSTALL_FULL_SHADERDIR ${OSL_INSTALL_SHADERDIR})
+else()
+ set (INSTALL_FULL_SHADERDIR "${CMAKE_INSTALL_PREFIX}/${OSL_INSTALL_SHADERDIR}")
+endif()
+message (STATUS "Shader install dir = ${INSTALL_FULL_SHADERDIR}")
+
include (GNUInstallDirs)
list (APPEND CMAKE_MODULE_PATH
diff --git a/src/liboslcomp/CMakeLists.txt b/src/liboslcomp/CMakeLists.txt
index 549aa54..a91a1b5 100644
--- a/src/liboslcomp/CMakeLists.txt
+++ b/src/liboslcomp/CMakeLists.txt
@@ -29,6 +29,9 @@ else ()
endif ()
+configure_file ( oslcomp_shaders_dir.h.in oslcomp_shaders_dir.h )
+target_include_directories ( oslcomp PRIVATE "${CMAKE_BINARY_DIR}/src/liboslcomp" )
+
TARGET_LINK_LIBRARIES ( oslcomp ${OPENIMAGEIO_LIBRARIES} ${ILMBASE_LIBRARIES}
${Boost_LIBRARIES} ${CMAKE_DL_LIBS}
${CLANG_LIBRARIES} ${LLVM_LIBRARIES} ${LLVM_LDFLAGS}
diff --git a/src/liboslcomp/oslcomp.cpp b/src/liboslcomp/oslcomp.cpp
index 76145dd..db1ec06 100644
--- a/src/liboslcomp/oslcomp.cpp
+++ b/src/liboslcomp/oslcomp.cpp
@@ -36,6 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cerrno>
#include "oslcomp_pvt.h"
+#include "oslcomp_shaders_dir.h"
#include <OpenImageIO/platform.h>
#include <OpenImageIO/sysutil.h>
@@ -485,6 +486,14 @@ find_stdoslpath (const std::vector<std::string>& includepaths)
}
}
+ // Try the regular install directory
+ std::string install_path = OSL_SHADERS_INSTALL_DIR;
+ if (OIIO::Filesystem::is_directory (install_path)) {
+ install_path = install_path + "/stdosl.h";
+ if (OIIO::Filesystem::exists (install_path))
+ return ustring(install_path);
+ }
+
// Try looking for "oslc" binary in the $PATH, and if so, look in
// ../../shaders/stdosl.h
std::vector<std::string> exec_path_dirs;
diff --git a/src/liboslcomp/oslcomp_shaders_dir.h.in b/src/liboslcomp/oslcomp_shaders_dir.h.in
new file mode 100644
index 0000000..0638252
--- /dev/null
+++ b/src/liboslcomp/oslcomp_shaders_dir.h.in
@@ -0,0 +1,7 @@
+#ifndef OSL_SHADERS_INSTALL_DIR
+
+// Keep this in sync with the DESTINATION in shaders/CMakeLists.txt
+// and shaders/MaterialX/CMakeLists.txt
+#define OSL_SHADERS_INSTALL_DIR "@INSTALL_FULL_SHADERDIR@/shaders/"
+
+#endif // OSL_SHADERS_INSTALL_DIR
diff --git a/src/liboslexec/CMakeLists.txt b/src/liboslexec/CMakeLists.txt
index 9f39444..fce411b 100644
--- a/src/liboslexec/CMakeLists.txt
+++ b/src/liboslexec/CMakeLists.txt
@@ -41,6 +41,7 @@ if (NOT BUILDSTATIC)
endif ()
include_directories ( "${CMAKE_SOURCE_DIR}/src/liboslcomp" )
+include_directories ( "${CMAKE_BINARY_DIR}/src/liboslcomp" )
FILE ( GLOB exec_headers "*.h" )
FILE ( GLOB compiler_headers "../liboslcomp/*.h" )
diff --git a/src/shaders/CMakeLists.txt b/src/shaders/CMakeLists.txt
index 9b263ff..594c09c 100644
--- a/src/shaders/CMakeLists.txt
+++ b/src/shaders/CMakeLists.txt
@@ -63,4 +63,4 @@ add_custom_target (shaders ALL
SOURCES ${shader_source} ${shader_headers})
install (FILES ${shader_headers} ${shader_source} ${shader_objs}
- DESTINATION shaders)
+ DESTINATION ${INSTALL_FULL_SHADERDIR}/shaders)
diff --git a/src/shaders/MaterialX/CMakeLists.txt b/src/shaders/MaterialX/CMakeLists.txt
index 88b52f3..42384da 100644
--- a/src/shaders/MaterialX/CMakeLists.txt
+++ b/src/shaders/MaterialX/CMakeLists.txt
@@ -258,5 +258,5 @@ add_custom_target (mxshaders ALL
SOURCES ${shader_source} ${mx_shader_headers})
install (FILES ${mx_shader_headers} ${mx_shader_objs} ${mx_shader_osls}
- DESTINATION shaders/MaterialX)
+ DESTINATION ${INSTALL_FULL_SHADERDIR}/shaders/MaterialX)
--
2.24.0