1.0 KiB
1.0 KiB
NewProject
A simple demonstration of how to include multiple cpp files in a single project, using cmake.
There are three strategies:
- direct declaration in the main, with the external source files identified in the cmakelist add_executables.
- explicit inclusion (
#include mysource.cpp
). In this case, they should not be added to the cmakelist. - 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:
Here is the cmakelist:
Note, that you'll have to specify your version of cmake in the set
.
You can build this with this command:
cmake --build {your-project-path}/NewProject/cmake-build-debug --target NewProject -j 14
And when you run the compiled binary, you should see: