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..af0c075 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) + { + 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: