add readme for posterity

This commit is contained in:
Greg Gauthier 2023-07-20 20:24:05 +01:00
parent cce320f2a5
commit 1d66462b2f
4 changed files with 28 additions and 0 deletions

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# NewProject
---
A simple demonstration of how to include multiple cpp files in a single project, using cmake.
There are three strategies:
1. direct declaration in the main, with the external source files identified in the cmakelist add_executables.
2. explicit inclusion (`#include mysource.cpp`). In this case, they should not be added to the cmakelist.
3. The "canonical" or "best practice" c++ approach: explicit inclusion of a header file (`#include mysource.h`) which declares all the classes and methods publicly accessible to main. Both the source and header must be added to cmakelist.
Here is my main, with all three strategies implemented:
![inclusions](img/inclusions.png)
Here is the cmakelist:
![](img/cmakelist.png)
Note, that you'll have to specify your version of cmake in the `set`.
You can build this with this command:
```shell
cmake --build {your-project-path}/NewProject/cmake-build-debug --target NewProject -j 14
```
And when you run the compiled binary, you should see:
![the output](img/output.png)

BIN
img/cmakelist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
img/inclusions.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
img/output.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB