From 45633f4a54f9d04d33406e97e48613066c072d81 Mon Sep 17 00:00:00 2001 From: David Adam Date: Sat, 21 Dec 2019 21:58:45 +0800 Subject: [PATCH] cmake: force C++11 in CHECK_CXX_SOURCE_COMPILES for atomic GCC 4.8 requires the use of `-std=gnu++11` or similar to enable atomic features. However, older versions of CMake don't pick up the project-wide target for C++11 when building the configure check targets. Although CMake policy 0067 could be set to NEW to enable this, it only exists on CMake 3.8 and newer, while many of our supported platforms are on an older version. --- cmake/ConfigureChecks.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 59d48140e601..901c743bab0b 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -189,6 +189,13 @@ int main () { FIND_PROGRAM(SED sed) # https://github.com/fish-shell/fish-shell/issues/5865 +CMAKE_PUSH_CHECK_STATE() +# Needed until CMP0067 is set to NEW +# g++ 4.8 needs -std=gnu+11 set to enable atomic features, but CMake < 3.8 does not add that +# flag to TRY_COMPILE targets even when set for the project +IF(CMAKE_COMPILER_IS_GNUCXX) + LIST(APPEND CMAKE_REQUIRED_FLAGS "-std=gnu++11") +ENDIF() CHECK_CXX_SOURCE_COMPILES(" #include #include @@ -200,3 +207,4 @@ LIBATOMIC_NOT_NEEDED) IF (NOT LIBATOMIC_NOT_NEEDED) SET(ATOMIC_LIBRARY "atomic") ENDIF() +CMAKE_POP_CHECK_STATE()