The missing CMake project initializer
cmake-init
- The missing CMake project initializercmake-init
is an opinionated CMake project initializer that generates CMake
projects which are FetchContent ready, separate consumer and developer targets,
provide install rules with proper relocatable CMake packages and use modern
CMake (3.14+).
Please see the wiki for example outputs of cmake-init and other pragmatic
examples of functionality implemented for CMake, like package managers, fuzz
testing, superbuilds, etc.
If you wish to contact me for anything CMake related, then you may find me in
the #cmake
channel of the C++ Slack. If what you wish to know is
cmake-init specific, then you may also ask questions in this repository’s
Discussions.
h
whens
when prompted. SimpleFetchContent
ready projectsMake sure you have these programs installed:
NOTE
Some of these tools can be used on Windows as well if you want to use Visual
Studio, but you have to install these addins:
This package is available for download from PyPI. You can install this
package using pip
:
pip install cmake-init
clang-tidy is a static analysis tool that helps you spot logical errors in
your code before it is compiled. This script gives you the option to inherit
the clang-tidy
preset in your dev
preset, enabling the CMake integration
for this tool.
CI will always run clang-tidy for you, so it is entirely optional to install
and use it locally, but it is recommended.
For Windows users, if you wish to use clang-tidy, then you must install
Ninja and set the generator
field in your dev
preset to Ninja
. The
reason for this is that only Makefiles and Ninja are supported with CMake
for use with clang-tidy. For other generators, this feature is a no-op.
cppcheck is a static analysis tool similar to clang-tidy, however the
overlap in what they detect is minimal, so it’s beneficial to use both of them.
This script gives you the option to inherit the cppcheck
preset in your dev
preset, enabling the CMake integration for this tool.
CI will always run cppcheck for you, so it is entirely optional to install and
use it locally, but it is recommended.
For Windows users, if you wish to use cppcheck, then you must install
Ninja and set the generator
field in your dev
preset to Ninja
. The
reason for this is that only Makefiles and Ninja are supported with CMake
for use with cppcheck. For other generators, this feature is a no-op.
Doxygen is a tool to generate documentation from annotated source code.
In conjunction with it, m.css is used for presenting the generated
documentation.
The generated projects will have a docs
target in developer mode, which can
be used to build the documentation into the <binary-dir>/docs/html
directory.
After Doxygen is installed, please make sure the doxygen
executable exists in
the PATH
, otherwise you might get confusing error messages.
This documentation can be deployed to GitHub Pages using the docs
job in the
generated CI workflow. Follow the comments left in the job to enable this.
NOTE: m.css does not work with Doxygen >= 1.9. You can install 1.8.20 to
use the docs
target. See issues #41 and #48.
LCOV is a tool to process coverage info generated by executables that
were instrumented with GCC’s gcov
. This coverage info can be used to see what
parts of the program were executed.
The generated projects will have a coverage
target in developer mode if theENABLE_COVERAGE
variable is enabled. The reason why a separate target is used
instead of CTest’s built-in coverage
step is because it lacks necessary
customization. This target should be run after the tests and by default it will
generate a report at <binary-dir>/coverage.info
and an HTML report at the<binary-dir>/coverage_html
directory.
For Windows users, you may use a similar tool called OpenCppCoverage,
for which there is an example script in the generated cmake
directory. This
script is left as an example, because the Linux VM launches and runs faster in
GitHub Actions and so it is used for coverage submission.
clang-format is part of the LLVM tool suite similar to
clang-tidy. It’s a code linter and code formatter, which can be
used to enforce style guides.
Two targets are made available to check and fix code in developer mode using
the format-check
and format-fix
targets respectively.
NOTE: the project generates files that are formatted according to
clang-format 18. Newer or older versions may format the project differently.
codespell is a tool to find and fix spelling errors mainly in source
code.
Two targets are made available to check and fix spelling errors in developer
mode using the spell-check
and spell-fix
targets respectively.
The -p
flag can be used to select a package manager for the project.
Arguments for the flag can be:
When using a package manager, the following packages are used in the generated
project:
Make sure to read the generated HACKING document to see what needs to be done
to fetch dependencies.
cmake-init [--c] <path>
-s
, -e
or-h
flags after to quickly create a shared library, executable or a header--c
switch will set the generated project’scmake-init --help
cmake-init
is Free Software: You can use, study, share and improve it at your
will. Specifically you can redistribute and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
The contents of the directory cmake-init/templates
are licensed using the
Unlicense license. See the license in that directory for further details.