Simple C++ project with CMake build system + CPM as package manager. This project included with separated apps and libraries for example.
CPM (CPM.cmake) is a cross-platform CMake script that adds dependency management capabilities to CMake. Readmore https://github.com/cpm-cmake/CPM.cmake
This project also has been preloaded with libraries:
-
Install
CMake, minimum version 3.20 -
Justto run defined command (optional) -
Build app by running this command:
cmake -S . -B build -G "Ninja Multi-Config" # or use `just cmake` # to build debug app: cmake --build build --config Debug # or use `just build_debug` # to build release app: cmake --build build --config Release # or use `just build_release`
-
To run app:
# to run debug app ./build/bin/Debug/example # or use `just run_debug example` # to run release app ./build/bin/Release/example # or use `just run_release example`
all command can be found inside
justfile
Dependency can be added in CMakeLists.txt or organize it in cmake/dependnecies.cmake (recommended).
Example:
CPMAddPackage("gh:fmtlib/fmt#11.1.3")
# or
CPMAddPackage(
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.15.2
OPTIONS "SPDLOG_FMT_EXTERNAL 1"
)Readmore in https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#usage
The CMake also generate compile_commands.json for LSP.
cmake -S . -B build # or use `just cmake`File compile_commands.json can be found in build/ directory
├── apps
├── apps
│ ├── CMakeLists.txt
│ └── example
│ ├── CMakeLists.txt
│ ├── include
│ │ └── foo_bar.hpp
│ └── src
│ ├── foo_bar.cpp
│ └── main.cpp
├── cmake
│ ├── CPM.cmake
│ ├── dependencies.cmake
│ └── setup.cmake
├── CMakeLists.txt
├── justfile
├── libs
│ ├── bar
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ │ └── bar.hpp
│ │ └── src
│ │ └── bar.cpp
│ ├── CMakeLists.txt
│ └── foo
│ ├── CMakeLists.txt
│ ├── include
│ │ └── foo.hpp
│ └── src
│ └── foo.cpp
├── README.md
└── scripts
└── update_cpm.sh