A C++ Project structure template, based on the guide by Mateusz Pusz: "CMake + Conan: 3 Years Later":
This is a simplified version of Mateusz's new-project-template, with support for the things I need.
Includes support for:
- C++20 (can be changed)
- Core built as library
- Boost 1.81.0 (via Conan), including Boost::Log
- GTest 1.12.1 (via Conan)
- Debug & Release configurations
- CLion support
- Pthreads
To convert to your new project name:
- Search/replace the project name
cpp-project-template
- Search/replace the namespace
cpt
- Search/replace the header guards
CPT_
Before the project can be built, any Conan dependencies must be made available.
Then, cmake
can be used to generate the build files, and then run the build.
If the following profiles do not exist, create them.
Debug:
$ conan profile new gcc-11-debug --detect
$ conan profile update settings.compiler.libcxx=libstdc++11 gcc-11-debug
$ conan profile update settings.compiler.cppstd=20 gcc-11-debug
$ conan profile update settings.build_type=Debug gcc-11-debug
Release:
$ conan profile new gcc-11-release --detect
$ conan profile update settings.compiler.libcxx=libstdc++11 gcc-11-release
$ conan profile update settings.compiler.cppstd=20 gcc-11-release
$ conan profile update settings.build_type=Release gcc-11-release
Debug:
$ conan install -if $BUILD_DIR . --build=missing -s build_type=Debug -pr:b=gcc-11-debug
Release:
$ conan install -if $BUILD_DIR . --build=missing -s build_type=Release -pr:b=gcc-11-release
Prepare:
$ cmake .. \
-B $BUILD_DIR \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
-DBUILD_TESTS=1 \
-DUSE_STATIC_BOOST=1
Build:
$ cmake \
--build $BUILD_DIR \
--config Release \
-j 8