]> SALOME platform Git repositories - tools/libbatch.git/commitdiff
Salome HOME
Add option to choose C++ standard; default value is set to 11 (requries CMake minimal... occ/warnings
authorvsr <vsr@opencascade.com>
Mon, 14 Sep 2020 08:50:01 +0000 (11:50 +0300)
committervsr <vsr@opencascade.com>
Mon, 21 Sep 2020 12:45:37 +0000 (15:45 +0300)
CMakeLists.txt

index a120733355b0c0a22bc275055a133585e9126748..ec66a121e3c84d20c9d315fa24c635bd27ceca8e 100644 (file)
@@ -20,7 +20,7 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)
 PROJECT(LibBatch C CXX)
 
 # Versioning
@@ -63,23 +63,19 @@ ENDIF()
 
 INCLUDE(CheckCXXCompilerFlag)
 
-SET(LIBBATCH_NO_CXX11_SUPPORT FALSE CACHE BOOL "Switch OFF C++-11 standard")
-IF(NOT LIBBATCH_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()
-  ENDIF()
+# Option: C++ standard to use
+# Note: CMake by default enables C++ extensions; they can be disabled by additionally
+#       specifying -DCMAKE_CXX_EXTENSIONS=OFF
+CMAKE_POLICY(SET CMP0057 NEW) # for IF(IN_LIST) operator
+SET(LIBBATCH_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
+SET(_supported_standards 11 14 17 20)
+IF(NOT ${LIBBATCH_CXX_STANDARD} IN_LIST _supported_standards)
+  MESSAGE(FATAL_ERROR "Unsupported C++ standard: ${LIBBATCH_CXX_STANDARD}; allowed values: ${_supported_standards}")
 ENDIF()
+UNSET(_supported_standards)
+MESSAGE(STATUS "Setting C++ standard to ${LIBBATCH_CXX_STANDARD}")
+SET(CMAKE_CXX_STANDARD ${LIBBATCH_CXX_STANDARD})
+SET(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 IF(NOT (WIN32 OR APPLE))
   SET(LIBBATCH_DEBUG_WARNINGS FALSE CACHE BOOL "Print more compiler warnings")