-
Notifications
You must be signed in to change notification settings - Fork 77
/
CompilerCaching.cmake
70 lines (65 loc) · 2.96 KB
/
CompilerCaching.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# SPDX-FileCopyrightText: 2021 Tenacity Audio Editor contributors
# SPDX-FileContributor: Be <be.0@gmx.com>
# SPDX-FileContributor: Emily Mabrey <emabrey@tenacityaudio.org>
# SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
CompilerCaching
---------------
Search for sccache and ccache and use them for compiler caching for C & C++.
sccache is preferred if both are found, but the user can override this by
explicitly setting SCCACHE=OFF to use ccache when both are installed.
#]=======================================================================]
# ccache does not support MSVC
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
find_program(CCACHE_PROGRAM ccache)
mark_as_advanced(FORCE CCACHE_PROGRAM)
if("${CCACHE_PROGRAM}" STREQUAL "CCACHE_PROGRAM-NOTFOUND")
message(STATUS "Could NOT find ccache")
else()
message(STATUS "Found ccache: ${CCACHE_PROGRAM}")
option(CCACHE "Use ccache for compiler caching to speed up rebuilds." ON)
endif()
endif()
find_program(SCCACHE_PROGRAM sccache)
mark_as_advanced(FORCE SCCACHE_PROGRAM)
if("${SCCACHE_PROGRAM}" STREQUAL "SCCACHE_PROGRAM-NOTFOUND")
message(STATUS "Could NOT find sccache")
else()
message(STATUS "Found sccache: ${SCCACHE_PROGRAM}")
option(SCCACHE "Use sccache for compiler caching to speed up rebuilds." ON)
endif()
if(SCCACHE)
message(STATUS "Using sccache for compiler caching to speed up rebuilds")
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
if (NOT DEFINED ENV{RUSTC_WRAPPER})
# Enable sccache for rustc - especially important when building cxx-qt-lib!
set(CMAKE_RUSTC_WRAPPER "${SCCACHE_PROGRAM}" CACHE PATH "RUSTC_WRAPPER detected by CMake")
endif()
# Instruct MSVC to generate symbolic debug information within object files for sccache
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(IS_MULTI_CONFIG)
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${CONFIG}" CONFIG)
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_${CONFIG} "${CMAKE_CXX_FLAGS_${CONFIG}}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${CONFIG} "${CMAKE_C_FLAGS_${CONFIG}}")
endforeach()
else()
string(TOUPPER "${CMAKE_BUILD_TYPE}" CONFIG)
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_${CONFIG} "${CMAKE_CXX_FLAGS_${CONFIG}}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${CONFIG} "${CMAKE_C_FLAGS_${CONFIG}}")
endif()
endif()
elseif(CCACHE)
message(STATUS "Using ccache for compiler caching to speed up rebuilds")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "No compiler caching enabled. Install sccache to speed up rebuilds.")
else()
message(STATUS "No compiler caching enabled. Install ccache or sccache to speed up rebuilds.")
endif()
endif()