From 16544bb4081597cdbe5f8a8ece58ccfacb83263b Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sat, 7 Jan 2012 21:49:12 +0100
Subject: [PATCH] BUG: fix issue #457. do not mix ITK_AUTOLOAD_PATH from build
 tree and install tree

---
 CMake/otbcli.sh.buildtree.in                  | 29 +++++++++++++++++++
 ...{otbcli.sh.in => otbcli.sh.installtree.in} |  6 ----
 CMake/otbgui.sh.buildtree.in                  | 29 +++++++++++++++++++
 ...{otbgui.sh.in => otbgui.sh.installtree.in} |  8 +----
 .../ApplicationLauncherQt/CMakeLists.txt      | 11 +++++--
 Code/Wrappers/CommandLine/CMakeLists.txt      | 14 +++++----
 6 files changed, 76 insertions(+), 21 deletions(-)
 create mode 100644 CMake/otbcli.sh.buildtree.in
 rename CMake/{otbcli.sh.in => otbcli.sh.installtree.in} (84%)
 create mode 100644 CMake/otbgui.sh.buildtree.in
 rename CMake/{otbgui.sh.in => otbgui.sh.installtree.in} (81%)

diff --git a/CMake/otbcli.sh.buildtree.in b/CMake/otbcli.sh.buildtree.in
new file mode 100644
index 0000000000..847b707512
--- /dev/null
+++ b/CMake/otbcli.sh.buildtree.in
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+#
+# Autogenerated by OTB installation process
+# DO NOT MODIFY
+#
+
+CURRENT_SCRIPT_DIR=`dirname $0`
+
+if [ -e $CURRENT_SCRIPT_DIR/otbApplicationLauncherCommandLine ]
+then
+  # Prefer using the launcher inside the script dir
+  OTB_CLI_LAUNCHER=$CURRENT_SCRIPT_DIR/otbApplicationLauncherCommandLine
+else
+  # Use the one from the PATH
+  OTB_CLI_LAUNCHER=otbApplicationLauncherCommandLine
+fi
+
+# works for build dir
+if [ -d @APPLICATION_BINARY_PATH@ ]
+then
+  ITK_AUTOLOAD_PATH=@APPLICATION_BINARY_PATH@:$ITK_AUTOLOAD_PATH
+fi
+
+# export it to make it available to otbApplicationLauncherCommandLine environment
+export ITK_AUTOLOAD_PATH
+
+# start the application
+$OTB_CLI_LAUNCHER "$@"
diff --git a/CMake/otbcli.sh.in b/CMake/otbcli.sh.installtree.in
similarity index 84%
rename from CMake/otbcli.sh.in
rename to CMake/otbcli.sh.installtree.in
index 6cb5437f7d..fb4b6a9aa5 100644
--- a/CMake/otbcli.sh.in
+++ b/CMake/otbcli.sh.installtree.in
@@ -16,12 +16,6 @@ else
   OTB_CLI_LAUNCHER=otbApplicationLauncherCommandLine
 fi
 
-# works for build dir
-if [ -d @APPLICATION_BINARY_PATH@ ]
-then
-  ITK_AUTOLOAD_PATH=@APPLICATION_BINARY_PATH@:$ITK_AUTOLOAD_PATH
-fi
-
 # works for install tree
 if [ -d $CURRENT_SCRIPT_DIR/../@OTB_INSTALL_APP_DIR_CM24@ ]
 then
diff --git a/CMake/otbgui.sh.buildtree.in b/CMake/otbgui.sh.buildtree.in
new file mode 100644
index 0000000000..eb04c45cc9
--- /dev/null
+++ b/CMake/otbgui.sh.buildtree.in
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+#
+# Autogenerated by OTB installation process
+# DO NOT MODIFY
+#
+
+CURRENT_SCRIPT_DIR=`dirname $0`
+
+if [ -e $CURRENT_SCRIPT_DIR/otbApplicationLauncherQt ]
+then
+  # Prefer using the launcher inside the script dir
+  OTB_GUI_LAUNCHER=$CURRENT_SCRIPT_DIR/otbApplicationLauncherQt
+else
+  # Use the one from the PATH
+  OTB_GUI_LAUNCHER=otbApplicationLauncherQt
+fi
+
+# use the buildtree path to applications
+if [ -d @APPLICATION_BINARY_PATH@ ]
+then
+  ITK_AUTOLOAD_PATH=@APPLICATION_BINARY_PATH@:$ITK_AUTOLOAD_PATH
+fi
+
+# export it to make it available to otbApplicationLauncherCommandLine environment
+export ITK_AUTOLOAD_PATH
+
+# start the application
+$OTB_GUI_LAUNCHER "$@"
diff --git a/CMake/otbgui.sh.in b/CMake/otbgui.sh.installtree.in
similarity index 81%
rename from CMake/otbgui.sh.in
rename to CMake/otbgui.sh.installtree.in
index f82c694ad9..c4b18470d4 100644
--- a/CMake/otbgui.sh.in
+++ b/CMake/otbgui.sh.installtree.in
@@ -16,13 +16,7 @@ else
   OTB_GUI_LAUNCHER=otbApplicationLauncherQt
 fi
 
-# works for build dir
-if [ -d @APPLICATION_BINARY_PATH@ ]
-then
-  ITK_AUTOLOAD_PATH=@APPLICATION_BINARY_PATH@:$ITK_AUTOLOAD_PATH
-fi
-
-# works for install tree
+# use the default install tree path for applications
 if [ -d $CURRENT_SCRIPT_DIR/../@OTB_INSTALL_APP_DIR_CM24@ ]
 then
   ITK_AUTOLOAD_PATH=$CURRENT_SCRIPT_DIR/../@OTB_INSTALL_APP_DIR_CM24@:$ITK_AUTOLOAD_PATH
diff --git a/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt b/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt
index 3d37c35f30..b36bc8c733 100644
--- a/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt
+++ b/Code/Wrappers/ApplicationLauncherQt/CMakeLists.txt
@@ -25,12 +25,17 @@ set(APPLICATION_BINARY_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
 
 # Generate a script in the build dir, next to the cli launcher
 # Need a two-step process since configure_file don't support permissions
-configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbgui.sh.in
-                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbgui
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/buildtree)
+configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbgui.sh.buildtree.in
+                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/buildtree/otbgui
                 @ONLY )
 file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbgui
      DESTINATION ${CLI_OUPUT_DIR}
      FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)  
 
-install(PROGRAMS ${CLI_OUPUT_DIR}/otbgui
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree)
+configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbgui.sh.installtree.in
+                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree/otbgui
+                @ONLY )
+install(PROGRAMS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree/otbgui
         DESTINATION ${OTB_INSTALL_BIN_DIR_CM24})
diff --git a/Code/Wrappers/CommandLine/CMakeLists.txt b/Code/Wrappers/CommandLine/CMakeLists.txt
index b56286995d..68bc328d27 100644
--- a/Code/Wrappers/CommandLine/CMakeLists.txt
+++ b/Code/Wrappers/CommandLine/CMakeLists.txt
@@ -31,17 +31,21 @@ install(TARGETS otbApplicationLauncherCommandLine
 get_target_property(CLI_OUPUT_DIR otbApplicationLauncherCommandLine RUNTIME_OUTPUT_DIRECTORY)
 
 # What is the path to the applications
-# a MODULE target is always treated as LIBRARY
 set(APPLICATION_BINARY_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
 
 # Generate a script in the build dir, next to the cli launcher
 # Need a two-step process since configure_file don't support permissions
-configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbcli.sh.in
-                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbcli
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/buildtree)
+configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbcli.sh.buildtree.in
+                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/buildtree/otbcli
                 @ONLY )
-file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/otbcli
+file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/buildtree/otbcli
      DESTINATION ${CLI_OUPUT_DIR}
      FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)  
 
-install(PROGRAMS ${CLI_OUPUT_DIR}/otbcli
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree)
+configure_file( ${CMAKE_SOURCE_DIR}/CMake/otbcli.sh.installtree.in
+                ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree/otbcli
+                @ONLY )
+install(PROGRAMS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Scripts/installtree/otbcli
         DESTINATION ${OTB_INSTALL_BIN_DIR_CM24})
-- 
GitLab