⚙

CMakeLists.txt Generator

Configure your C++ project and generate a ready-to-use CMakeLists.txt — modern CMake, no bad practices.

Project Settings
Required. Must start with a letter; letters, digits, underscores, hyphens only.
Must start with a letter; letters, digits, underscores, hyphens only.
Must be in the format X.Y (e.g. 3.16, 3.28).
C++ Standard
Source Files
Leave empty and a TODO placeholder will be generated instead of a GLOB. Why not GLOB?
Source file paths must only contain letters, digits, underscores, hyphens, dots, and slashes.
Include dir paths must only contain letters, digits, underscores, hyphens, dots, and slashes.
Libraries
GTest is a test framework — it will be linked to a separate test executable, not to your library. A myproject_tests target will be generated.
Build Options
Compiler flags are emitted with generator expressions so GCC/Clang and MSVC each get their own flags. For production projects, consider moving flags to CMakePresets.json instead.
Advanced / Dependency Management
These will add helpful commented sections in the generated file.
Recommended for new projects: Use vcpkg or Conan + modern find_package.
CMakeLists.txt
# Configure your project above and click "Generate CMakeLists.txt"
# CMakePresets.json will appear here after generation

How to use the CMakeLists.txt generator (and what the output means)

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.

Using the generator

  1. Enter a project name. It must start with a letter and use only letters, digits, underscores and hyphens. Leave the target name empty to reuse it.
  2. Pick a minimum CMake version and a C++ standard (11, 14, 17, 20 or 23). Newer standards need newer CMake. As a rule of thumb, C++23 needs CMake 3.20 or later.
  3. List your source files, one per line, and any include directories.
  4. Tick the libraries you use, choose your build options and click Generate.
  5. Copy or download the result. Save it as CMakeLists.txt in your project root, then build with cmake -S . -B build followed by cmake --build build.

Why the generator does not use GLOB

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.

Include visibility: PRIVATE, PUBLIC and INTERFACE

When you build a library, the include-directory command needs to know who should see those headers.

Build options explained

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.

Where do libraries come from?

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.

The CMakePresets.json tab

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

Frequently asked questions

Does the generator replace learning CMake?
No. It gives you a solid starting file. Read the output and look up each command, because you will need to edit it as your project grows.
Is anything uploaded when I click Generate?
No. The file is built in your browser from the values in the form.
Which C++ standard should I pick?
C++17 is a safe default for most projects. Choose a newer standard only if your compilers fully support it.
My library isn’t in the list. What now?
Add a find_package line and a target_link_libraries entry by hand, following the pattern the generator produced for the others.

Verify You're Human

Copied to clipboard!

We use cookies to enhance your experience. Optional cookies only run if you consent. See our Privacy Policy.