[libcxx-commits] [libcxx] [libcxxabi] Added support ccache for speedup recompilation libcxx and libcxxabi (PR #78470)
Herman Semenov via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 17 08:43:59 PST 2024
https://github.com/GermanAizek created https://github.com/llvm/llvm-project/pull/78470
It will save a lot of time when checkout git branches and compile again.
>From 76e721248096e1191a628dbaac6ad4cb71232125 Mon Sep 17 00:00:00 2001
From: Herman Semenov <GermanAizek at yandex.ru>
Date: Wed, 17 Jan 2024 19:42:15 +0300
Subject: [PATCH] Added support ccache for speedup recompilation libcxx and
libcxxabi
---
libcxx/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++
libcxxabi/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index d0abd8413f1b2b..cdb1ae5cb144f3 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -599,6 +599,40 @@ endfunction()
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
+# Build libcxx with ccache if the package is present
+set(LIBCXX_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
+if(LIBCXX_CCACHE_BUILD)
+ find_program(CCACHE_PROGRAM ccache)
+ if(CCACHE_PROGRAM)
+ set(LIBCXX_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
+ set(LIBCXX_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
+ set(LIBCXX_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
+ CACHE STRING "Parameters to pass through to ccache")
+
+ if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(CCACHE_PROGRAM "${LIBCXX_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
+ if (LIBCXX_CCACHE_MAXSIZE)
+ set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LIBCXX_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
+ endif()
+ if (LIBCXX_CCACHE_DIR)
+ set(CCACHE_PROGRAM "CCACHE_DIR=${LIBCXX_CCACHE_DIR} ${CCACHE_PROGRAM}")
+ endif()
+ set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
+ else()
+ if(LIBCXX_CCACHE_MAXSIZE OR LIBCXX_CCACHE_DIR OR
+ NOT LIBCXX_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
+ message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
+ endif()
+ # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
+ # with cmd.exe and some MSVC tools other than cl.exe
+ set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
+ set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
+ endif()
+ else()
+ message(FATAL_ERROR "Unable to find the program ccache. Set LIBCXX_CCACHE_BUILD to OFF")
+ endif()
+endif()
+
# Sanitizer flags =============================================================
function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index da998d2221dc4f..b197f5c9f9716b 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -412,6 +412,40 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
add_definitions("-D_XOPEN_SOURCE=700")
endif()
+# Build libcxxabi with ccache if the package is present
+set(LIBCXXABI_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
+if(LIBCXXABI_CCACHE_BUILD)
+ find_program(CCACHE_PROGRAM ccache)
+ if(CCACHE_PROGRAM)
+ set(LIBCXXABI_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
+ set(LIBCXXABI_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
+ set(LIBCXXABI_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
+ CACHE STRING "Parameters to pass through to ccache")
+
+ if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(CCACHE_PROGRAM "${LIBCXXABI_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
+ if (LIBCXXABI_CCACHE_MAXSIZE)
+ set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LIBCXXABI_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
+ endif()
+ if (LIBCXXABI_CCACHE_DIR)
+ set(CCACHE_PROGRAM "CCACHE_DIR=${LIBCXXABI_CCACHE_DIR} ${CCACHE_PROGRAM}")
+ endif()
+ set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
+ else()
+ if(LIBCXXABI_CCACHE_MAXSIZE OR LIBCXXABI_CCACHE_DIR OR
+ NOT LIBCXXABI_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
+ message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
+ endif()
+ # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
+ # with cmd.exe and some MSVC tools other than cl.exe
+ set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
+ set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
+ endif()
+ else()
+ message(FATAL_ERROR "Unable to find the program ccache. Set LIBCXXABI_CCACHE_BUILD to OFF")
+ endif()
+endif()
+
#===============================================================================
# Setup Source Code
#===============================================================================
More information about the libcxx-commits
mailing list