When working with c or c++ in the command line I usually make scripts to help me with common tasks. Usually I will make a few scripts to activate different kinds of builds quickly
These scripts should be project independent so that we can re-use them in any given c/c++ project.
Note: My toolchain is cmake for builds, clang for formatting, and bash for scripting
The first step of this process is to create a scripts dir in the root of the project
We'll start with a script which moves us to the correct directory: scripts/move_to_base_project_dir.sh
- we're making this a script because if we ever change our project dir we can still use these scripts from anywhere
- [your project directory] must be an absolute path, this is because we will run this script multiple times, if it was a relative path say "..", then we would continually be moving back a directory.
- Add an argument to each script which mentions if it's already in the project dir, if it is don't cd again, this will allow support for relative paths
cmake scripts
If you're not yet familiar with cmake check out my page on it here
compiling a program
Because cmake
provides a solution to a complex problem, it is highly configurable, and usually a highly configurable systems make doing simple things a little more involved, indeed this manifests itself in cmake while trying to build a simple project. Here's the breakdown
With cmake we start by generating the build system (on my machine this will create a makefile)
Next we can build the project
If we want to generate the build system and build all at once
Now that you've built your project run it
You've made some edits, and you want to build and run the program
Notice that the only parameters to these scripts were the executable name and the project directory, to complete our goal, we should store these in a file and load them in dynamically