From: Egbert Eich <eich@suse.com>
Date: Sat Feb 5 14:50:58 2022 +0100
Subject: Make include and library path configurable using Cmake variables
Patch-mainline: Not yet
Git-commit: bb4d470ecb2ff1b36c35c05dd1ab846bd1b3510b
References: 

The include and library paths used may be different than the
default (lib, include). Attempt to get their values from
${PROJECT_NAME}_INSTALL_INCLUDE_DIR and ${PROJECT_NAME}_INSTALL_LIB_DIR.
Determine whether they are relative to CMAKE_INSTALL_PREFIX.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 packages/seacas/scripts/CMakeLists.txt | 21 +++++++++++++++++++++
 packages/seacas/scripts/exodus2.in.py  |  6 +++---
 packages/seacas/scripts/exodus3.in.py  |  6 +++---
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/packages/seacas/scripts/CMakeLists.txt b/packages/seacas/scripts/CMakeLists.txt
index 0d5d04c8..4f141449 100644
--- a/packages/seacas/scripts/CMakeLists.txt
+++ b/packages/seacas/scripts/CMakeLists.txt
@@ -5,6 +5,27 @@ endif()
 SET( ACCESSDIR ${CMAKE_INSTALL_PREFIX} )
 SET( SEPARATOR "_")
 
+IF( ${${PROJECT_NAME}_INSTALL_INCLUDE_DIR} MATCHES "^${CMAKE_INSTALL_PREFIX}.*" )
+   STRING( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" ""
+           SEACAS_INCLUDE "${${PROJECT_NAME}_INSTALL_INCLUDE_DIR}" )
+   STRING( REGEX REPLACE "^/" ""
+           SEACAS_INCLUDE "${SEACAS_INCLUDE}" )
+ELSEIF( NOT ${${PROJECT_NAME}_INSTALL_INCLUDE_DIR} MATCHES "^/" )
+   SET( SEACAS_INCLUDE "${${PROJECT_NAME}_INSTALL_INCLUDE_DIR}" )
+ELSE()
+   SET( SEACAS_INCLUDE "include" )
+ENDIF()
+IF( ${${PROJECT_NAME}_INSTALL_LIB_DIR} MATCHES "^${CMAKE_INSTALL_PREFIX}.*" )
+   STRING( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" ""
+           SEACAS_LIB "${${PROJECT_NAME}_INSTALL_LIB_DIR}" )
+   STRING( REGEX REPLACE "^/" ""
+           SEACAS_LIB "${SEACAS_LIB}")
+ELSEIF( NOT ${CMAKE_INSTALL_LIBDIR} MATCHES "^/" )
+   SET( SEACAS_LIB "${${PROJECT_NAME}_INSTALL_LIB_DIR}" )
+ELSE()
+   SET( SEACAS_LIB "lib" )
+ENDIF()
+
 ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASNemspread)
 ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASNemslice)
 IF (${PROJECT_NAME}_ENABLE_SEACASNemspread AND ${PROJECT_NAME}_ENABLE_SEACASNemslice)
diff --git a/packages/seacas/scripts/exodus2.in.py b/packages/seacas/scripts/exodus2.in.py
index b07b31ca..da1346bc 100644
--- a/packages/seacas/scripts/exodus2.in.py
+++ b/packages/seacas/scripts/exodus2.in.py
@@ -60,7 +60,7 @@ def getExodusVersion():
     version_major = 0
     version_minor = 0
     ACCESS = os.getenv('ACCESS', '@ACCESSDIR@')
-    for line in open(ACCESS + "/include/exodusII.h"):
+    for line in open(ACCESS + "/@SEACAS_INCLUDE@/exodusII.h"):
         fields = line.split()
         if (len(fields) == 3 and
                 fields[0] == '#define' and
@@ -76,9 +76,9 @@ def getExodusVersion():
 
 ACCESS = os.getenv('ACCESS', '@ACCESSDIR@')
 if os.uname()[0] == 'Darwin':
-    EXODUS_SO = ACCESS + "/lib/libexodus.dylib"
+    EXODUS_SO = ACCESS + "/@SEACAS_LIB@/libexodus.dylib"
 else:
-    EXODUS_SO = ACCESS + "/lib/libexodus.so"
+    EXODUS_SO = ACCESS + "/@SEACAS_LIB@/libexodus.so"
 EXODUS_LIB = cdll.LoadLibrary(EXODUS_SO)
 
 MAX_STR_LENGTH = 32      # match exodus default
diff --git a/packages/seacas/scripts/exodus3.in.py b/packages/seacas/scripts/exodus3.in.py
index 3fc5c45a..10b672e5 100644
--- a/packages/seacas/scripts/exodus3.in.py
+++ b/packages/seacas/scripts/exodus3.in.py
@@ -116,7 +116,7 @@ def getExodusVersion():
     """
     version_major = -1
     version_minor = -1
-    with open(ACCESS + "/include/exodusII.h") as header_file:
+    with open(ACCESS + "/@SEACAS_INCLUDE@/exodusII.h") as header_file:
         for line in header_file:
             fields = line.split()
             if (len(fields) == 3 and
@@ -162,9 +162,9 @@ class ex_options(Enum):
 
 ACCESS = os.getenv('ACCESS', '@ACCESSDIR@')
 if os.uname()[0] == 'Darwin':
-    EXODUS_SO = ACCESS + "/lib/libexodus.dylib"
+    EXODUS_SO = ACCESS + "/@SEACAS_LIB@/libexodus.dylib"
 else:
-    EXODUS_SO = ACCESS + "/lib/libexodus.so"
+    EXODUS_SO = ACCESS + "/@SEACAS_LIB@/libexodus.so"
 EXODUS_LIB = ctypes.cdll.LoadLibrary(EXODUS_SO)
 
 MAX_STR_LENGTH = 32      # match exodus default
