Introduction
| Requirement | Codemap | Dependencies | Build | CI | Appendices | Contributing | License |This is an example of how to create a Modern CMake C++ Project.
This project should run on GNU/Linux, MacOS and Windows.
Requirement
You'll need:
- "CMake >= 3.24".
Codemap
The project layout is as follow:
-
CMakeLists.txt Top-level for CMake based build.
-
cmake Subsidiary CMake files.
-
ci Root directory for continuous integration.
-
Foo Root directory for
Foolibrary.- CMakeLists.txt for
Foo. - include public folder.
- src private folder.
- CMakeLists.txt for
-
Bar Root directory for
Barlibrary.- CMakeLists.txt for
Bar. - include public folder.
- src private folder.
- CMakeLists.txt for
-
FooBar Root directory for
FooBarlibrary.- CMakeLists.txt for
FooBar. - include public folder.
- src private folder.
- CMakeLists.txt for
-
FooBarApp Root directory for
FooBarAppexecutable.- CMakeLists.txt for
FooBarApp. - src private folder.
- CMakeLists.txt for
Dependencies
To complexify a little, the CMake project is composed of three libraries (Foo, Bar and FooBar)
with the following dependencies:
Foo:
Bar:
FooBar: PUBLIC Foo PRIVATE Bar
FooBarApp: PRIVATE FooBarnote: Since Foo is a public dependency of FooBar, then FooBarApp will
see Foo inlude directories
Build
To build the C++ project, as usual:
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --config Release --target testBuild directory layout
Since we want to use the CMAKE_BINARY_DIR to generate the binary package.
We want this layout (tree build --prune -P "*.so|FooApp"):
build
├── bin
│ └── FooBarApp
└── lib
└── lib*.so
Appendices
Few links on the subject...
Resources
Project layout:
CMake:
- https://llvm.org/docs/CMakePrimer.html
- https://cliutils.gitlab.io/modern-cmake/
- https://cgold.readthedocs.io/en/latest/
Contributing
The CONTRIBUTING.md file contains instructions on how to
file the Contributor License Agreement before sending any pull requests (PRs).
Of course, if you're new to the project, it's usually best to discuss any
proposals and reach consensus before sending your first PR.
License
Apache 2. See the LICENSE file for details.
Disclaimer
This is not an official Google product, it is just code that happens to be
owned by Google.