]> SALOME platform Git repositories - tools/configuration.git/commitdiff
Salome HOME
Configure C++ standard to be used
authorSALOME <salome@opencascade.com>
Mon, 24 Aug 2020 07:50:37 +0000 (10:50 +0300)
committervsr <vsr@opencascade.com>
Thu, 12 Nov 2020 09:22:16 +0000 (12:22 +0300)
cmake/SalomeSetupPlatform.cmake

index a1290e6360a7908b19a9b14a680b295db75dbbcd..87cfdf1be29b566794084ad8439606cb9bf655ff 100644 (file)
@@ -106,23 +106,27 @@ IF(COMPILER_SUPPORTS_NO_OPERATOR_NAMES)
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names")
 ENDIF()
 
-SET(NO_CXX11_SUPPORT OFF CACHE BOOL "Disable C++11 support")
-IF(NOT NO_CXX11_SUPPORT)
-  # C++11 support
-  CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
-  IF(COMPILER_SUPPORTS_CXX11)
-    MESSAGE(STATUS "Enable C++11 support")
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-  ELSE()
-    CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
-    IF(COMPILER_SUPPORTS_CXX0X)
-      MESSAGE(STATUS "Enable C++0x support")
-      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
-    ELSE()
-      MESSAGE(WARNING "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
-    ENDIF()
+# Option: C++ standard to use
+# Note: CMake by default enables C++ extensions; they can be disabled by additionally
+#       specifying -DCMAKE_CXX_EXTENSIONS=OFF
+SET(SALOME_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
+SET(_supported_standards 11 14 17 20)
+SET(_standard_ok FALSE)
+FOREACH(_standard ${_supported_standards})
+  IF(SALOME_CXX_STANDARD STREQUAL _standard)
+    SET(_standard_ok TRUE)
+    BREAK()
   ENDIF()
+ENDFOREACH()
+IF(NOT _standard_ok)
+  MESSAGE(FATAL_ERROR "Unsupported C++ standard: ${SALOME_CXX_STANDARD}; allowed values: ${_supported_standards}")
 ENDIF()
+UNSET(_supported_standards)
+UNSET(_standard)
+UNSET(_standard_ok)
+MESSAGE(STATUS "Setting C++ standard to ${SALOME_CXX_STANDARD}")
+SET(CMAKE_CXX_STANDARD ${SALOME_CXX_STANDARD})
+SET(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 # Fight warnings
 IF(NOT APPLE)