Выбор версии стандарта C++ (для Астра 1.5 - 11, иначе 17)

This commit is contained in:
Andrei Astafev 2021-05-30 20:31:10 +03:00
parent c6414bbc03
commit 28cf80381e

View File

@ -19,33 +19,68 @@ macro(CHECK_ENABLE_CXX_FLAG flag)
unset(CHECK_CXX_FLAG CACHE) unset(CHECK_CXX_FLAG CACHE)
endmacro() endmacro()
if(LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE" AND LSB_CODENAME STREQUAL "smolensk" AND LSB_RELEASE STREQUAL function(cmlib_set_cxx_standard version)
"1.5")
# Выбор стандарта по умолчанию (можно переопределить в проекте)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if(version STREQUAL "11")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS YES)
endif()
if(version STREQUAL "14")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS YES)
endif()
if(version STREQUAL "17")
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
check_cxx_compiler_flag(-std=gnu++17 HAVE_FLAG_STD_GNUXX17)
if(HAVE_FLAG_STD_GNUXX17)
add_compile_options("-std=gnu++17")
else()
check_cxx_compiler_flag(-std=gnu++1z HAVE_FLAG_STD_GNUXX1Z)
if(HAVE_FLAG_STD_GNUXX1Z)
add_compile_options("-std=gnu++1z")
else()
check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17)
if(HAVE_FLAG_STD_CXX17)
add_compile_options("-std=c++17")
else()
check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z)
if(HAVE_FLAG_STD_CXX1Z)
add_compile_options("-std=c++1z")
endif()
endif()
endif()
endif()
else()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS YES)
endif()
endif()
endfunction()
# cmake-format: off
if(LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE" AND
LSB_CODENAME STREQUAL "smolensk" AND
LSB_RELEASE STREQUAL "1.5")
# cmake-format: on
cmlib_set_cxx_standard(11)
set(_CMAKE_TOOLCHAIN_PREFIX "x86_64-linux-gnu-") set(_CMAKE_TOOLCHAIN_PREFIX "x86_64-linux-gnu-")
set(_CMAKE_TOOLCHAIN_SUFFIX "-4.7") set(_CMAKE_TOOLCHAIN_SUFFIX "-4.7")
set(_CMAKE_TOOLCHAIN_LOCATION} "/usr/bin") set(_CMAKE_TOOLCHAIN_LOCATION} "/usr/bin")
else() else()
cmlib_set_cxx_standard(17)
# -Wshadow gives a lot of false positives with GCC 4.7.2 in Astra Linux 1.5 # -Wshadow gives a lot of false positives with GCC 4.7.2 in Astra Linux 1.5
if(CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_GCC)
check_enable_cxx_flag(-Wshadow) check_enable_cxx_flag(-Wshadow)
endif() endif()
endif() endif()
# Выбор стандарта по умолчанию (можно переопределить в проекте)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
check_cxx_compiler_flag(-std=c++14 HAVE_FLAG_STD_CXX14)
if(HAVE_FLAG_STD_CXX14)
set(CMAKE_CXX_STANDARD 14)
check_cxx_compiler_flag(-std=gnu++14 HAVE_FLAG_STD_GNUXX14)
if(HAVE_FLAG_STD_GNUXX14)
set(CMAKE_CXX_EXTENSIONS YES)
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS YES)
endif()
# Common configuration for GCC, clang and Intel. # Common configuration for GCC, clang and Intel.
if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_INTEL OR CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_INTEL OR CMAKE_CXX_COMPILER_IS_GCC)
if(CMLIB_WARNING_FLAGS AND CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMLIB_WARNING_FLAGS AND CMAKE_BUILD_TYPE STREQUAL "Debug")