Configure your C++ project and generate a ready-to-use CMakeLists.txt — modern CMake, no bad practices.
generator expressions so GCC/Clang and MSVC each get their own flags. For production projects, consider moving flags to CMakePresets.json instead.
vcpkg or Conan + modern find_package.
# Configure your project above and click "Generate CMakeLists.txt"
# CMakePresets.json will appear here after generation
CMake does not compile anything itself. It reads a file called CMakeLists.txt and produces build files for your real build tool, such as Ninja, Make or Visual Studio. Writing that file from scratch is easy to get wrong, and a lot of the examples online use habits that CMake’s own maintainers have been steering people away from for years. This generator fills in the form fields you give it and produces a file in the modern, target-based style.
CMakeLists.txt in your project root, then build with cmake -S . -B build followed by cmake --build build.Many tutorials collect sources with file(GLOB ...). The catch is that CMake only evaluates the pattern when you configure the project. If you add or delete a source file, the build does not notice until you re-run CMake by hand, which causes confusing “undefined reference” errors. CMake’s documentation recommends listing sources explicitly. If you leave the source box empty, the generator inserts a clearly marked TODO instead of a glob.
When you build a library, the include-directory command needs to know who should see those headers.
-Wall -Wextra): turn on the compiler’s most useful checks. MSVC uses a different flag (/W4), so the generator emits each flag only for the compiler that understands it, using generator expressions.Setting CMAKE_CXX_STANDARD_REQUIRED to ON makes the build fail if the compiler can’t provide the standard you chose, instead of quietly falling back to an older one. Setting CMAKE_CXX_EXTENSIONS to OFF requests plain ISO C++ rather than a compiler-specific dialect.
The generator adds find_package calls for the libraries you tick, such as Boost, OpenSSL or Eigen3. That only works if the library is already installed. For new projects, a package manager such as vcpkg or Conan is the most reliable way to install them. The “FetchContent” option adds commented examples that download and build a dependency as part of your own build, which suits small libraries. Boost is header-only unless you select components such as filesystem or program_options.
Google Test is handled differently on purpose: it is linked into a separate test executable (named after your project with a _tests suffix), not into your main target.
A presets file stores your configure settings (generator, build directory and build type) in the project, so everyone on a team builds the same way. The generator creates a Debug and a Release preset using Ninja. After saving the file, run cmake --preset default. Presets require CMake 3.19 or newer, and anything beyond the basics may need a newer version still.
cmake --preset default cmake --build build/default
find_package line and a target_link_libraries entry by hand, following the pattern the generator produced for the others.