From fca0c75b2e8500b3195d114ea09055a647fc0b26 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Jan 2024 03:45:59 +0100 Subject: [PATCH] Don't give an error if compiler supports C++17 by default Previously CMake would give an error if CMAKE_CXX_STANDARD wasn't explicitly set to C++17 or greater when using CEF, but this is not really needed if the compiler supports C++17 without any non-default options, so check for this too. --- build/cmake/init.cmake | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 040df05f4d..ca24b5b848 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -506,11 +506,36 @@ if(wxUSE_GUI) message(WARNING "WebviewChromium libcef_dll_wrapper can only be built with MSVC... disabled") wx_option_force_value(wxUSE_WEBVIEW_CHROMIUM OFF) endif() - if(wxUSE_WEBVIEW_CHROMIUM AND CMAKE_CXX_STANDARD LESS 17) - # We shouldn't disable this option as it's disabled by default and - # if it is on, it means that CEF is meant to be used, but we can't - # continue neither as libcef_dll_wrapper will fail to build. - message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") + if(wxUSE_WEBVIEW_CHROMIUM) + # Check for C++17 support as it's required by CEF: we trust + # CMAKE_CXX_STANDARD if it is defined, but we need to compile a + # test program if it is not because the compiler could be + # supporting C++17 anyway. + if (DEFINED CMAKE_CXX_STANDARD) + if (CMAKE_CXX_STANDARD GREATER_EQUAL 17) + set(wxHAVE_CXX17 ON) + endif() + else() + check_cxx_source_compiles(" + #if defined(_MSVC_LANG) + #if _MSVC_LANG < 201703L + #error C++17 support is required + #endif + #elif __cplusplus < 201703L + #error C++17 support is required + #endif + int main() { + [[maybe_unused]] auto unused = 17; + }" + wxHAVE_CXX17) + endif() + + if (NOT wxHAVE_CXX17) + # We shouldn't disable this option as it's disabled by default and + # if it is on, it means that CEF is meant to be used, but we can't + # continue neither as libcef_dll_wrapper will fail to build. + message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") + endif() endif() endif()