{"id":16692692,"url":"https://github.com/izvolov/mylib","last_synced_at":"2025-07-16T23:35:25.760Z","repository":{"id":36236947,"uuid":"199146008","full_name":"izvolov/mylib","owner":"izvolov","description":"Шаблон кросплатформенного CMake-проекта для языка C++ 🇬🇧 Modern CMake crossplatform project template for C++","archived":false,"fork":false,"pushed_at":"2022-07-25T22:08:18.000Z","size":122,"stargazers_count":66,"open_issues_count":3,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T23:41:18.095Z","etag":null,"topics":["ci","cmake","coverage","cplusplus","cpp","crossplatform","doxygen","github-actions","static-analysis","template"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izvolov.png","metadata":{"files":{"readme":"README.en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-27T09:45:59.000Z","updated_at":"2025-03-23T09:30:33.000Z","dependencies_parsed_at":"2022-07-25T19:48:42.809Z","dependency_job_id":null,"html_url":"https://github.com/izvolov/mylib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izvolov/mylib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izvolov%2Fmylib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izvolov%2Fmylib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izvolov%2Fmylib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izvolov%2Fmylib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izvolov","download_url":"https://codeload.github.com/izvolov/mylib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izvolov%2Fmylib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265550417,"owners_count":23786565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","cmake","coverage","cplusplus","cpp","crossplatform","doxygen","github-actions","static-analysis","template"],"created_at":"2024-10-12T16:28:07.979Z","updated_at":"2025-07-16T23:35:25.741Z","avatar_url":"https://github.com/izvolov.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"[:ru: Оригинал](README.md)\n\nCMake-based template for C++ project\n====================================\n\nClone, replace \"Mylib\" with the desired name, and it's done.\n\nOr generate a new project with a script: https://github.com/izvolov/mylib-gen/blob/master/README.en.md\n\nContents\n--------\n\n1.  [Build](#build)\n    1.  [Generate a build system](#generate-a-build-system)\n    2.  [Build a project](#build-a-project)\n2.  [Options](#options)\n    1.  [MYLIB_COVERAGE](#MYLIB_COVERAGE)\n    2.  [MYLIB_TESTING](#MYLIB_TESTING)\n    3.  [DOXYGEN_OUTPUT_LANGUAGE](#DOXYGEN_OUTPUT_LANGUAGE)\n3.  [Targets](#targets)\n    1.  [Default](#default)\n    2.  [mylib_library](#mylib_library)\n    3.  [mylib-unit-tests](#mylib-unit-tests)\n    4.  [check](#check)\n    5.  [coverage](#coverage)\n    6.  [doc](#doc)\n    7.  [wandbox](#wandbox)\n4.  [Examples](#examples)\n5.  [Usage](#usage)\n    1.  [Through the installation](#through-the-installation)\n    2.  [As a submodule](#as-a-submodule)\n6.  [Tools](#tools)\n7.  [Bonus](#bonus)\n\nBuild\n-----\n\nBuilding this project, like any other CMake project, consists of two stages:\n\n### Generate a build system\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory [options ...]\n```\n\n[More about options](#options).\n\n### Build a project\n\n```shell\ncmake --build path/to/build/directory [--target target]\n```\n\n[More about targets](#targets).\n\nOptions\n-------\n\n### MYLIB_COVERAGE\n\n```shell\ncmake -S ... -B ... -DMYLIB_COVERAGE=ON [other options ...]\n```\n\nTurns on the [`coverage`](#coverage) target which performs code coverage measurement.\n\n### MYLIB_TESTING\n\n```shell\ncmake -S ... -B ... -DMYLIB_TESTING=OFF [other options ...]\n```\n\nProvides the ability to turn off unit testing and hence the [`check`](#check) target. As a result, the code coverage measurement is also turned off (see [Code coverage](#MYLIB_COVERAGE)).\n\nAlso, testing is automatically disabled if the project is included to another project as a subproject using the [`add_subdirectory`](https://cmake.org/cmake/help/v3.14/command/add_subdirectory.html) command.\n\n### DOXYGEN_OUTPUT_LANGUAGE\n\n```shell\ncmake -S ... -B ... -DDOXYGEN_OUTPUT_LANGUAGE=English [other options ...]\n```\n\nSwitches the language of the documentation generated by the [`doc`](#doc) target. For a list of available languages, see [Doxygen site](http://www.doxygen.nl/manual/config.html#cfg_output_language).\n\nDefault language is Russian.\n\nTargets\n-------\n\n### Default\n\n```shell\ncmake --build path/to/build/directory\ncmake --build path/to/build/directory --target all\n```\n\nIf a target is not specified (which is equivalent to the `all` target), it builds everything possible including unit tests and also calls the [`check`](#check) target.\n\n### mylib_library\n\n```shell\ncmake --build path/to/build/directory --target mylib_library\n```\n\nCompiles the `mylib_library` library. Enabled by default.\n\n### mylib-unit-tests\n\n```shell\ncmake --build path/to/build/directory --target mylib-unit-tests\n```\n\nBuilds unit tests. Enabled by default.\n\n### check\n\n```shell\ncmake --build path/to/build/directory --target check\n```\n\nLaunches built (and builds if not yet) unit tests. Enabled by default.\n\nSee also [`mylib-unit-tests`](#mylib-unit-tests).\n\n### coverage\n\n```shell\ncmake --build path/to/build/directory --target coverage\n```\n\nAnalyzes run unit tests (and runs is not yet) using [gcovr](https://gcovr.com).\n\nTarget is only available if [`MYLIB_COVERAGE`](#MYLIB_COVERAGE) option is on.\n\nSee also [`check`](#check).\n\n### doc\n\n```shell\ncmake --build path/to/build/directory --target doc\n```\n\nGenerates source code documentation using [Doxygen](http://doxygen.nl).\n\n### wandbox\n\n```shell\ncmake --build path/to/build/directory --target wandbox\n```\n\nThe [Wandbox](https://wandbox.org) service is used. Please, don't abuse it.\n\nExamples\n--------\n\n#### Building the project in the debug mode and measure a coverage\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory -DCMAKE_BUILD_TYPE=Debug -DMYLIB_COVERAGE=ON\ncmake --build path/to/build/directory --target coverage --parallel 16\n```\n\n#### Installing the project without building and testing it\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory -DMYLIB_TESTING=OFF -DCMAKE_INSTALL_PREFIX=path/to/install/directory\ncmake --build path/to/build/directory --target install\n```\n\n#### Building the project in the release mode with a specified compiler\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_PREFIX_PATH=path/to/installed/dependencies\ncmake --build path/to/build/directory --parallel 4\n```\n\n#### Generating the documentation in English\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory -DCMAKE_BUILD_TYPE=Release -DDOXYGEN_OUTPUT_LANGUAGE=English\ncmake --build path/to/build/directory --target doc\n```\n\nUsage\n-----\n\n### Through the installation\n\nOne of the ways to use the module is to install it into the system.\n\n```shell\ncmake --build path/to/build/directory --target install\n```\n\nAfter that, all the libraries from the `Mylib::` namespace can be used from any other project using the [`find_package`](https://cmake.org/cmake/help/v3.14/command/find_package.html) command:\n\n```cmake\nfind_package(Mylib 1.0 REQUIRED)\n\nadd_executable(some_executable some.cpp sources.cpp)\ntarget_link_libraries(some_executable PRIVATE Mylib::library)\n```\n\n`Mylib::headers` library is used for the headers only, and `Mylib::library` library is used when it is also needed to link with the `libmylib_library` library.\n\n### As a submodule\n\nThe project can also be used by another project as a submodule using the [`add_subdirectory`](https://cmake.org/cmake/help/v3.14/command/add_subdirectory.html) command:\n\nIn this case, libraries `Mylib::library` and `Mylib::headers` will be available in the same manner.\n\nTools\n-----\n\n1.  [CMake](https://cmake.org) 3.14\n\n    CMake 3.14 is required because of incorrect work of the command `install(TARGETS ... EXPORT ...)`: is does not set default install paths properly.\n\n2.  [doctest](https://github.com/onqtam/doctest) testing framework\n\n    Testing might be turned off (see [Testing](#MYLIB_TESTING)).\n\n3.  [Doxygen](http://doxygen.nl)\n\n    Switching the language of the generated documentation is provided by the [`DOXYGEN_OUTPUT_LANGUAGE`](#DOXYGEN_OUTPUT_LANGUAGE) option.\n\n4.  [Python 3](https://www.python.org) interpreter\n\n    Used to generate an [online sandbox](#wandbox).\n\nBonus\n-----\n\nWith CMake and a couple of good tools, you can get a static analysis with minimal effort.\n\n### Cppcheck\n\nCMake has build-in support for [Cppcheck](http://cppcheck.sourceforge.net).\n\nIt is provided by the [`CMAKE_CXX_CPPCHECK`](https://cmake.org/cmake/help/v3.14/variable/CMAKE_LANG_CPPCHECK.html#variable:CMAKE_\u003cLANG\u003e_CPPCHECK) option:\n\n```shell\ncmake -S path/to/sources -B path/to/build/directory -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_CPPCHECK=\"cppcheck;--enable=all;-Ipath/to/sources/include\"\n```\n\nAfter that, static analysis will be automatically run every time the source code is compiled and recompiled.\n\n### Clang\n\nWith [`scan-build`](https://clang-analyzer.llvm.org/scan-build) you can run static analysis easily, too:\n\n```shell\nscan-build cmake -S path/to/sources -B path/to/build/directory -DCMAKE_BUILD_TYPE=Debug\nscan-build cmake --build path/to/build/directory\n```\n\nHere, unlike the case of [Cppcheck](#cppcheck) it is required to build the project using `scan-build` each time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizvolov%2Fmylib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizvolov%2Fmylib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizvolov%2Fmylib/lists"}