From 2e80787bfadd3d02064d72f7d5374d07bc0225cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= 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 /shaders, which does not fit the needs of most Linux distributions, where 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 Index: OpenShadingLanguage-Release-1.10.7/CMakeLists.txt =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/CMakeLists.txt 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/CMakeLists.txt 2019-11-06 11:56:09.880927045 +0200 @@ -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 Index: OpenShadingLanguage-Release-1.10.7/src/liboslcomp/CMakeLists.txt =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/src/liboslcomp/CMakeLists.txt 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/src/liboslcomp/CMakeLists.txt 2019-11-06 11:56:09.880927045 +0200 @@ -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} Index: OpenShadingLanguage-Release-1.10.7/src/liboslcomp/oslcomp.cpp =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/src/liboslcomp/oslcomp.cpp 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/src/liboslcomp/oslcomp.cpp 2019-11-06 11:56:09.880927045 +0200 @@ -36,6 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE #include #include "oslcomp_pvt.h" +#include "oslcomp_shaders_dir.h" #include #include @@ -485,6 +486,14 @@ find_stdoslpath (const std::vector exec_path_dirs; Index: OpenShadingLanguage-Release-1.10.7/src/liboslcomp/oslcomp_shaders_dir.h.in =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ OpenShadingLanguage-Release-1.10.7/src/liboslcomp/oslcomp_shaders_dir.h.in 2019-11-06 11:56:09.880927045 +0200 @@ -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 Index: OpenShadingLanguage-Release-1.10.7/src/liboslexec/CMakeLists.txt =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/src/liboslexec/CMakeLists.txt 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/src/liboslexec/CMakeLists.txt 2019-11-06 11:56:09.880927045 +0200 @@ -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" ) Index: OpenShadingLanguage-Release-1.10.7/src/shaders/CMakeLists.txt =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/src/shaders/CMakeLists.txt 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/src/shaders/CMakeLists.txt 2019-11-06 11:56:09.880927045 +0200 @@ -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) Index: OpenShadingLanguage-Release-1.10.7/src/shaders/MaterialX/CMakeLists.txt =================================================================== --- OpenShadingLanguage-Release-1.10.7.orig/src/shaders/MaterialX/CMakeLists.txt 2019-10-01 08:05:04.000000000 +0200 +++ OpenShadingLanguage-Release-1.10.7/src/shaders/MaterialX/CMakeLists.txt 2019-11-06 11:56:09.880927045 +0200 @@ -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)