From 357918e276d5fbc97cbe148fe7ed3d4615155fdf Mon Sep 17 00:00:00 2001 From: Mattias Ellert Date: Tue, 24 Jan 2023 17:51:17 +0100 Subject: [PATCH] Don't downgrade the C++ version The cmake configuration adds a compiler flag to set the C++ version to C++11. This happens even if the default C++ version for the GCC compiler version used is higer than C++11. In this case the flag downgrades the version. Since system libraries and headers can use features compatible with the default C++ version of the default compiler, downgrading the C++ version might make some system libraries incompatible with this setting. The recent update of googletest in Fedora requires C++ 14. The gcc version in Fedora Rawhide is currently 13. C++ 17 is the default since GCC 11. C++ 14 is the default since GCC 6.1. This PR drops the addition of the -std=c++11 flag if the GCC version is 6.1 or greater. With this change the code can be compiled on Fedora Rawhide without triggering errors: /usr/include/gtest/internal/gtest-port.h:270:2: error: #error C++ versions less than C++14 are not supported. --- cmake/modules/CMakeCXX11Support.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmake/modules/CMakeCXX11Support.cmake b/cmake/modules/CMakeCXX11Support.cmake index cdde3f98..4b6edf25 100644 --- a/cmake/modules/CMakeCXX11Support.cmake +++ b/cmake/modules/CMakeCXX11Support.cmake @@ -3,10 +3,13 @@ include(CheckCXXSourceCompiles REQUIRED) if(CMAKE_COMPILER_IS_GNUCXX) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) + if(GCC_VERSION VERSION_GREATER 6.1 OR GCC_VERSION VERSION_EQUAL 6.1) SET(HAVE_CXX011_FULL_SUPPORT TRUE) SET(HAVE_CXX011_PARTIAL_SUPPORT TRUE) - SET(CXX11_FLAG_ENABLE "-std=c++11") + elseif(GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) + SET(HAVE_CXX011_FULL_SUPPORT TRUE) + SET(HAVE_CXX011_PARTIAL_SUPPORT TRUE) + SET(CXX11_FLAG_ENABLE "-std=c++11") elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) message(STATUS "C++11 partial support") SET(HAVE_CXX011_PARTIAL_SUPPORT TRUE)