diff Resources/CMake/JsonCppConfiguration.cmake @ 1947:c1053112b323

Switch to the C++11 standard if the version of JsonCpp is 1.y.z
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Apr 2016 10:11:40 +0200
parents fbf763bb1fa3
children 326fdda31b42
line wrap: on
line diff
--- a/Resources/CMake/JsonCppConfiguration.cmake	Mon Apr 04 13:37:31 2016 +0200
+++ b/Resources/CMake/JsonCppConfiguration.cmake	Tue Apr 05 10:11:40 2016 +0200
@@ -32,4 +32,25 @@
     message(FATAL_ERROR "Please install the libjsoncpp-dev package")
   endif()
 
+  # Switch to the C++11 standard if the version of JsonCpp is 1.y.z
+  message(${JSONCPP_INCLUDE_DIR}/json/version.h)
+  if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h)
+    file(STRINGS
+      "${JSONCPP_INCLUDE_DIR}/json/version.h" 
+      JSONCPP_VERSION_MAJOR1 REGEX
+      ".*JSONCPP_VERSION_MAJOR .*")
+    string(REGEX REPLACE
+      ".*JSONCPP_VERSION_MAJOR ([0-9]+)\\s*$" "\\1" 
+      JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1})
+    message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}")
+
+    if (CMAKE_COMPILER_IS_GNUCXX AND 
+        JSONCPP_VERSION_MAJOR GREATER 0)
+      message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+    endif()
+  else()
+    message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
+  endif()
+
 endif()