From 2f6bf0da2c30c087a277afdde20c867560005109 Mon Sep 17 00:00:00 2001
From: Rashad Kanavath <rashad.kanavath@c-s.fr>
Date: Thu, 19 Jan 2017 10:58:33 +0100
Subject: [PATCH] COMP: call find_package(OTB) if needed

---
 Examples/CMakeLists.txt             |  9 +++++----
 Utilities/Completion/CMakeLists.txt | 11 ++++++++---
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt
index 04b570526e..94ebcd0d4b 100644
--- a/Examples/CMakeLists.txt
+++ b/Examples/CMakeLists.txt
@@ -10,11 +10,16 @@ endif()
 
 #check if this is a standalone build?
 
+find_package(OTB REQUIRED)
+message(STATUS "[Examples] Found OTB: ${OTB_USE_FILE}")
+
 if(PROJECT_NAME STREQUAL "OTBExamples")
   if(BUILD_TESTING)
     include(CTest)
   endif()
 
+  include(${OTB_USE_FILE})
+
   # dashboard build. Why do I need to see the deprecated warnings on dashboard!
   # It just fades the actual warnings and most importantly very annoying.
   if(NOT "$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
@@ -135,10 +140,6 @@ else()
   include(${CMAKE_CURRENT_SOURCE_DIR}/../CMake/OTBManageLargeInputPaths.cmake)
 endif()
 
-find_package(OTB REQUIRED)
-include(${OTB_USE_FILE})
-message(STATUS "Found OTB: ${OTB_USE_FILE}")
-
 set(OTB_TEST_DRIVER otbTestDriver)
 
 if(OTBApplicationEngine_LOADED)
diff --git a/Utilities/Completion/CMakeLists.txt b/Utilities/Completion/CMakeLists.txt
index 7647a6916d..fc9f4f9d38 100644
--- a/Utilities/Completion/CMakeLists.txt
+++ b/Utilities/Completion/CMakeLists.txt
@@ -1,6 +1,11 @@
-
-find_package(OTB REQUIRED)
-include(${OTB_USE_FILE})
+##### check if standalone project ######
+if(NOT PROJECT_NAME)
+  cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
+  project(OTBCompletion)
+  find_package(OTB REQUIRED)
+  message("OTBCompletion")
+  include(${OTB_USE_FILE})
+endif()
 
 add_executable(completionGenerator EXCLUDE_FROM_ALL completionGenerator.cxx)
 target_link_libraries(completionGenerator ${OTB_LIBRARIES})
-- 
GitLab