From 8cab82799ca311a47e07eb3f9ea752f800dcd05a Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Thu, 24 Nov 2016 18:12:49 +0100
Subject: [PATCH] BUG: fix c++11 requirement, check must be done after
 enablement/disablement routines

---
 CMake/OTBModuleEnablement.cmake | 5 +++++
 CMake/OTBModuleMacros.cmake     | 4 +---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/CMake/OTBModuleEnablement.cmake b/CMake/OTBModuleEnablement.cmake
index a2d78ac07c..be1475f008 100644
--- a/CMake/OTBModuleEnablement.cmake
+++ b/CMake/OTBModuleEnablement.cmake
@@ -169,6 +169,11 @@ set(OTB_MODULES_ENABLED "")
 set(OTB_MODULES_DISABLED "")
 foreach(otb-module ${OTB_MODULES_ALL})
   if(${otb-module}_ENABLED)
+    # check cxx11 requirement after all enable/disable macros have been passed
+    if(OTB_MODULE_${otb-module}_REQUIRES_CXX11 AND NOT OTB_HAS_CXX11)
+      message(FATAL_ERROR "Module ${otb-module} requires C++11 support. Consider adding --std=c++11 to your compiler flags or disabling it.")
+    endif()
+
     list(APPEND OTB_MODULES_ENABLED ${otb-module})
 
     # We will sort modules according to their dependency graph,
diff --git a/CMake/OTBModuleMacros.cmake b/CMake/OTBModuleMacros.cmake
index b45a9757a4..0580f8e50c 100644
--- a/CMake/OTBModuleMacros.cmake
+++ b/CMake/OTBModuleMacros.cmake
@@ -336,7 +336,5 @@ macro(otb_module_target _name)
 endmacro()
 
 macro(otb_module_requires_cxx11)
-  if(${otb-module}_ENABLED AND NOT ${OTB_HAS_CXX11})
-    message(FATAL_ERROR "Module ${otb-module} requires C++11 support. Consider adding --std=c++11 to your compiler flags or disabling it.")
-  endif()  
+  set(OTB_MODULE_${otb-module}_REQUIRES_CXX11 1)
 endmacro()
-- 
GitLab