diff --git a/CMakeLists.txt b/CMakeLists.txt index c4deaee89..6b70ad14f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake deleted file mode 100644 index 73ad5a189..000000000 --- a/cmake/ccache.cmake +++ /dev/null @@ -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() \ No newline at end of file diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index ecf9bf2dd..7369554e9 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -1,4 +1,6 @@ if (MSVC) + # add_compile_definitions() requires CMake 3.12 + # Visual Studio only sets _DEBUG add_compile_definitions($<$:DEBUG>) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 23c51be4f..e0a4011ca 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -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 diff --git a/cmake/cxx11.cmake b/cmake/cxx11.cmake index 37a038b4e..40891aae4 100644 --- a/cmake/cxx11.cmake +++ b/cmake/cxx11.cmake @@ -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) diff --git a/cmake/options.cmake b/cmake/options.cmake index 8083532d0..fe9bcf252 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -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") diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 3ccc78db5..e21ec8a6d 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -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}") diff --git a/cmake/versions.cmake b/cmake/versions.cmake index 8d307012f..3ff979ecb 100644 --- a/cmake/versions.cmake +++ b/cmake/versions.cmake @@ -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 "") diff --git a/releasenotes.txt b/releasenotes.txt index 29c5ac502..d6dd91249 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -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. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b4db4be9e..9e560e101 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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_ 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_ usage for if (MATCHES) requires CMake 3.9 find_package(Threads REQUIRED) include(ProcessorCount)