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
This commit is contained in:
Oliver Stöneberg 2023-03-31 10:37:53 +02:00 committed by GitHub
parent 89ec148199
commit cb915085ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
project(Cppcheck) project(Cppcheck)
include(cmake/cxx11.cmake)
use_cxx11()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs) include(GNUInstallDirs)
@ -13,13 +16,11 @@ include(cmake/findDependencies.cmake)
include(cmake/compileroptions.cmake) include(cmake/compileroptions.cmake)
include(cmake/compilerDefinitions.cmake) include(cmake/compilerDefinitions.cmake)
include(cmake/buildFiles.cmake) include(cmake/buildFiles.cmake)
include(cmake/cxx11.cmake)
include(cmake/printInfo.cmake) include(cmake/printInfo.cmake)
if(BUILD_GUI) if(BUILD_GUI)
include(cmake/qtCompat.cmake) include(cmake/qtCompat.cmake)
endif() endif()
use_cxx11()
file(GLOB addons "addons/*.py") file(GLOB addons "addons/*.py")
file(GLOB cfgs "cfg/*.cfg") file(GLOB cfgs "cfg/*.cfg")

View File

@ -154,7 +154,7 @@ if (MSVC)
# C/C++ - Language # C/C++ - Language
add_compile_options(/Zc:rvalueCast) # Enforce type conversion rules 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 # C/C++ - Browse Information
# Enable Browse Information - No # Enable Browse Information - No

View File

@ -6,7 +6,12 @@ macro(use_cxx11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif () endif ()
else () 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) set (CMAKE_CXX_STANDARD_REQUIRED ON)
if (POLICY CMP0025) if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW) cmake_policy(SET CMP0025 NEW)

View File

@ -1,9 +1,11 @@
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------") message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------")
message( STATUS ) message( STATUS )
message( STATUS "CMake Version = ${CMAKE_VERSION}")
message( STATUS "CMake Generator = ${CMAKE_GENERATOR}") message( STATUS "CMake Generator = ${CMAKE_GENERATOR}")
message( STATUS "Compiler = ${CMAKE_CXX_COMPILER_ID}") message( STATUS "Compiler = ${CMAKE_CXX_COMPILER_ID}")
message( STATUS "Compiler Version = ${CMAKE_CXX_COMPILER_VERSION}") message( STATUS "Compiler Version = ${CMAKE_CXX_COMPILER_VERSION}")
message( STATUS "Build type = ${CMAKE_BUILD_TYPE}") 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_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
message( STATUS "CMAKE_DISABLE_PRECOMPILE_HEADERS = ${CMAKE_DISABLE_PRECOMPILE_HEADERS}" ) message( STATUS "CMAKE_DISABLE_PRECOMPILE_HEADERS = ${CMAKE_DISABLE_PRECOMPILE_HEADERS}" )
message( STATUS "C++ flags (General) = ${CMAKE_CXX_FLAGS}") 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 "C++ flags (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}")
message( STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") message( STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message( STATUS "CPPCHK_GLIBCXX_DEBUG = ${CPPCHK_GLIBCXX_DEBUG}" ) message( STATUS "CPPCHK_GLIBCXX_DEBUG = ${CPPCHK_GLIBCXX_DEBUG}" )
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) get_directory_property( DirCompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} ) message( STATUS "COMPILE_DEFINITIONS (global) = ${DirCompileDefs}" )
message( STATUS "Found Define: " ${d} ) get_directory_property( DirCompileOptions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_OPTIONS )
endforeach() message( STATUS "COMPILE_OPTIONS (global) = ${DirCompileOptions}" )
message( STATUS ) message( STATUS )
message( STATUS "---------------------------------------------------------" ) message( STATUS "---------------------------------------------------------" )
message( STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}" ) message( STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}" )