Skip to content

Commit

Permalink
Don't downgrade the C++ version
Browse files Browse the repository at this point in the history
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.

The implementation and the preceding commit message text are by Mattias
Ellert, @ellert, copied from cern-fts/davix#103.
  • Loading branch information
musicinmybrain committed Jan 25, 2023
1 parent 11aec21 commit 887a3a7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmake/modules/CMakeCXX11Support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ 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)
SET(HAVE_CXX011_FULL_SUPPORT TRUE)
SET(HAVE_CXX011_PARTIAL_SUPPORT TRUE)
SET(CXX11_FLAG_ENABLE "-std=c++11")
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)
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)
SET(HAVE_CXX011_PARTIAL_SUPPORT TRUE)
SET(CXX11_FLAG_ENABLE "-std=c++0x")
else ()
message(STATUS "C++11 no support ")
Expand All @@ -22,7 +25,6 @@ else(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX11_FLAG_ENABLE "-std=c++0x")
endif(CMAKE_COMPILER_IS_GNUCXX)


## Check TR1
CHECK_CXX_SOURCE_COMPILES("
#include <tr1/functional>
Expand All @@ -34,4 +36,3 @@ message(STATUS "TR1 support detected")
else(HAVE_TR1_SUPPORT)
message(STATUS "no TR1 support")
endif(HAVE_TR1_SUPPORT)

0 comments on commit 887a3a7

Please sign in to comment.