Skip to content

Commit df8d64f

Browse files
ppenzinrhuanjl
authored andcommitted
[CMake] Refactor ccache build option
Allow enabling ccache from bare CMake build and make sure both ways do the same thing.
1 parent 622c745 commit df8d64f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

CMakeLists.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
66
# Disable expected CMake workflow
77
option(CHAKRACORE_BUILD_SH "Use build.sh")
88

9+
set(CCACHE_PROGRAM_NAME_DEFAULT "ccache")
10+
911
if(NOT CHAKRACORE_BUILD_SH)
1012
option(DISABLE_JIT "Disable JIT compilation" OFF)
1113
option(INTL_ICU "Enable Intl" ON)
1214
option(EMBED_ICU "Build ICU within ChakraCore build" OFF)
15+
option(USE_CCACHE "Build using ccache" OFF)
16+
set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_DEFAULT} CACHE
17+
STRING "ccache executable")
1318
set(ICU_INCLUDE_PATH "" CACHE STRING "libicu iclude path")
1419
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1520
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type" FORCE)
@@ -80,13 +85,21 @@ unset(CC_TARGETS_ARM_SH CACHE)
8085
unset(CC_TARGETS_X86_SH CACHE)
8186
unset(CC_TARGETS_AMD64_SH CACHE)
8287

83-
if(CCACHE_PROGRAM_NAME_SH)
84-
find_program(CCACHE_PROGRAM ${CCACHE_PROGRAM_NAME_SH})
85-
if (CCACHE_PROGRAM)
86-
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
87-
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
88-
endif()
89-
unset(CCACHE_PROGRAM_NAME_SH CACHE)
88+
if (CHAKRACORE_BUILD_SH)
89+
if(CCACHE_PROGRAM_NAME_SH)
90+
set(USE_CCACHE ON)
91+
set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_SH})
92+
unset(CCACHE_PROGRAM_NAME_SH CACHE)
93+
else()
94+
set(USE_CCACHE OFF)
95+
set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_DEFAULT})
96+
endif()
97+
endif()
98+
99+
if(USE_CCACHE)
100+
find_program(CCACHE_PROGRAM ${CCACHE_PROGRAM_NAME} REQUIRED)
101+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
102+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
90103
endif()
91104

92105
if(ENABLE_VALGRIND_SH)

0 commit comments

Comments
 (0)