diff --git a/CMakeLists.txt b/CMakeLists.txt index d2359e6a21c..b11fceac713 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/QtCreatorAPI.cmake b/cmake/QtCreatorAPI.cmake index 0493fb95bc0..63a8717dca7 100644 --- a/cmake/QtCreatorAPI.cmake +++ b/cmake/QtCreatorAPI.cmake @@ -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__BY_DEFAULT will be set to OFF # and for every element we set BUILD__ to ON diff --git a/cmake/QtCreatorAPIInternal.cmake b/cmake/QtCreatorAPIInternal.cmake index 2278932a02b..8d370d1b94e 100644 --- a/cmake/QtCreatorAPIInternal.cmake +++ b/cmake/QtCreatorAPIInternal.cmake @@ -117,15 +117,24 @@ 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) - foreach(config DEBUG RELWITHDEBINFO) - foreach(lang C CXX) - set(flags_var "CMAKE_${lang}_FLAGS_${config}") - string(REPLACE "/Zi" "/Z7" ${flags_var} "${${flags_var}}") - set(${flags_var} "${${flags_var}}" PARENT_SCOPE) +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}") + string(REPLACE "/Zi" "/Z7" ${flags_var} "${${flags_var}}") + set(${flags_var} "${${flags_var}}" PARENT_SCOPE) + endforeach() 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()