C++ CMake project template with Hunter package manager
- CMake >= 3.21.0
- C++ compiler (gcc, msvc, mingw)
- IDE related (optional, only for VSCode)
- VSCode
- VSCode plugin - C/C++
- VSCode plugin - CMake
- VSCode plugin - CMake Tools
For MinGW users:
Please remember to set the MinGW to the PATH environment.
This template is based on CMake and aimed to minimize the CMake build script programming effort for the developer.
But we still recommend the users of this template to learn the CMake language.
- Press the Use this template from CppProjectTemplate
- Fill repo name & description
- Press Create repository from template
Here is a flow from CMake configure to Run & Debug the code.
- Install the VSCode and related plugins(See Prerequisite)
- Clone your repo to local & open with VSCode
- CMake: Select a Kit, select your compiler toolchain.
- CMake configure build type (optional).
- Build.
- If CMake asks for the configuration to the IntelliSense, press Don't Allow. (This template generate c_cpp_properties.json for IntelliSense)
- Press Run and Debug.
- Select executable.
- Add breakpoint in source code
- Press Start debugging.
- Add new .cpp/.c code under
src
. - reconfigure, done.
See src/CppProjectTemplate/example.cpp for example.
- Add new .cpp/.c code under
src
. - Add cmake file with same name as source, for example:
src/mycode.cpp
,src/mycode.cmake
- Edit cmake file, add following content:
# src/<your file name>.cmake
include(cmake/scheme/lib.cmake)
- Open cmake/packages.cmake
- Add hunter package. For example, add
fmt
package:
# ...The existing item in packages.cmake
hunter_add_package(fmt)
find_package(fmt CONFIG REQUIRED)
- All the source code can use the imported library directly, no needs to write link script.