Skip to content

Commit

Permalink
modernized and cleaned up CMake files / explicitly check for CMake 3.…
Browse files Browse the repository at this point in the history
…13 with Visual Studio [skip ci]
  • Loading branch information
firewave committed Jan 4, 2024
1 parent 8261ded commit ae554e2
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 40 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
cmake_minimum_required(VERSION 2.8.12)
project(Cppcheck)
cmake_minimum_required(VERSION 3.5)
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)
Expand Down
7 changes: 0 additions & 7 deletions cmake/ccache.cmake

This file was deleted.

2 changes: 2 additions & 0 deletions cmake/compilerDefinitions.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
if (MSVC)
# add_compile_definitions() requires CMake 3.12

# Visual Studio only sets _DEBUG
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)

Expand Down
4 changes: 3 additions & 1 deletion cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 6 additions & 17 deletions cmake/cxx11.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
# 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 ()
# 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)
endif ()
endif ()
set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
endif()
endmacro(use_cxx11)
4 changes: 4 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ else()
set(CMAKE_DISABLE_PRECOMPILE_HEADERS On CACHE BOOL "Disable precompiled headers")
endif()

if (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")

Expand Down
2 changes: 1 addition & 1 deletion cmake/printInfo.cmake
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
7 changes: 1 addition & 6 deletions cmake/versions.cmake
Original file line number Diff line number Diff line change
@@ -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.12.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 "")
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Deprecations:

Other:
- Added CMake option 'EXTERNALS_AS_SYSTEM' to treat external includes as 'SYSTEM' ones.
- 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.
6 changes: 1 addition & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ if (BUILD_TESTS)
endif()

if (REGISTER_TESTS)
# CMP0064 requires 3.4
# 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)
Expand Down

0 comments on commit ae554e2

Please sign in to comment.