Skip to content

Commit f5ecead

Browse files
committed
modernized and cleaned up CMake files / explicitly check for CMake 3.13 with Visual Studio [skip ci]
1 parent 8261ded commit f5ecead

File tree

10 files changed

+26
-40
lines changed

10 files changed

+26
-40
lines changed

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
cmake_minimum_required(VERSION 2.8.12)
2-
project(Cppcheck)
1+
cmake_minimum_required(VERSION 3.5)
2+
if (MSVC)
3+
cmake_minimum_required(VERSION 3.13)
4+
endif()
5+
cmake_policy(SET CMP0048 NEW) # allow VERSION in project()
6+
project(Cppcheck VERSION 2.13.99 LANGUAGES CXX)
37

48
include(cmake/cxx11.cmake)
59
use_cxx11()
10+
set (CMAKE_CXX_STANDARD_REQUIRED ON)
611

712
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
813

914
include(GNUInstallDirs)
1015

11-
include(cmake/ccache.cmake)
1216
include(cmake/compilerCheck.cmake)
1317
include(cmake/versions.cmake)
1418
include(cmake/options.cmake)

cmake/ccache.cmake

Lines changed: 0 additions & 7 deletions
This file was deleted.

cmake/compilerDefinitions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
if (MSVC)
2+
# add_compile_definitions() requires CMake 3.12
3+
24
# Visual Studio only sets _DEBUG
35
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
46

cmake/compileroptions.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
8585

8686
if (USE_LIBCXX)
8787
add_compile_options(-stdlib=libc++)
88-
add_link_options(-lc++)
88+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++")
8989
endif()
9090

9191
# TODO: fix and enable these warnings - or move to suppression list below
@@ -133,6 +133,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
133133
endif()
134134

135135
if (MSVC)
136+
# add_link_options() requires CMake 3.13
137+
136138
# General
137139
add_compile_options(/W4) # Warning Level
138140
add_compile_options(/Zi) # Debug Information Format - Program Database

cmake/cxx11.cmake

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
macro(use_cxx11)
2-
if (CMAKE_VERSION VERSION_LESS "3.1")
3-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
4-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
5-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
6-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
7-
endif ()
2+
# some GitHub Action Windows runners randomly fail with a complaint that Qt6 requires a C++17 compiler
3+
if (MSVC AND USE_QT6)
4+
# CMAKE_CXX_STANDARD 17 was added in CMake 3.8
5+
set (CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use")
86
else ()
9-
# some GitHub Action windows runners randomly fail with a complaint that Qt6 requires a C++17 compiler
10-
if (MSVC)
11-
set (CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use")
12-
else ()
13-
set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
14-
endif()
15-
set (CMAKE_CXX_STANDARD_REQUIRED ON)
16-
if (POLICY CMP0025)
17-
cmake_policy(SET CMP0025 NEW)
18-
endif ()
19-
endif ()
7+
set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
8+
endif()
209
endmacro(use_cxx11)

cmake/options.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ else()
7272
set(CMAKE_DISABLE_PRECOMPILE_HEADERS On CACHE BOOL "Disable precompiled headers")
7373
endif()
7474

75+
if (BUILD_TESTS AND REGISTER_TESTS AND CMAKE_VERSION VERSION_LESS "3.9")
76+
message(FATAL_ERROR "Registering tests with CTest requires at least CMake 3.9. Use REGISTER_TESTS=OFF to disable this.")
77+
endif()
78+
7579
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Output directory for headers")
7680
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "Output directory for libraries")
7781

cmake/printInfo.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------")
1+
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${PROJECT_VERSION} -----------------")
22
message( STATUS )
33
message( STATUS "CMake Version = ${CMAKE_VERSION}")
44
message( STATUS "CMake Generator = ${CMAKE_GENERATOR}")

cmake/versions.cmake

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Version for libraries CPP
22
# Version string must have 3 "parts". https://sourceforge.net/p/cppcheck/discussion/development/thread/e57efb2b62/
3-
SET(VERSION "2.12.99")
4-
STRING(REGEX MATCHALL "[0-9]+" VERSION_PARTS "${VERSION}")
5-
LIST(GET VERSION_PARTS 0 VERSION_MAJOR)
6-
LIST(GET VERSION_PARTS 1 VERSION_MINOR)
7-
LIST(GET VERSION_PARTS 2 VERSION_PATCH)
8-
SET(SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
3+
SET(SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
94

105
# Postfix of so's:
116
SET(DLLVERSION "")

releasenotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Deprecations:
1717

1818
Other:
1919
- Added CMake option 'EXTERNALS_AS_SYSTEM' to treat external includes as 'SYSTEM' ones.
20+
- 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.

test/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ if (BUILD_TESTS)
6060
endif()
6161

6262
if (REGISTER_TESTS)
63-
# CMP0064 requires 3.4
64-
# CMAKE_MATCH_<n> usage for if (MATCHES) requires 3.9
65-
cmake_minimum_required(VERSION 3.9)
66-
cmake_policy(SET CMP0064 NEW)
67-
cmake_policy(SET CMP0057 NEW)
63+
# CMAKE_MATCH_<n> usage for if (MATCHES) requires CMake 3.9
6864

6965
find_package(Threads REQUIRED)
7066
include(ProcessorCount)

0 commit comments

Comments
 (0)