From 6e90151d652dfc640b3ca7eef65862fec4b9eb36 Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Mon, 9 Mar 2015 10:26:58 +0100
Subject: [PATCH] COMP: only sort enabled dependencies

---
 CMake/OTBModuleEnablement.cmake | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/CMake/OTBModuleEnablement.cmake b/CMake/OTBModuleEnablement.cmake
index 4e6eec844a..d10935462c 100644
--- a/CMake/OTBModuleEnablement.cmake
+++ b/CMake/OTBModuleEnablement.cmake
@@ -170,10 +170,14 @@ foreach(otb-module ${OTB_MODULES_ALL})
 
     # We will sort modules according to their dependency graph,
     # to enable them in order. To solve the modules dependency graph,
-    # we join both DEPENDS and OPTIONAL_DEPENDS
+    # we join both DEPENDS and OPTIONAL_DEPENDS (if enabled)
     set(OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT "")
     list(APPEND OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT ${OTB_MODULE_${otb-module}_DEPENDS})
-    list(APPEND OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT ${OTB_MODULE_${otb-module}_OPTIONAL_DEPENDS})
+    foreach(opt-dep ${OTB_MODULE_${otb-module}_OPTIONAL_DEPENDS})
+      if(${opt-dep}_ENABLED)
+        list(APPEND OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT ${opt-dep})
+      endif()
+    endforeach()
   else()
     list(APPEND OTB_MODULES_DISABLED ${otb-module})
   endif()
-- 
GitLab