From c078d90a6570d3cdf372f33f83057b21e44f40ad Mon Sep 17 00:00:00 2001
From: Jonathan Scruggs <j.scruggs@gmail.com>
Date: Thu, 28 Sep 2017 15:08:47 +0100
Subject: [PATCH 1/2] oiio/RB-1.6: Use GNUInstallDirs for installation paths
 (#1747)

* Change all hard coded paths to GNUInstallDirs varibles.
* Remove variable setting in install.cmake file since
  GNUInstallDirs does all this for you.
* Added new search paths for fonts.

Backported from:
https://github.com/OpenImageIO/oiio/commit/1383ba314ec2522b4f0c7e9037bd546b68bc2d7d
---
 CMakeLists.txt                           | 51 ++++++++------------------------
 src/cmake/oiio_macros.cmake              |  6 ++--
 src/doc/CMakeLists.txt                   |  4 +--
 src/fonts/CMakeLists.txt                 |  2 +-
 src/include/CMakeLists.txt               |  2 +-
 src/libOpenImageIO/imagebufalgo_draw.cpp | 11 +++++++
 src/nuke/txReader/CMakeLists.txt         |  3 +-
 src/nuke/txWriter/CMakeLists.txt         |  3 +-
 8 files changed, 32 insertions(+), 50 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bcbcbf94..b29efac6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -302,6 +302,8 @@ if (NOT OIIO_NAMESPACE)
 endif ()
 message(STATUS "Setting Namespace to: ${OIIO_NAMESPACE}")
 
+include (GNUInstallDirs)
+
 set (CMAKE_MODULE_PATH
      "${PROJECT_SOURCE_DIR}/src/cmake/modules"
      "${PROJECT_SOURCE_DIR}/src/cmake")
@@ -319,58 +321,32 @@ include_directories (
 
 
 ###########################################################################
-# Paths for install tree customization.  Note that relative paths are relative
-# to CMAKE_INSTALL_PREFIX.
-set (DEFAULT_BIN_INSTALL_DIR   "bin")
-set (DEFAULT_LIB_INSTALL_DIR   "lib")
-set (DEFAULT_INCLUDE_INSTALL_DIR "include/OpenImageIO")
+# Set install paths for the python modules
+# TODO: Figure out how to get the correct python directory
+
 if (UNIX AND NOT SELF_CONTAINED_INSTALL_TREE)
-    # Try to be well-behaved and install into reasonable places according to
-    # the "standard" unix directory heirarchy
     # TODO: Figure out how to get the correct python directory
-    set (DEFAULT_PYLIB_INSTALL_DIR "lib/python/site-packages")
-    set (DEFAULT_PYLIB3_INSTALL_DIR "lib/python3/site-packages")
-    set (DEFAULT_DOC_INSTALL_DIR "share/doc/OpenImageIO")
-    set (DEFAULT_MAN_INSTALL_DIR "share/man/man1")
-    set (DEFAULT_FONTS_INSTALL_DIR "share/fonts/oiio")
+    set (DEFAULT_PYLIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python/site-packages")
+    set (DEFAULT_PYLIB3_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python3/site-packages")
 else ()
-    # Here is the "self-contained install tree" case: the expectation here is
-    # that everything OIIO related will go into its own directory, not into
-    # some standard system heirarchy.
+    # Here is the "self-contained install tree" case: the expectation here
+    # is that everything related to this project will go into its own
+    # directory, not into some standard system heirarchy.
     set (DEFAULT_PYLIB_INSTALL_DIR "python")
     set (DEFAULT_PYLIB3_INSTALL_DIR "python3")
-    set (DEFAULT_DOC_INSTALL_DIR "doc")
-    set (DEFAULT_MAN_INSTALL_DIR "doc/man")
-    set (DEFAULT_FONTS_INSTALL_DIR "fonts/oiio")
 endif ()
 if (EXEC_INSTALL_PREFIX)
     # Tack on an extra prefix to support multi-arch builds.
-    set (DEFAULT_BIN_INSTALL_DIR   "${EXEC_INSTALL_PREFIX}/${DEFAULT_BIN_INSTALL_DIR}")
-    set (DEFAULT_LIB_INSTALL_DIR   "${EXEC_INSTALL_PREFIX}/${DEFAULT_LIB_INSTALL_DIR}")
     set (DEFAULT_PYLIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${DEFAULT_PYLIB_INSTALL_DIR}")
     set (DEFAULT_PYLIB3_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${DEFAULT_PYLIB3_INSTALL_DIR}")
-    set (DEFAULT_FONTS_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${DEFAULT_FONTS_INSTALL_DIR}")
 endif ()
 # Set up cmake cache variables corresponding to the defaults deduced above, so
 # that the user can override them as desired:
-set (BIN_INSTALL_DIR ${DEFAULT_BIN_INSTALL_DIR} CACHE STRING
-     "Install location for binaries (relative to CMAKE_INSTALL_PREFIX or absolute)")
-set (LIB_INSTALL_DIR ${DEFAULT_LIB_INSTALL_DIR} CACHE STRING
-     "Install location for libraries (relative to CMAKE_INSTALL_PREFIX or absolute)")
 set (PYLIB_INSTALL_DIR ${DEFAULT_PYLIB_INSTALL_DIR} CACHE STRING
      "Install location for python libraries (relative to CMAKE_INSTALL_PREFIX or absolute)")
 set (PYLIB3_INSTALL_DIR ${DEFAULT_PYLIB3_INSTALL_DIR} CACHE STRING
      "Install location for python3 libraries (relative to CMAKE_INSTALL_PREFIX or absolute)")
-set (INCLUDE_INSTALL_DIR ${DEFAULT_INCLUDE_INSTALL_DIR} CACHE STRING
-     "Install location of header files (relative to CMAKE_INSTALL_PREFIX or absolute)")
-set (DOC_INSTALL_DIR ${DEFAULT_DOC_INSTALL_DIR} CACHE STRING
-     "Install location for documentation (relative to CMAKE_INSTALL_PREFIX or absolute)")
-set (FONTS_INSTALL_DIR ${DEFAULT_FONTS_INSTALL_DIR} CACHE STRING
-     "Install location for fonts (relative to CMAKE_INSTALL_PREFIX or absolute)")
-if (UNIX)
-    set (MAN_INSTALL_DIR ${DEFAULT_MAN_INSTALL_DIR} CACHE STRING
-         "Install location for manual pages (relative to CMAKE_INSTALL_PREFIX or absolute)")
-endif()
+
 set (PLUGIN_SEARCH_PATH "" CACHE STRING "Default plugin search path")
 
 set (INSTALL_DOCS ON CACHE BOOL "Install documentation")
@@ -388,10 +364,7 @@ if (CMAKE_SKIP_RPATH)
     set (CMAKE_SKIP_RPATH FALSE)
     unset (CMAKE_INSTALL_RPATH)
 else ()
-    set (CMAKE_INSTALL_RPATH "${LIB_INSTALL_DIR}")
-    if (NOT IS_ABSOLUTE ${CMAKE_INSTALL_RPATH})
-        set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
-    endif ()
+    set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
     set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 endif ()
 
diff --git a/src/cmake/oiio_macros.cmake b/src/cmake/oiio_macros.cmake
index e65020bf..22d78ccd 100644
--- a/src/cmake/oiio_macros.cmake
+++ b/src/cmake/oiio_macros.cmake
@@ -7,9 +7,9 @@
 #
 macro (oiio_install_targets)
     install (TARGETS ${ARGN}
-             RUNTIME DESTINATION "${BIN_INSTALL_DIR}" COMPONENT user
-             LIBRARY DESTINATION "${LIB_INSTALL_DIR}" COMPONENT user
-             ARCHIVE DESTINATION "${LIB_INSTALL_DIR}" COMPONENT developer)
+             RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT user
+             LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT user
+             ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT developer)
 endmacro ()
 
 # Macro to add a build target for an IO plugin.
diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt
index 5e2e9866..170ff89c 100644
--- a/src/doc/CMakeLists.txt
+++ b/src/doc/CMakeLists.txt
@@ -7,7 +7,7 @@ set (public_docs
 )
 
 if (INSTALL_DOCS)
-    install (FILES ${public_docs} DESTINATION ${DOC_INSTALL_DIR}
+    install (FILES ${public_docs} DESTINATION ${CMAKE_INSTALL_DOCDIR}
              COMPONENT documentation)
 endif ()
 
@@ -37,6 +37,6 @@ if (UNIX AND TXT2MAN AND PYTHONINTERP_FOUND)
 
     if (INSTALL_DOCS)
         install (FILES ${manpage_files}
-                 DESTINATION ${MAN_INSTALL_DIR} COMPONENT documentation)
+                 DESTINATION ${CMAKE_INSTALL_MANDIR} COMPONENT documentation)
     endif ()
 endif()
diff --git a/src/fonts/CMakeLists.txt b/src/fonts/CMakeLists.txt
index 1e296da0..d1bd6409 100644
--- a/src/fonts/CMakeLists.txt
+++ b/src/fonts/CMakeLists.txt
@@ -1,7 +1,7 @@
 file (GLOB public_fonts "*/*.ttf")
 
 if (INSTALL_FONTS AND USE_FREETYPE)
-    install (FILES ${public_fonts} DESTINATION ${FONTS_INSTALL_DIR}
+    install (FILES ${public_fonts} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/fonts/OpenImageIO
              COMPONENT fonts)
 endif ()
 
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
index b605b53b..5cdc6542 100644
--- a/src/include/CMakeLists.txt
+++ b/src/include/CMakeLists.txt
@@ -17,5 +17,5 @@ set (OIIO_VERSION_NS "v${MANGLED_SOVERSION}")
 configure_file(OpenImageIO/oiioversion.h.in "${CMAKE_BINARY_DIR}/include/OpenImageIO/oiioversion.h" @ONLY)
 list(APPEND public_headers "${CMAKE_BINARY_DIR}/include/OpenImageIO/oiioversion.h")
 
-install (FILES ${public_headers} DESTINATION ${INCLUDE_INSTALL_DIR}
+install (FILES ${public_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/OpenImageIO
          COMPONENT developer)
diff --git a/src/libOpenImageIO/imagebufalgo_draw.cpp b/src/libOpenImageIO/imagebufalgo_draw.cpp
index fb4dcf4d..cb9ef095 100644
--- a/src/libOpenImageIO/imagebufalgo_draw.cpp
+++ b/src/libOpenImageIO/imagebufalgo_draw.cpp
@@ -441,27 +441,38 @@ ImageBufAlgo::render_text (ImageBuf &R, int x, int y, string_view text,
     if (home && *home) {
         std::string h (home);
         search_dirs.push_back (h + "/fonts");
+        search_dirs.push_back (h + "/fonts/OpenImageIO");
         search_dirs.push_back (h + "/Fonts");
+        search_dirs.push_back (h + "/Fonts/OpenImageIO");
         search_dirs.push_back (h + "/Library/Fonts");
+        search_dirs.push_back (h + "/Library/Fonts/OpenImageIO");
     }
     const char *systemRoot = getenv ("SystemRoot");
     if (systemRoot && *systemRoot)
         search_dirs.push_back (std::string(systemRoot) + "/Fonts");
+        search_dirs.push_back (std::string(systemRoot) + "/Fonts/OpenImageIO");
     search_dirs.push_back ("/usr/share/fonts");
+
     search_dirs.push_back ("/Library/Fonts");
+    search_dirs.push_back ("/Library/Fonts/OpenImageIO");
     search_dirs.push_back ("C:/Windows/Fonts");
+    search_dirs.push_back ("C:/Windows/Fonts/OpenImageIO");
     search_dirs.push_back ("/usr/local/share/fonts");
+    search_dirs.push_back ("/usr/local/share/fonts/OpenImageIO");
     search_dirs.push_back ("/opt/local/share/fonts");
+    search_dirs.push_back ("/opt/local/share/fonts/OpenImageIO");
     // Try $OPENIMAGEIOHOME/fonts
     const char *oiiohomedir = getenv ("OPENIMAGEIOHOME");
     if (oiiohomedir && *oiiohomedir)
         search_dirs.push_back (std::string(oiiohomedir) + "/fonts");
+        search_dirs.push_back (std::string(oiiohomedir) + "/fonts/OpenImageIO");
     // Try ../fonts relative to where this executing binary came from
     std::string this_program = OIIO::Sysutil::this_program_path ();
     if (this_program.size()) {
         std::string path = Filesystem::parent_path (this_program);
         path = Filesystem::parent_path (path);
         search_dirs.push_back (path+"/fonts");
+        search_dirs.push_back (path+"/fonts/OpenImageIO");
     }
 
     // Try to find the font.  Experiment with several extensions
diff --git a/src/nuke/txReader/CMakeLists.txt b/src/nuke/txReader/CMakeLists.txt
index 3e72b6d4..660a2ee1 100644
--- a/src/nuke/txReader/CMakeLists.txt
+++ b/src/nuke/txReader/CMakeLists.txt
@@ -28,5 +28,4 @@ else ()
         COMPILE_FLAGS "-fPIC -msse")
 endif ()
 
-install (TARGETS txReader
-    LIBRARY DESTINATION "${LIB_INSTALL_DIR}/nuke")
+oiio_install_targets (txReader)
diff --git a/src/nuke/txWriter/CMakeLists.txt b/src/nuke/txWriter/CMakeLists.txt
index 66312bc4..0fb70a36 100644
--- a/src/nuke/txWriter/CMakeLists.txt
+++ b/src/nuke/txWriter/CMakeLists.txt
@@ -28,5 +28,4 @@ else ()
         COMPILE_FLAGS "-fPIC -msse")
 endif ()
 
-install (TARGETS txWriter
-    LIBRARY DESTINATION "${LIB_INSTALL_DIR}/nuke")
+oiio_install_targets (txWriter)
-- 
2.14.2

