forked from pool/OpenShadingLanguage
147 lines
5.6 KiB
Diff
147 lines
5.6 KiB
Diff
|
From 2e80787bfadd3d02064d72f7d5374d07bc0225cc 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 | 2 ++
|
||
|
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, 30 insertions(+), 2 deletions(-)
|
||
|
create mode 100644 src/liboslcomp/oslcomp_shaders_dir.h.in
|
||
|
|
||
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||
|
index 02feab53..05d5e959 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)
|
||
|
|
||
|
set (CMAKE_MODULE_PATH
|
||
|
diff --git a/src/liboslcomp/CMakeLists.txt b/src/liboslcomp/CMakeLists.txt
|
||
|
index 549aa549..15d9d026 100644
|
||
|
--- a/src/liboslcomp/CMakeLists.txt
|
||
|
+++ b/src/liboslcomp/CMakeLists.txt
|
||
|
@@ -29,6 +29,8 @@ else ()
|
||
|
|
||
|
endif ()
|
||
|
|
||
|
+configure_file ( oslcomp_shaders_dir.h.in oslcomp_shaders_dir.h )
|
||
|
+
|
||
|
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 a89212aa..d4deda70 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>
|
||
|
@@ -478,6 +479,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 00000000..0638252f
|
||
|
--- /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 eb8f0fa9..ff5595cc 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 9b263ffa..594c09cb 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 98f54840..d134fcde 100644
|
||
|
--- a/src/shaders/MaterialX/CMakeLists.txt
|
||
|
+++ b/src/shaders/MaterialX/CMakeLists.txt
|
||
|
@@ -196,5 +196,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.20.1
|
||
|
|