From cb915085ea5e9b1653edd19f0c1cab51bd329150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 31 Mar 2023 10:37:53 +0200 Subject: [PATCH] use C++17 when building with Visual Studio in CMake - fixes GUI CI builds (#4924) * use C++17 when building with Visual Studio in CMake * printInfo.cmake: print more variables * CMakeLists.txt: set C++ standard earlier --- CMakeLists.txt | 5 +++-- cmake/compileroptions.cmake | 2 +- cmake/cxx11.cmake | 7 ++++++- cmake/printInfo.cmake | 10 ++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93904832..0b76fbf81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 2.8.12) project(Cppcheck) +include(cmake/cxx11.cmake) +use_cxx11() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(GNUInstallDirs) @@ -13,13 +16,11 @@ include(cmake/findDependencies.cmake) include(cmake/compileroptions.cmake) include(cmake/compilerDefinitions.cmake) include(cmake/buildFiles.cmake) -include(cmake/cxx11.cmake) include(cmake/printInfo.cmake) if(BUILD_GUI) include(cmake/qtCompat.cmake) endif() -use_cxx11() file(GLOB addons "addons/*.py") file(GLOB cfgs "cfg/*.cfg") diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index fe3cb8fda..8ebf5da18 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -154,7 +154,7 @@ if (MSVC) # C/C++ - Language add_compile_options(/Zc:rvalueCast) # Enforce type conversion rules - add_compile_options(/std:c++14) # C++ Language Standard - ISO C++14 Standard + #add_compile_options(/std:c++14) # C++ Language Standard - ISO C++14 Standard # C/C++ - Browse Information # Enable Browse Information - No diff --git a/cmake/cxx11.cmake b/cmake/cxx11.cmake index b4692a7e1..37a038b4e 100644 --- a/cmake/cxx11.cmake +++ b/cmake/cxx11.cmake @@ -6,7 +6,12 @@ macro(use_cxx11) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif () else () - set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") + # some GitHub Action windows runners randomly fail with a complaint that Qt6 requires a C++17 compiler + if (MSVC) + set (CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use") + else () + set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") + endif() set (CMAKE_CXX_STANDARD_REQUIRED ON) if (POLICY CMP0025) cmake_policy(SET CMP0025 NEW) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 288319506..2a42d7d4d 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -1,9 +1,11 @@ message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------") message( STATUS ) +message( STATUS "CMake Version = ${CMAKE_VERSION}") message( STATUS "CMake Generator = ${CMAKE_GENERATOR}") message( STATUS "Compiler = ${CMAKE_CXX_COMPILER_ID}") message( STATUS "Compiler Version = ${CMAKE_CXX_COMPILER_VERSION}") message( STATUS "Build type = ${CMAKE_BUILD_TYPE}") +message( STATUS "CMake C++ Standard = ${CMAKE_CXX_STANDARD}") message( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" ) message( STATUS "CMAKE_DISABLE_PRECOMPILE_HEADERS = ${CMAKE_DISABLE_PRECOMPILE_HEADERS}" ) message( STATUS "C++ flags (General) = ${CMAKE_CXX_FLAGS}") @@ -12,10 +14,10 @@ message( STATUS "C++ flags (RelWithDebInfo) = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" message( STATUS "C++ flags (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}") message( STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") message( STATUS "CPPCHK_GLIBCXX_DEBUG = ${CPPCHK_GLIBCXX_DEBUG}" ) -get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) -foreach( d ${DirDefs} ) - message( STATUS "Found Define: " ${d} ) -endforeach() +get_directory_property( DirCompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) +message( STATUS "COMPILE_DEFINITIONS (global) = ${DirCompileDefs}" ) +get_directory_property( DirCompileOptions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_OPTIONS ) +message( STATUS "COMPILE_OPTIONS (global) = ${DirCompileOptions}" ) message( STATUS ) message( STATUS "---------------------------------------------------------" ) message( STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}" )