cbt
or "C++ Build Tool" is a postmodern build tool aimed to provide a standard application structure and facilitate code re-use, thereby making working with C++ a breeze.
The one thing lacking in the C++ ecosystem is a simple and lucid build system. While the flexibility of C++ and the low-level target nature of this language has enabled/forced multiple vendors to create their own (both platform-agnostic and platform-dependent) build systems, it is really difficult to interact with such tools due to one or more of the following (a non-enhaustive list) issues:
Meson
, Ninja
Make
and family of build tools, e.g. CMake
; and also continuously update the MakeFile (and variants) with cryptic glob patternsSCons
clang
, g++
)One reason why proliferation of JavaScript has been so prominent is due to npm
(later other package managers followed suite) and the one unified package.json
, both of which have catapulted a once browser-only language to be used in almost all (sometimes even inappropriately) domains.
cbt
is similar in spirit to npm
and package.json
, except it is more about making software development with C++ more approachable to beginners and seasoned developers alike; and equally not raising C++ to such higher abstraction language(s) like Java, C#, etc.
cbt
is a very simple build tool made from first principles:
cbt create-project my-app
, cbt create-file some_module/some_util
project.cfg
npm
project, ensure that all projects created with cbt
strictly have the same folder structurecbt create-file <file_name>
(descriptions given below), and thereby reduce cognitive loadenv
file(s)cbt_tools
offered to bring quality-of-life improvements as well as enable flexible customisation(s) as per project requirements$ cbt help
Usage:
1. Globally - cbt <options> [file_name]
2. From inside a project - [env=<an_env_file>] cbt <options> [file_name]
Note:
1. Environment files are located under the `<project>/environments/` directory
2. The '.env.template' file must be provided with all the environment values along with the necessary types
3. `env` entry defaults to 'local.env' if no `env` entry is provided
4. Specify the `env` file to be picked up without the '.env' extension, e.g. "env=production"
Options:
create-project <project-name> - Scaffold a new project
create-file <file_name> - Generate respective C++ files under 'headers/', 'src/' and 'tests/' directories
create-file <path/to/file_name> - Same as above, but will create necessary sub-directories if required
compile-project - Compile all files (timestamp-aware) and generate respective binaries under 'build/binaries/'
build-project - Perform linking and generate final executable under 'build/'
run-unit-tests - Run all test cases (timestamp-unaware) under 'tests/unit_tests/' directory
clear-build - Delete all object files under 'build/' directory
info - Show information regarding cbt
help - Shows this help message
Ready-made binaries for Ubuntu and Windows are available through Releases.
For other platforms, or for building from source, read on.
cbt
is developed in WSL2 Ubuntu 20.04
and Windows 11
.g++
as the underlying tool.C++2a
standard. Ensure your GNU
toolchain is at least 9.4.0
.GNU
toolchain used for development is 11.4.0
.g++
is actually a tiny wrapper over clang
. This shouldn't be a problem as such, but if you want to develop exclusively through g++
, then download the binary (though Homebrew or MacPorts, etc.) and alias g++
to the appropriate downloaded binary, i.e. alias g++=g++-<version>
Run the following:
# On *nix platforms
$ chmod +x script.sh
$ ./script.sh init compile build
# On Windows
> .\script.bat init compile build
build/
directory with the name cbt
(or cbt.exe
on Windows
)./build/cbt help
(or .\build\cbt.exe
on Windows
) to get all available commandsPATH
.Note: During the build
stage through script.sh
, pay attention to the following:
Linux
but not Ubuntu
, update the file-name at line 40.SHA-256
checksum.uname
is not available on your platform, replace $(uname -s)
with "$OSTYPE"
in line 39, and update the options accordingly.In any of the above case(s), the format for the file-name containing the checksum is <platform>.sha256.checksum.txt
.
Disclaimer: The following roadmap may be subjected to change depending on various factors like: bandwidth, priority and/or complexity.
# | Task | Status | Notes |
---|---|---|---|
1 | Create a basic workable binary | ✅ Complete |
|
2 | Allow basic create , compile and build functionalities |
✅ Complete |
|
3 | Support scaffold for test ing |
⛅ Partially achieved |
Only unit tests supported currently |
4 | Use project.cfg as a one-stop configuration file for the entire project workspace management |
✅ Complete |
|
5 | Decouple g++ and all build configurations from source code |
✅ Complete |
|
6 | Add support for various other C++ compilers | 💤 TBD |
Requires a slight forward thinking mindset w.r.t. point 8 below |
7 | Support scaffold for shared objects (.so and .dll ) |
💤 TBD |
|
8 | Add support for dependency management | 💤 TBD |
|
9 | Add support for documentation during scaffold and as a command (maybe via some 3rd party tools like doxygen ) |
💤 TBD |
|
10 | Bootstrap cbt with cbt |
⛅ Partially achieved |
|
11 | Add native support for reading environment values from env file(s) |
✅ Complete |
|
12 | Optimise compilation and building by inspecting dependency graph | ✅ Complete |
|
13 | Support scaffold for daemons (*nix) and services (Windows) | 💤 TBD |
|
14 | Add support for lint ing |
💤 TBD |
cppcheck seems to be a good fit for integration |