Преглед на файлове

cmake: Enable C++11 standards support

This patch checks for, and enables C++11 support for building UPM.
This should work for all cmake versions currently supported by UPM
(2.8.11+), and any compiler (clang/gcc) that was released in this
decade.

Support can be specifically disabled by passing '-DENABLECXX11=OFF' to
cmake, though modules requiring this support will not build.

C++11 support is enabled by default.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Jon Trulson преди 9 години
родител
ревизия
7a133cf891
променени са 1 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 22
    0
      CMakeLists.txt

+ 22
- 0
CMakeLists.txt Целия файл

@@ -58,6 +58,7 @@ option (BUILDSWIGJAVA "Build swig java modules" OFF)
58 58
 option (IPK "Generate IPK using CPack" OFF)
59 59
 option (RPM "Generate RPM using CPack" OFF)
60 60
 option (BUILDTESTS "Generate check-ups for upm" ON)
61
+option (ENABLECXX11 "Enable C++11 standards support" ON)
61 62
 
62 63
 # Find swig
63 64
 if (BUILDSWIG)
@@ -76,6 +77,27 @@ include (TargetArch)
76 77
 target_architecture (DETECTED_ARCH)
77 78
 message( INFO " - Target arch is ${DETECTED_ARCH}")
78 79
 
80
+# enable c++11 standards support
81
+if (ENABLECXX11)
82
+  include(CheckCXXCompilerFlag)
83
+  if (CMAKE_VERSION VERSION_LESS "3.1")
84
+    CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
85
+    CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
86
+    if (COMPILER_SUPPORTS_CXX11)
87
+      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
88
+    elseif (COMPILER_SUPPORTS_CXX0X)
89
+      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
90
+    else()
91
+      message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
92
+    endif()
93
+  else()
94
+    # 3.1+ uses this generic method to enable c++11
95
+    set (CMAKE_CXX_STANDARD 11)
96
+  endif()
97
+else()
98
+  message(WARNING "Some modules require C++11 support, and may not build without it.")
99
+endif()
100
+
79 101
 if (BUILDDOC)
80 102
   # Add a target to generate API documentation with Doxygen
81 103
   find_package (Doxygen)