From def21f06be831d12af22c5f2ab631987f6b1bfbe Mon Sep 17 00:00:00 2001 From: Jacob Pedersen Date: Wed, 17 Jun 2026 23:57:52 +0200 Subject: [PATCH 1/2] Added ccache support and missing documentation --- CPPBuild/BuildSetup.h | 1 + CPPBuild/CPPBuild.cpp | 8 +++++++- CPPBuild/Target.cpp | 6 ++++++ Docs/README.md | 34 +++++++++++++++++++++++++++++----- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CPPBuild/BuildSetup.h b/CPPBuild/BuildSetup.h index e836220..534b6e8 100644 --- a/CPPBuild/BuildSetup.h +++ b/CPPBuild/BuildSetup.h @@ -216,6 +216,7 @@ class BuildSetup int version = 1; std::string sourcePath; BuildProject project; + bool ccache = false; static BuildSetup fromJson(const JsonValue& json); }; diff --git a/CPPBuild/CPPBuild.cpp b/CPPBuild/CPPBuild.cpp index 3adb590..38334af 100644 --- a/CPPBuild/CPPBuild.cpp +++ b/CPPBuild/CPPBuild.cpp @@ -287,7 +287,13 @@ void CPPBuild::createPackage() BuildSetup CPPBuild::loadBuildSetup() { - return BuildSetup::fromJson(JsonValue::parse(File::readAllText(FilePath::combine(cppbuildDir, "config.json")))); + BuildSetup setup = BuildSetup::fromJson(JsonValue::parse(File::readAllText(FilePath::combine(cppbuildDir, "config.json")))); + JsonValue properties = loadProperties(FilePath::combine(getGlobalConfigDir(), "properties.json")); + JsonValue localProperties = loadProperties(FilePath::combine(getLocalConfigDir(), "properties.json")); + for (const auto& it : localProperties.properties()) + properties[it.first] = it.second; + setup.ccache = (properties["ccache.enable"].to_string() == "true"); + return setup; } std::vector CPPBuild::getBuildOrder(BuildSetup& setup, std::string targetName, std::string configuration) diff --git a/CPPBuild/Target.cpp b/CPPBuild/Target.cpp index 6549168..74a4653 100644 --- a/CPPBuild/Target.cpp +++ b/CPPBuild/Target.cpp @@ -1004,6 +1004,12 @@ void Target::loadTarget(BuildSetup& setup, PackageManager* packages) ar = "ar"; isGcc = true; #endif + + if (setup.ccache && system("which ccache >/dev/null 2>&1") == 0) + { + cc = "ccache " + cc; + ccpp = "ccache " + ccpp; + } } wwwrootDir = FilePath::combine(sourcePath, targetDef.wwwRootDir); diff --git a/Docs/README.md b/Docs/README.md index 38f9ef3..1e43eaf 100644 --- a/Docs/README.md +++ b/Docs/README.md @@ -7,9 +7,9 @@ CPPBuild is a build system and a project generator for C and C++ projects. ``` cppbuild configure [source path] cppbuild set [--global] -cppbuild [--workdir ] build -cppbuild [--workdir ] clean -cppbuild [--workdir ] rebuild +cppbuild [--workdir ] build [--no-deps] +cppbuild [--workdir ] clean [--no-deps] +cppbuild [--workdir ] rebuild [--no-deps] cppbuild [--workdir ] create-package cppbuild [--workdir ] create-installer ``` @@ -22,16 +22,40 @@ After this the project can be built either by running cppbuild directly, opening `cppbuild set` sets a property value that can then be read via `Project.getProperty(name)` in the configure script. If `--global` is specified the property is set globally for all cppbuild projects. -`cppbuild build` will build a specific target. +`cppbuild build` will build a specific target and all of its dependencies in the correct order. -`cppbuild clean` will remove all intermediate and output files from earlier builds. +`cppbuild clean` will remove all intermediate and output files for a target and its dependencies. `cppbuild rebuild` is shorthand for first running clean followed by build. +The optional `--no-deps` flag skips dependency resolution and builds only the named target itself. This is used internally by the generated Visual Studio project files, where Visual Studio handles dependency ordering via project references. + `cppbuild create-package` creates packages described via `PackageInstaller.add()`. `cppbuild create-installer` creates MSI installers described via `Installer.add()`. +## Built-in Properties + +Some properties are recognized directly by CPPBuild and affect how it builds targets. They are set with `cppbuild set` like any other property. + +| Property | Platform | Values | Default | Description | +|---|---|---|---|---| +| `ccache.enable` | Linux, macOS | `true` / `false` | `false` | Prepends `ccache` to the C and C++ compiler commands. ccache must be installed. Has no effect if ccache is not found on `PATH`. | +| `cppbuild.vsversion` | Windows | VS display name | latest installed | Selects the Visual Studio installation used when generating the solution. The value must match the VS display name exactly, e.g. `Visual Studio 2022`. If not set, the most recently installed version is used. | + +Examples: + +``` +cppbuild set ccache.enable true +cppbuild set cppbuild.vsversion "Visual Studio 2022" +``` + +Use `--global` to apply the setting to all CPPBuild projects on the machine: + +``` +cppbuild set --global ccache.enable true +``` + ## Configure.js A basic configure script might look like this: From cd342b472b6abaeb85920f87f7f08be2be463a42 Mon Sep 17 00:00:00 2001 From: Jacob Pedersen Date: Thu, 18 Jun 2026 00:02:32 +0200 Subject: [PATCH 2/2] No need to check if ccache is installed if enabled --- CPPBuild/Target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPPBuild/Target.cpp b/CPPBuild/Target.cpp index 74a4653..af0c075 100644 --- a/CPPBuild/Target.cpp +++ b/CPPBuild/Target.cpp @@ -1005,7 +1005,7 @@ void Target::loadTarget(BuildSetup& setup, PackageManager* packages) isGcc = true; #endif - if (setup.ccache && system("which ccache >/dev/null 2>&1") == 0) + if (setup.ccache) { cc = "ccache " + cc; ccpp = "ccache " + ccpp;