modernized and cleaned up CMake files / explicitly check for CMake 3.13 with Visual Studio (#5825)

This commit is contained in:
Oliver Stöneberg 2024-01-05 11:07:16 +01:00 committed by GitHub
parent fc1d4d6f7d
commit 93a53af168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 40 deletions

View File

@ -1,14 +1,18 @@
cmake_minimum_required(VERSION 3.5)
project(Cppcheck)
if (MSVC)
cmake_minimum_required(VERSION 3.13)
endif()
cmake_policy(SET CMP0048 NEW) # allow VERSION in project()
project(Cppcheck VERSION 2.13.99 LANGUAGES CXX)
include(cmake/cxx11.cmake)
use_cxx11()
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs)
include(cmake/ccache.cmake)
include(cmake/compilerCheck.cmake)
include(cmake/versions.cmake)
include(cmake/options.cmake)

View File

@ -1,7 +0,0 @@
if (CMAKE_VERSION VERSION_LESS "3.0")
if (CMAKE_CXX_COMPILER_LAUNCHER)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_CXX_COMPILER_LAUNCHER}")
elseif (CMAKE_C_COMPILER_LAUNCHER)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_C_COMPILER_LAUNCHER}")
endif()
endif()

View File

@ -1,4 +1,6 @@
if (MSVC)
# add_compile_definitions() requires CMake 3.12
# Visual Studio only sets _DEBUG
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)

View File

@ -85,7 +85,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (USE_LIBCXX)
add_compile_options(-stdlib=libc++)
add_link_options(-lc++)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++")
endif()
# TODO: fix and enable these warnings - or move to suppression list below
@ -133,6 +133,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()
if (MSVC)
# add_link_options() requires CMake 3.13
# General
add_compile_options(/W4) # Warning Level
add_compile_options(/Zi) # Debug Information Format - Program Database

View File

@ -1,20 +1,9 @@
macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()
else ()
# some GitHub Action windows runners randomly fail with a complaint that Qt6 requires a C++17 compiler
if (MSVC)
# some GitHub Action Windows runners randomly fail with a complaint that Qt6 requires a C++17 compiler
if (MSVC AND USE_QT6)
# CMAKE_CXX_STANDARD 17 was added in CMake 3.8
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)
endif ()
endif ()
endmacro(use_cxx11)

View File

@ -72,6 +72,10 @@ else()
set(CMAKE_DISABLE_PRECOMPILE_HEADERS On CACHE BOOL "Disable precompiled headers")
endif()
if (BUILD_TESTS AND REGISTER_TESTS AND CMAKE_VERSION VERSION_LESS "3.9")
message(FATAL_ERROR "Registering tests with CTest requires at least CMake 3.9. Use REGISTER_TESTS=OFF to disable this.")
endif()
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Output directory for headers")
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "Output directory for libraries")

View File

@ -1,4 +1,4 @@
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------")
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${PROJECT_VERSION} -----------------")
message( STATUS )
message( STATUS "CMake Version = ${CMAKE_VERSION}")
message( STATUS "CMake Generator = ${CMAKE_GENERATOR}")

View File

@ -1,11 +1,6 @@
# Version for libraries CPP
# Version string must have 3 "parts". https://sourceforge.net/p/cppcheck/discussion/development/thread/e57efb2b62/
SET(VERSION "2.13.99")
STRING(REGEX MATCHALL "[0-9]+" VERSION_PARTS "${VERSION}")
LIST(GET VERSION_PARTS 0 VERSION_MAJOR)
LIST(GET VERSION_PARTS 1 VERSION_MINOR)
LIST(GET VERSION_PARTS 2 VERSION_PATCH)
SET(SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
SET(SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# Postfix of so's:
SET(DLLVERSION "")

View File

@ -19,3 +19,4 @@ Other:
- Added CMake option 'EXTERNALS_AS_SYSTEM' to treat external includes as 'SYSTEM' ones.
- The minimum required compiler versions have been bumped to GCC 5.1 / Clang 3.5 / Visual Studio 2015
- The minimum required CMake version has been bumped to 3.5
- Using Visual Studio with CMake now checks if the CMake version is at least 3.13. This was always required but was not checked explicitly.

View File

@ -60,12 +60,7 @@ if (BUILD_TESTS)
endif()
if (REGISTER_TESTS)
# CMP0057 requires 3.3 - if (IN_LIST)
# CMP0064 requires 3.4 - if (TEST)
# CMAKE_MATCH_<n> usage for if (MATCHES) requires 3.9
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0064 NEW)
cmake_policy(SET CMP0057 NEW)
# CMAKE_MATCH_<n> usage for if (MATCHES) requires CMake 3.9
find_package(Threads REQUIRED)
include(ProcessorCount)