cmake: tidy up adding C++11 compile flags

Two blocks of code were trying to do the same thing in different ways;
standardise on one, and only add the compile flags if CMake won't do it
itself (policy CMP0067).
This commit is contained in:
David Adam 2019-12-23 22:10:30 +08:00
parent 74ab9e72ac
commit 4d325dcd7a

View file

@ -181,7 +181,10 @@ CMAKE_POP_CHECK_STATE()
# the CHECK_CXX_SOURCE_COMPILES function. See CMake issue #16456.
# Ensure we do this after the FIND_PACKAGE calls which use C, and will error on a C++
# standards flag.
LIST(APPEND CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}")
# Also see https://github.com/fish-shell/fish-shell/issues/5865
IF(NOT POLICY CMP0067)
LIST(APPEND CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}")
ENDIF()
CHECK_CXX_SOURCE_COMPILES("
#include <memory>
@ -195,14 +198,6 @@ 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 <atomic>
#include <cstdint>
@ -214,4 +209,3 @@ LIBATOMIC_NOT_NEEDED)
IF (NOT LIBATOMIC_NOT_NEEDED)
SET(ATOMIC_LIBRARY "atomic")
ENDIF()
CMAKE_POP_CHECK_STATE()