cbt or "C++ Build Tool" is a postmodern build tool intended towards developing applications in C++ effortlessly.
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:
- Different syntax to learn
- Some such tools generate output which is then to be fed to some other tool which then builds your application, e.g.
Meson,Ninja - The language itself (owing to its development history) demanding understanding of intrinsic low-level or operating system specific features which then needs to be made portable
- Different tools having different folder layout structure adding to cognitive load
- Need to understand flow of commands in
Makeand family of build tools, e.g.CMake; and also continuously update the MakeFile (and variants) with cryptic glob patterns - Some build tools being written in some other interpreted language requiring the end-developer to download extra runtime environments, e.g.
SCons - Some tools require knowledge of the GUI (Graphical User Interface) IDE (Integrated Development Environment) that interacts with the underlying build tool (e.g. Visual C++ Build Tool); while some CLI (Command Line Interface) tools are so complex that considerable effort has to be made to first understand cryptic flags and arguments (e.g.
clang,g++) - And lot more ...
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.
- Lightning Talk at CppIndiaCon-2024 (cbt-2024.07.30 being demoed).
cbt is a very simple build tool made from first principles:
- Entirely command driven, e.g.
cbt create-project my-app,cbt create-file some_module/some_util - Simple commands to compile, test and build the project
- Native support for timestamp-aware compilation and testing without any extra involvement/effort from developer's end
- Simple, intuitive and maintainable project configuration through
project.cfg - Unlike an
npmproject, ensure that all projects created withcbtstrictly have the same directory structure - Automatically create proper scaffold upon invocation of
cbt create-file <file_name>(descriptions given below), and thereby reduce cognitive load - First-class (and type-safe) support for
envfile(s) - Unobtrusive and transparent
cbt_toolsoffered 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-application <name> - Scaffold a new application
create-library <name> - Scaffold a new library
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 and generate respective binaries under 'build/binaries/'
build-project - (For applications only) Perform linking and generate final executable under 'build/'
run-unit-tests - Run all test cases under 'tests/unit_tests/' directory
clear-build - Delete all object files under 'build/' directory
info - Show information regarding cbt
help - Shows this help messageReady-made binaries for Ubuntu and Windows are available through Releases.
For other platforms, or for building from source, read on.
cbtis developed inWSL2 Ubuntu 20.04andWindows 11.- There is a hard dependency on
g++as the underlying tool. - There is a hard dependency on
C++2astandard. Ensure yourGNUtoolchain is at least9.4.0. GNUtoolchain used for development is11.4.0.- If on Windows, MinGW can be downloaded from WinLibs.
- On a Mac,
g++is actually a tiny wrapper overclang. This shouldn't be a problem as such, but if you want to develop exclusively throughg++, then download the binary (through Homebrew or MacPorts, etc.) and aliasg++to the appropriate downloaded binary, i.e.alias g++=g++-<version>.
- Clone/download the source code and navigate to the directory.
- Run the following:
# On *nix platforms
$ chmod +x script.sh
$ ./script.sh init compile build
# On Windows
> .\script.bat init compile build- The executable will be placed under the
build/directory with the namecbt(orcbt.exeonWindows). - Run
./build/cbt help(or.\build\cbt.exeonWindows) to get all available commands. - Add the binary to your OS'
PATH.
Note: During the build stage through script.sh, pay attention to the following:
- If your platform is
Linuxbut notUbuntu, update the file-name at line 40. - If you get a message "Please use a binary that can generate a SHA-256 checksum for this platform", then add your respective platform and associated binary that computes the
SHA-256checksum. - If
unameis 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 testing |
✅ Complete |
Note: 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 |
✅ Complete |
|
| 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 |
Refer to this discussion |
| 14 | Add support for linting |
💤 TBD |
cppcheck seems to be a good fit for integration |