-cmake_minimum_required(VERSION 3.4.3)
+cmake_minimum_required(VERSION 3.15)
-project(ccache LANGUAGES C CXX ASM)
+project(ccache LANGUAGES C CXX ASM ASM_MASM)
+if(MSVC)
+ enable_language(ASM_MASM)
+else()
+ enable_language(ASM)
+endif()
set(CMAKE_PROJECT_DESCRIPTION "a fast C/C++ compiler cache")
-if(NOT "${CMAKE_CXX_STANDARD}")
- set(CMAKE_CXX_STANDARD 11)
-endif()
+set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
# C++ error messages)
#
-# Clang 3.4 and AppleClang 6.0 fail to compile doctest.
-# GCC 4.8.4 is known to work OK but give warnings.
-if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
- OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.4)
+if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
message(
FATAL_ERROR
"You need one listed here: https://ccache.dev/platform-compiler-language-support.html")
endif()
-# All Clang problems / special handling ccache has are because of version 3.5.
-# All GCC problems / special handling ccache has are because of version 4.8.4.
-if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
- OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
+if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4)
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6))
message(
WARNING
"The compiler you are using is rather old.\n"
#
# Settings
#
-include(StandardSettings)
-include(StandardWarnings)
-include(CIBuildType)
-include(DefaultBuildType)
+include(CcacheVersion)
-if(NOT ${CMAKE_VERSION} VERSION_LESS "3.9")
- cmake_policy(SET CMP0069 NEW)
- option(ENABLE_IPO "Enable interprocedural (link time, LTO) optimization" OFF)
- if(ENABLE_IPO)
- set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
+if(NOT DEFINED CCACHE_DEV_MODE)
+ if("${CCACHE_VERSION_ORIGIN}" STREQUAL git OR DEFINED ENV{CI})
+ set(CCACHE_DEV_MODE ON)
+ else()
+ set(CCACHE_DEV_MODE OFF)
endif()
endif()
+message(STATUS "Ccache dev mode: ${CCACHE_DEV_MODE}")
+
+option(ENABLE_IPO "Enable interprocedural (link time, LTO) optimization" OFF)
+if(ENABLE_IPO AND NOT MINGW)
+ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
+endif()
+
+include(CIBuildType)
+include(DefaultBuildType)
+include(UseFastestLinker)
+include(StandardSettings)
+include(StandardWarnings)
#
# Configuration
#
-include(GNUInstallDirs)
+
+include(InstallDirs)
include(GenerateConfigurationFile)
include(GenerateVersionFile)
-if(HAVE_SYS_MMAN_H)
- set(INODE_CACHE_SUPPORTED 1)
+#
+# Static link configuration
+#
+
+set(STATIC_LINK_DEFAULT OFF)
+if(WIN32)
+ set(STATIC_LINK_DEFAULT ON)
+endif()
+
+option(STATIC_LINK "Prefer linking libraries statically" ${STATIC_LINK_DEFAULT})
+
+if(STATIC_LINK)
+ list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ set(CMAKE_LINK_SEARCH_START_STATIC ON)
+
+ # Link MSVC runtime statically.
+ if(MSVC)
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+ # Link MINGW runtime statically.
+ elseif(WIN32)
+ if((CMAKE_CXX_COMPILER_ID STREQUAL GNU) OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang))
+ list(APPEND CCACHE_EXTRA_LIBS -static-libgcc -static-libstdc++ -static -lwinpthread -dynamic)
+ endif()
+ if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
+ list(APPEND CCACHE_EXTRA_LIBS -fuse-ld=lld)
+ endif()
+ endif()
endif()
#
# Third party
#
-set(ZSTD_FROM_INTERNET_DEFAULT OFF)
+set(ZSTD_FROM_INTERNET AUTO CACHE STRING "Download and use libzstd from the Internet")
+set_property(CACHE ZSTD_FROM_INTERNET PROPERTY STRINGS AUTO ON OFF)
-# Default to downloading deps for Visual Studio, unless using a package manager.
-if(MSVC AND NOT CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg|conan")
- set(ZSTD_FROM_INTERNET_DEFAULT ON)
-endif()
+set(HIREDIS_FROM_INTERNET AUTO CACHE STRING "Download and use libhiredis from the Internet")
+set_property(CACHE HIREDIS_FROM_INTERNET PROPERTY STRINGS AUTO ON OFF)
-option(ZSTD_FROM_INTERNET "Download and use libzstd from the Internet" ${ZSTD_FROM_INTERNET_DEFAULT})
-find_package(zstd 1.1.2 REQUIRED)
+find_package(zstd 1.1.2 MODULE REQUIRED)
+
+option(REDIS_STORAGE_BACKEND "Enable Redis remote storage" ON)
+
+if(REDIS_STORAGE_BACKEND)
+ find_package(hiredis 0.13.3 MODULE REQUIRED)
+endif()
#
# Special flags
include(CodeAnalysis)
option(ENABLE_TRACING "Enable possibility to use internal ccache tracing" OFF)
-if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
- option(STATIC_LINK "Link statically with system libraries" OFF)
-endif()
-
#
# Source code
#
# ccache executable
#
add_executable(ccache src/main.cpp)
-target_link_libraries(ccache PRIVATE standard_settings standard_warnings ccache_lib)
+target_link_libraries(ccache PRIVATE standard_settings standard_warnings ccache_framework)
#
# Documentation
#
-add_subdirectory(doc)
+option(ENABLE_DOCUMENTATION "Enable documentation" ON)
+if(ENABLE_DOCUMENTATION)
+ add_subdirectory(doc)
+endif()
#
# Installation
#
# Special formatting targets
#
-find_program(
- CLANG_FORMAT_EXE
- NAMES "clang-format"
- DOC "Path to clang-format executable.")
-mark_as_advanced(CLANG_FORMAT_EXE) # Don't show in CMake UIs
-
-if(NOT CLANG_FORMAT_EXE)
- message(STATUS "clang-format not found")
-else()
- add_custom_target(
- format
- COMMAND misc/format-files --all
- COMMENT "Formatting code"
- USES_TERMINAL
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-
- add_custom_target(
- check_format
- COMMAND misc/format-files --all --check
- COMMENT "Checking code formatting"
- USES_TERMINAL
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-endif()
+add_custom_target(
+ format
+ COMMAND misc/format-files --all
+ COMMENT "Formatting code"
+ USES_TERMINAL
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_custom_target(
+ check_format
+ COMMAND misc/format-files --all --check
+ COMMENT "Checking code formatting"
+ USES_TERMINAL
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})