Skip to content

Commit 7908507

Browse files
committed
[CMake] Refactor ccache build option
Allow enabling ccache from bare CMake build and make sure both ways do the same thing.
1 parent 03f16a2 commit 7908507

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)
@@ -81,13 +86,21 @@ unset(CC_TARGETS_ARM_SH CACHE)
8186
unset(CC_TARGETS_X86_SH CACHE)
8287
unset(CC_TARGETS_AMD64_SH CACHE)
8388

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

93106
if(ENABLE_VALGRIND_SH)

0 commit comments

Comments
 (0)