I was recently looking for an easy to use build tool for my C/C++ projects and found out that there are so many build tools, but all of them are so complicated for a beginner. Since there are already too many of them and I got confused on what to use, I just thought of writing one of my own, with simplicity in mind. Since it was supposed to be a simpler version of
cmake, I named it
Some features of this tool are:
- Easy-to-write build files using the YAML standard
- Select input directory and output directory
- Write tests easily
Since python is an easy option to create command line applications, I used it to accomplish this in just 2 days.
- You can run this package using both Python 2 and 3.
- Clone the Github repository.
- Install requirements using
pip install -r requirements.txt
- Create a
virtualenvif you are just trying this out.
- After creating a
pip install -e .
How to use
Usage with input directory
$ cbake /path/to/input/directory
Usage with input and output directories
$ cbake /path/to/input/directory --output-directory /path/to/output/directory OR $ cbake /path/to/input/directory -o /path/to/output/directory
The Bake file
The build configuration can be simply put in a YAML file named:
.bake.yml. A sample bake file is shown below:
# name of the project project: project_name # Which command to use for compiling your project # Example: clang, gcc for C and clang++, g++ for C++ compile: gcc # executables that you want to add, with the C/C++ files # that you want to add to each executable executables: first: - a.h - b.c second: - c.h - d.h # This part adds the required compilation flags for your compiler flags: - Wall - w # flag to enable testing testing: true # out of the executables defines above, you can select some to be run as tests like shown below tests: - first
The above config will create the following commands:
$ gcc tests/test1/a.h tests/test1/b.c -o tests/test1/first.o -Wall -w $ gcc tests/test1/c.h tests/test1/d.c -o tests/test1/second.o -Wall -w
To write tests for your project, you can add executables that contain the sources for tests. After compilation, you can run
cbake . test with the previously used options and arguments, and the tests will be run.
Also, if you have not run
cbake before in some directory and it contains some tests, you can directly run the
test command and
cbake will compile those executables on the fly!
Things to keep in mind
- This cli should be used in the original sequence (
cbake [OPTIONS] [DIRECTORY] COMMAND [ARGS])
- For testing, the input directory needs to be specified, but for normal compilation it's not needed. Example:
cbake . -v test
While this was not much of a difficult project, since it simply generates appropriate commands and runs them, it would be really difficult / impossible to use this for bigger / complex projects.