CMake: add ccache option

Change-Id: I482b0f3ac372f141e465b72fbcca9d8b5c5b352d
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
David Schulz
2022-03-31 07:19:57 +02:00
parent 53a3504aac
commit ca7a18568c
3 changed files with 19 additions and 9 deletions

View File

@@ -24,7 +24,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
qtc_handle_sccache_support()
qtc_handle_compiler_cache_support()
option(BUILD_LINK_WITH_QT "Link with Qt from the parent Qt Creator" OFF)
qtc_link_with_qt()

View File

@@ -43,6 +43,7 @@ option(BUILD_LIBRARIES_BY_DEFAULT "Build libraries by default. This can be used
option(BUILD_TESTS_BY_DEFAULT "Build tests by default. This can be used to build all tests by default, or none." ON)
option(QTC_SEPARATE_DEBUG_INFO "Extract debug information from binary files." OFF)
option(WITH_SCCACHE_SUPPORT "Enables support for building with SCCACHE and separate debug info with MSVC, which SCCACHE normally doesn't support." OFF)
option(WITH_CCACHE_SUPPORT "Enables support for building with CCACHE and separate debug info with MSVC, which CCACHE normally doesn't support." OFF)
# If we provide a list of plugins, executables, libraries, then the BUILD_<type>_BY_DEFAULT will be set to OFF
# and for every element we set BUILD_<type>_<elment> to ON

View File

@@ -117,8 +117,9 @@ set(__QTC_TESTS "" CACHE INTERNAL "*** Internal ***")
# This increases memory usage, disk space usage and linking time, so should only be
# enabled if necessary.
# Must be called after project(...).
function(qtc_handle_sccache_support)
if (MSVC AND WITH_SCCACHE_SUPPORT)
function(qtc_handle_compiler_cache_support)
if (WITH_SCCACHE_SUPPORT OR WITH_CCACHE_SUPPORT)
if (MSVC)
foreach(config DEBUG RELWITHDEBINFO)
foreach(lang C CXX)
set(flags_var "CMAKE_${lang}_FLAGS_${config}")
@@ -127,6 +128,14 @@ function(qtc_handle_sccache_support)
endforeach()
endforeach()
endif()
endif()
if (WITH_CCACHE_SUPPORT)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "CXX compiler launcher" FORCE)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "C compiler launcher" FORCE)
endif()
endif()
endfunction()
function(qtc_link_with_qt)