Repository navigation
Expand file tree
/
Copy pathccache.cmake
More file actions
54 lines (51 loc) · 1.93 KB
/
Copy pathccache.cmake
File metadata and controls
54 lines (51 loc) · 1.93 KB
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
if(NOT UNIX)
return()
endif()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
# Set up wrapper scripts
set(C_LAUNCHER "${CCACHE_PROGRAM}")
set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
file(WRITE "${CMAKE_BINARY_DIR}/launch-c"
"#!/usr/bin/env sh\n"
"# Xcode generator doesn't include the compiler as the\n"
"# first argument, Ninja and Makefiles do. Handle both cases.\n"
"if [ \"$1\" = \"${CMAKE_C_COMPILER}\" ]; then\n"
" shift\n"
"fi\n"
"export CCACHE_CPP2=true\n"
"exec \"${C_LAUNCHER}\" \"${CMAKE_C_COMPILER}\" \"$@\"\n"
)
file(WRITE "${CMAKE_BINARY_DIR}/launch-cxx"
"#!/usr/bin/env sh\n"
"# Xcode generator doesn't include the compiler as the\n"
"# first argument, Ninja and Makefiles do. Handle both cases.\n"
"if [ \"$1\" = \"${CMAKE_CXX_COMPILER}\" ]; then\n"
" shift\n"
"fi\n"
"export CCACHE_CPP2=true\n"
"exec \"${CXX_LAUNCHER}\" \"${CMAKE_CXX_COMPILER}\" \"$@\"\n"
)
file(CHMOD
"${CMAKE_BINARY_DIR}/launch-c"
"${CMAKE_BINARY_DIR}/launch-cxx"
FILE_PERMISSIONS
OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
if(CMAKE_GENERATOR STREQUAL "Xcode")
# Set Xcode project attributes to route compilation and linking
# through our scripts
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx")
else()
# Support Unix Makefiles and Ninja
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx")
endif()
message(STATUS "CCache enabled")
else()
message(WARNING "CCache disabled")
endif()