* [Buildroot] [PATCH] core: allow host-cmake to be built with ccache
@ 2026-09-30 20:37 Thomas Devoogdt
0 siblings, 0 replies; only message in thread
From: Thomas Devoogdt @ 2026-09-30 20:37 UTC (permalink / raw)
To: buildroot; +Cc: Thomas Petazzoni, Thomas Devoogdt
host-cmake takes a long time to build, but it is never built with
ccache: host-ccache is a cmake package, so when no suitable cmake is
available on the build host, host-ccache depends on host-cmake, and
host-cmake cannot depend on host-ccache.
However, the packages in the host-ccache dependency chain (ccache,
hiredis, blake3) only need cmake 3.18, while BR2_HOST_CMAKE_AT_LEAST
may be much higher, e.g. 4.3 for mosquitto. So a cmake from the build
host is often suitable to build host-ccache, even if it is not
suitable for the other packages.
Thus, when BR2_CCACHE is enabled, look for a separate cmake of at
least 3.18, exposed as BR2_CMAKE_NOCCACHE and
BR2_CMAKE_NOCCACHE_HOST_DEPENDENCY, and use it in pkg-cmake.mk for
all packages that set <PKG>_ADD_CCACHE_DEPENDENCY = NO, as those can
by definition not depend on a host-cmake built with ccache.
When that cmake is found on the build host, host-cmake depends on
host-ccache, and uses it for both the bootstrap (--enable-ccache) and
the main build (CMAKE_<LANG>_COMPILER_LAUNCHER). Otherwise, host-cmake
is built without ccache, as before.
Additionally, when BR2_PACKAGE_HOST_CMAKE is enabled, use host-cmake
for all cmake packages instead of the one from the build host.
Tested with a system cmake 3.28, and without one (by passing
BR2_CMAKE_CANDIDATES=nonexistent):
- system cmake, host-cmake enabled: host-ccache is built with the
system cmake and host-cmake with ccache; a rebuild of host-cmake
with a warm cache takes 2m06s, with 1502/1736 cache hits;
- no system cmake: host-cmake is built without ccache and is used to
build host-ccache, no circular dependency;
- system cmake too old for BR2_HOST_CMAKE_AT_LEAST (mosquitto
enabled): host-ccache still uses the system cmake.
Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
---
docs/manual/ccache-support.adoc | 5 +++++
package/cmake/Config.in.host | 3 +++
package/cmake/cmake.mk | 15 ++++++++++++---
package/pkg-cmake.mk | 21 ++++++++++++++-------
support/dependencies/check-host-cmake.mk | 24 ++++++++++++++++++++++++
5 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/docs/manual/ccache-support.adoc b/docs/manual/ccache-support.adoc
index 86cb4a150dc..45af6dfd41d 100644
--- a/docs/manual/ccache-support.adoc
+++ b/docs/manual/ccache-support.adoc
@@ -15,6 +15,11 @@ speed up the build process.
+Enable compiler cache+ in +Build options+. This will automatically
build +ccache+ and use it for every host and target compilation.
+Since +ccache+ is built with CMake, a suitable CMake from the build
+machine (at least 3.18) is used for +ccache+ and its dependencies. This
+allows +host-cmake+, if needed, to be built with +ccache+ as well.
+Without such a CMake, +host-cmake+ is built first, without +ccache+.
+
The cache is located in the directory defined by the +BR2_CCACHE_DIR+
configuration option, which defaults to
+$HOME/.buildroot-ccache+. This default location is outside of
diff --git a/package/cmake/Config.in.host b/package/cmake/Config.in.host
index b8221a7d222..f4dea749e12 100644
--- a/package/cmake/Config.in.host
+++ b/package/cmake/Config.in.host
@@ -8,6 +8,9 @@ config BR2_PACKAGE_HOST_CMAKE
generate native makefiles and workspaces that can be used in
the compiler environment of your choice.
+ When enabled, this cmake is used to build all CMake
+ packages, instead of a cmake from the build machine.
+
http://www.cmake.org/
# The minimum system cmake version we expect if 3.18 as provided by
diff --git a/package/cmake/cmake.mk b/package/cmake/cmake.mk
index 098f6e91582..632fa2bf781 100644
--- a/package/cmake/cmake.mk
+++ b/package/cmake/cmake.mk
@@ -12,8 +12,15 @@ CMAKE_LICENSE = BSD-3-Clause
CMAKE_LICENSE_FILES = LICENSE.rst
CMAKE_CPE_ID_VALID = YES
-# The package is a dependency to ccache so ccache cannot be a dependency
+# host-cmake can only use ccache when host-ccache is built with a system cmake
+ifeq ($(BR2_CCACHE):$(BR2_CMAKE_NOCCACHE_HOST_DEPENDENCY),y:)
+HOST_CMAKE_BOOTSTRAP_OPTS = --enable-ccache
+HOST_CMAKE_CCACHE_OPTS = \
+ -DCMAKE_C_COMPILER_LAUNCHER=$(CCACHE) \
+ -DCMAKE_CXX_COMPILER_LAUNCHER=$(CCACHE)
+else
HOST_CMAKE_ADD_CCACHE_DEPENDENCY = NO
+endif
# CMake is a particular package:
# * CMake can be built using the generic infrastructure or the cmake one.
@@ -43,7 +50,7 @@ CMAKE_CONF_OPTS = \
HOST_CMAKE_CFLAGS = $(shell echo $(HOST_CFLAGS) | sed -r "s%$(HOST_CPPFLAGS)%%")
HOST_CMAKE_CXXFLAGS = $(shell echo $(HOST_CXXFLAGS) | sed -r "s%$(HOST_CPPFLAGS)%%")
-# We may be a ccache dependency, so we can't use ccache
+# ccache is enabled via bootstrap options, not via CC/CXX
HOST_CMAKE_CONFIGURE_OPTS = \
$(HOST_CONFIGURE_OPTS) \
CC="$(HOSTCC_NOCCACHE)" \
@@ -55,7 +62,9 @@ define HOST_CMAKE_CONFIGURE_CMDS
$(HOST_CMAKE_CONFIGURE_OPTS) \
CFLAGS="$(HOST_CMAKE_CFLAGS)" \
./bootstrap --prefix=$(HOST_DIR) \
- --parallel=$(PARALLEL_JOBS) -- \
+ --parallel=$(PARALLEL_JOBS) \
+ $(HOST_CMAKE_BOOTSTRAP_OPTS) -- \
+ $(HOST_CMAKE_CCACHE_OPTS) \
-DCMAKE_C_FLAGS="$(HOST_CMAKE_CFLAGS)" \
-DCMAKE_CXX_FLAGS="$(HOST_CMAKE_CXXFLAGS)" \
-DCMAKE_EXE_LINKER_FLAGS="$(HOST_LDFLAGS)" \
diff --git a/package/pkg-cmake.mk b/package/pkg-cmake.mk
index f572bdebb3d..d205f6c5dcc 100644
--- a/package/pkg-cmake.mk
+++ b/package/pkg-cmake.mk
@@ -103,7 +103,7 @@ define $(2)_CONFIGURE_CMDS
rm -f CMakeCache.txt && \
PATH=$$(BR_PATH) \
$$(if $$(BR2_INSTALL_LIBSTDCPP),,CXX=/bin/false) \
- $$($$(PKG)_CONF_ENV) $$(BR2_CMAKE) $$($$(PKG)_SRCDIR) \
+ $$($$(PKG)_CONF_ENV) $$($$(PKG)_CMAKE) $$($$(PKG)_SRCDIR) \
-G$$($$(PKG)_GENERATOR) \
-DCMAKE_MAKE_PROGRAM="$$($$(PKG)_GENERATOR_PROGRAM)" \
-DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/share/buildroot/toolchainfile.cmake" \
@@ -135,7 +135,7 @@ define $(2)_CONFIGURE_CMDS
PKG_CONFIG_LIBDIR="$$(HOST_DIR)/lib/pkgconfig:$$(HOST_DIR)/share/pkgconfig" \
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
- $$($$(PKG)_CONF_ENV) $$(BR2_CMAKE) $$($$(PKG)_SRCDIR) \
+ $$($$(PKG)_CONF_ENV) $$($$(PKG)_CMAKE) $$($$(PKG)_SRCDIR) \
-G$$($$(PKG)_GENERATOR) \
-DCMAKE_MAKE_PROGRAM="$$($$(PKG)_GENERATOR_PROGRAM)" \
-DCMAKE_INSTALL_SO_NO_EXE=0 \
@@ -174,7 +174,14 @@ endif
# primitives to find {C,LD}FLAGS, add it to the dependency list.
$(2)_DEPENDENCIES += host-pkgconf
+# Packages that host-ccache depends on can't use a host-cmake built with ccache
+ifeq ($$($(2)_ADD_CCACHE_DEPENDENCY),NO)
+$(2)_CMAKE = $$(BR2_CMAKE_NOCCACHE)
+$(2)_DEPENDENCIES += $(BR2_CMAKE_NOCCACHE_HOST_DEPENDENCY)
+else
+$(2)_CMAKE = $$(BR2_CMAKE)
$(2)_DEPENDENCIES += $(BR2_CMAKE_HOST_DEPENDENCY)
+endif
#
# Build step. Only define it if not already defined by the package .mk
@@ -183,11 +190,11 @@ $(2)_DEPENDENCIES += $(BR2_CMAKE_HOST_DEPENDENCY)
ifndef $(2)_BUILD_CMDS
ifeq ($(4),target)
define $(2)_BUILD_CMDS
- $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$(BR2_CMAKE) --build $$($$(PKG)_BUILDDIR) -j$(PARALLEL_JOBS) $$($$(PKG)_BUILD_OPTS)
+ $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$($$(PKG)_CMAKE) --build $$($$(PKG)_BUILDDIR) -j$(PARALLEL_JOBS) $$($$(PKG)_BUILD_OPTS)
endef
else
define $(2)_BUILD_CMDS
- $$(HOST_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$(BR2_CMAKE) --build $$($$(PKG)_BUILDDIR) -j$(PARALLEL_JOBS) $$($$(PKG)_BUILD_OPTS)
+ $$(HOST_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$($$(PKG)_CMAKE) --build $$($$(PKG)_BUILDDIR) -j$(PARALLEL_JOBS) $$($$(PKG)_BUILD_OPTS)
endef
endif
endif
@@ -198,7 +205,7 @@ endif
#
ifndef $(2)_INSTALL_CMDS
define $(2)_INSTALL_CMDS
- $$(HOST_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$(BR2_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_OPTS)
+ $$(HOST_MAKE_ENV) $$($$(PKG)_BUILD_ENV) $$($$(PKG)_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_OPTS)
endef
endif
@@ -208,7 +215,7 @@ endif
#
ifndef $(2)_INSTALL_STAGING_CMDS
define $(2)_INSTALL_STAGING_CMDS
- $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) DESTDIR=$$(STAGING_DIR) $$(BR2_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_STAGING_OPTS)
+ $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) DESTDIR=$$(STAGING_DIR) $$($$(PKG)_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_STAGING_OPTS)
endef
endif
@@ -218,7 +225,7 @@ endif
#
ifndef $(2)_INSTALL_TARGET_CMDS
define $(2)_INSTALL_TARGET_CMDS
- $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) DESTDIR=$$(TARGET_DIR) $$(BR2_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_TARGET_OPTS)
+ $$(TARGET_MAKE_ENV) $$($$(PKG)_BUILD_ENV) DESTDIR=$$(TARGET_DIR) $$($$(PKG)_CMAKE) --install $$($$(PKG)_BUILDDIR) $$($$(PKG)_INSTALL_TARGET_OPTS)
endef
endif
diff --git a/support/dependencies/check-host-cmake.mk b/support/dependencies/check-host-cmake.mk
index e3676903198..52ea9271a56 100644
--- a/support/dependencies/check-host-cmake.mk
+++ b/support/dependencies/check-host-cmake.mk
@@ -8,9 +8,33 @@
BR2_CMAKE_VERSION_MIN = $(BR2_HOST_CMAKE_AT_LEAST)
BR2_CMAKE_CANDIDATES ?= cmake cmake3
+
+# When host-cmake is enabled, use it for all packages.
+ifeq ($(BR2_PACKAGE_HOST_CMAKE),y)
+BR2_CMAKE = $(HOST_DIR)/bin/cmake
+BR2_CMAKE_HOST_DEPENDENCY = host-cmake
+else
BR2_CMAKE ?= $(call suitable-host-package,cmake,\
$(BR2_CMAKE_VERSION_MIN) $(BR2_CMAKE_CANDIDATES))
ifeq ($(BR2_CMAKE),)
BR2_CMAKE = $(HOST_DIR)/bin/cmake
BR2_CMAKE_HOST_DEPENDENCY = host-cmake
endif
+endif
+
+# cmake for packages that host-ccache depends on (<PKG>_ADD_CCACHE_DEPENDENCY
+# = NO). A suitable system cmake is preferred, so host-cmake can then itself
+# be built with ccache. The minimum is the one required by ccache.
+BR2_CMAKE_NOCCACHE_VERSION_MIN = 3.18
+
+ifeq ($(BR2_CCACHE),y)
+BR2_CMAKE_NOCCACHE ?= $(call suitable-host-package,cmake,\
+ $(BR2_CMAKE_NOCCACHE_VERSION_MIN) $(BR2_CMAKE_CANDIDATES))
+ifeq ($(BR2_CMAKE_NOCCACHE),)
+BR2_CMAKE_NOCCACHE = $(HOST_DIR)/bin/cmake
+BR2_CMAKE_NOCCACHE_HOST_DEPENDENCY = host-cmake
+endif
+else
+BR2_CMAKE_NOCCACHE = $(BR2_CMAKE)
+BR2_CMAKE_NOCCACHE_HOST_DEPENDENCY = $(BR2_CMAKE_HOST_DEPENDENCY)
+endif
--
2.43.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-30 20:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 20:37 [Buildroot] [PATCH] core: allow host-cmake to be built with ccache Thomas Devoogdt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.