From: Vesa-Pekka Palmu Date: Sun, 20 Nov 2022 18:23:40 +0000 (+0200) Subject: CMakeLists.txt: Enable use of C++17 on Apple systems X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c303f96d9125f36715340a1ce31643dde86d263a;p=pulseview.git CMakeLists.txt: Enable use of C++17 on Apple systems The stdlib on OSX 12 Monteray requires C++17 to compile. This change tests for and conditionally enables C++17 support on Apple devices. Other platforms remain unaffected. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d5469883..b12f50c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,12 +75,15 @@ add_subdirectory(manual) #------------------------------------------------------------------------------- include(CheckCSourceCompiles) +include(CheckCXXCompilerFlag) include(CheckCXXSourceCompiles) include(CMakePushCheckState) include(memaccess) find_package(PkgConfig) +check_cxx_compiler_flag("-std=c++17" PV_HAVE_C++17) + list(APPEND PKGDEPS glib-2.0>=2.28.0) # Try to find the prefered glibmm-2.4. If not found then add glibmm-2.68 @@ -166,7 +169,13 @@ find_package(Threads REQUIRED) # Helper for checking for atomics function(check_working_cxx_atomics varname additional_lib) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "-std=c++11") + # The OSX 12 (Monteray) stdlib requires C++17 to compile. + if(APPLE AND PV_HAVE_C++17) + message(STATUS "Using C++17 for OSX build") + set(CMAKE_REQUIRED_FLAGS "-std=c++17") + else() + set(CMAKE_REQUIRED_FLAGS "-std=c++11") + endif() set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}") set(CMAKE_REQUIRED_QUIET 1) CHECK_CXX_SOURCE_COMPILES(" @@ -499,7 +508,14 @@ qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc) add_definitions(-DQT_NO_KEYWORDS) add_definitions(-D__STDC_LIMIT_MACROS) add_definitions(-Wall -Wextra) -add_definitions(-std=c++11) + +# The OSX 12 Monteray stdlib requires C++17 to compile. +if(APPLE AND PV_HAVE_C++17) + add_definitions(-std=c++17) +else() + add_definitions(-std=c++11) +endif() + add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1) if(WIN32) add_definitions(-Wa,-mbig-obj -O3)