From 6566e853cdc374c66bf9eba5ae09c860cf605312 Mon Sep 17 00:00:00 2001 From: Anthony Donlon <4056887+donlon@users.noreply.github.com> Date: Fri, 10 Nov 2023 02:05:36 +0000 Subject: [PATCH] Support ccache when compiling Verilator with CMake (#4678) --- CMakeLists.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f21ee2782..0041e6d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,27 @@ if (WIN32) set(CMAKE_CXX_STANDARD 20) endif() +set(OBJCACHE "" CACHE STRING "Path for ccache, auto-detected if empty") +option(OBJCACHE_ENABLED "Compile Verilator with ccache" ON) + +if (OBJCACHE_ENABLED) + if (OBJCACHE STREQUAL "") + find_program(OBJCACHE_PATH ccache) + if (OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND") + set(OBJCACHE_PATH "") + endif() + else() + set(OBJCACHE_PATH "${OBJCACHE}") + endif() + if (NOT OBJCACHE_PATH STREQUAL "") + execute_process(COMMAND "${OBJCACHE_PATH}" --version + OUTPUT_VARIABLE objcache_version) + string(REGEX MATCH "[^\n\r]+" objcache_version "${objcache_version}") + message(STATUS "Found ccache: ${OBJCACHE_PATH} (\"${objcache_version}\")") + set(CMAKE_CXX_COMPILER_LAUNCHER "${OBJCACHE_PATH}") + endif() +endif() + find_package(BISON) find_package(FLEX)