{"id":13419076,"url":"https://github.com/cginternals/cmake-init","last_synced_at":"2025-05-14T21:11:08.722Z","repository":{"id":13285703,"uuid":"15971519","full_name":"cginternals/cmake-init","owner":"cginternals","description":"Template for reliable, cross-platform C++ project setup using cmake.","archived":false,"fork":false,"pushed_at":"2025-04-11T16:23:07.000Z","size":2497,"stargazers_count":920,"open_issues_count":23,"forks_count":117,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-04-12T08:16:04.787Z","etag":null,"topics":["c-plus-plus","c-plus-plus-11","cmake","template"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cginternals.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-01-16T15:19:15.000Z","updated_at":"2025-04-11T16:23:01.000Z","dependencies_parsed_at":"2022-07-26T04:32:08.358Z","dependency_job_id":"833a0592-eca7-430c-a34d-963995dc4706","html_url":"https://github.com/cginternals/cmake-init","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cginternals%2Fcmake-init","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cginternals%2Fcmake-init/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cginternals%2Fcmake-init/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cginternals%2Fcmake-init/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cginternals","download_url":"https://codeload.github.com/cginternals/cmake-init/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227631,"owners_count":22035671,"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":["c-plus-plus","c-plus-plus-11","cmake","template"],"created_at":"2024-07-30T22:01:10.990Z","updated_at":"2025-05-14T21:11:08.701Z","avatar_url":"https://github.com/cginternals.png","language":"CMake","readme":"\n\u003cbr\u003e\u003ca href=\"https://github.com/cginternals/cmake-init/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/cginternals/cmake-init/master/cmake-init-logo.svg?sanitize=true\" width=\"50%\"\u003e\u003c/a\u003e\n\nThe C++ CMake Project Template\n\n[![Travis](https://img.shields.io/travis/cginternals/cmake-init/master.svg?style=flat\u0026logo=travis)](https://travis-ci.org/cginternals/cmake-init)\n[![Appveyor](https://img.shields.io/appveyor/ci/scheibel/cmake-init/master.svg?style=flat\u0026logo=appveyor)](https://ci.appveyor.com/project/scheibel/cmake-init/branch/master)\n[![Tokei](https://tokei.rs/b1/github/cginternals/cmake-init)](https://github.com/Aaronepower/tokei)\n[![Setup Guide](https://img.shields.io/badge/cmake%20guide-wiki-blue.svg?style=flat)](https://github.com/cginternals/cmake-init/wiki/Setup-Guide)\n\n\n*cmake-init* is a sophisticated copy \u0026 paste template for modern C and C++ projects.\nThe main goals include support of all use cases around software development (programming, testing, Q\u0026A, deployment, documentation) while being modular, flexible, and idiomatic. *cmake-init* is therefore a collection of cmake best-practices.\n\nThe main target platforms are typical desktop, laptop, and server platforms. Currently supported are:\n\n* Windows\n* macOS\n* GNU/Linux\n\nHowever, other UNIX versions may work as well if they are supported by CMake.\n\nThe cmake-init template assumes you want to setup a project using\n* CMake (3.20 or above)\n* C/C++ compiler\n\n\n# Contents\n\n* [Usage](#usage)\n  * [Adaption Guide](#adaption-guide)\n* [Non-Goals](#non-goals)\n* [Module Documentation](#module-documentation)\n  * [Core Modules](#core-modules)\n    * [CMake Initialization](#cmake-initialization)\n    * [CMake Backward Compatibility](#cmake-backward-compatability)\n    * [Project Meta Information](#project-meta-information)\n    * [Project Meta Information Code Generation](#project-meta-information-code-generation)\n    * [Project Build Options](#project-build-options)\n  * [Maintainer Modules](#maintainer-modules)\n    * [cmake-init Template Check](#cmake-init-template-check)\n  * [Development Modules](#development-modules)\n    * [Version Control System Integration](#version-control-system-integration)\n    * [Build Targets](#build-targets)\n    * [Documentation](#documentation)\n    * [Tests](#tests)\n    * [Linter](#linter)\n    * [Continuous Integration](#continuous-integration)\n    * [Deployment](#deployment)\n    * [Packaging](#packaging)\n    * [Run-time Assets](#run-time-assets)\n\n# Usage\n\nThe intended use of the template is a copy of the current version with a subsequent replacement of project names and customization of modules to your needs. This is documented within the [adaption guide](#adaption-guide).\nAnother approach is the initialization of a new CMake project where the required features are adopted from cmake-init. We propose the former workflow.\n\nConcluding, a new project should contain the core modules and, as needed, add the maintainer and development modules as required. All modules are designed in a way that they can be excluded. The process of integration or removal of a module/feature is documented with each module.\n\n## Adaption Guide\n\nThe file [ADAPT.md](https://github.com/cginternals/cmake-init/blob/master/ADAPT.md) contains a task checklist for new projects. Your start with a copy of cmake-init and process each item from the checklist, adjusting the template to your needs.\n\n## Update\n\nAfter some time working on a project, cmake-init may be updated and you want to integrate the changes.\nFor an overview of changes we suggest to use the [cmake-init Template Check](#cmake-init-template-check) module.\nAlternatively, you can update the required modules selectively.\n\n\n\n# Non-Goals\n\nIn order to be usable in a deterministic, idiomatic fashion, cmake-init avoids the following approaches and features:\n\n## Super-Build\n\nDue to the current semantics of targets and CMake internals, combining multiple\ncmake-init projects into one super-build project is not officially supported.\nThere are limited and restricting workarounds.\nActual solution: treat each project separately and use explicit dependency management.\n\n## High Abstraction\n\nWe use low abstractions to not build a language upon CMake a user has to learn.\n\n## File Glob\n\nExplicit source specification prevents erroneous cases when adding and removing\nsources from the project tree.\n\n# Module Documentation\n\n## Core Modules\n\n### CMake Initialization\n\nAs with most CMake projects, cmake-init initializes the CMake environment. This includes the minimum required CMake version,\n\n```cmake\n# CMake version\ncmake_minimum_required(VERSION 3.20 FATAL_ERROR)\n```\n\nrequired policies,\n\n```cmake\n# Set policies\nset_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted.\nset_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.\nset_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types.\n```\n\nadaption of the cmake module path,\n\n```cmake\n# Include cmake modules\nlist(APPEND CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake\")\n```\n\nand an include of default modules that are typically required for each project.\n\n```cpp\ninclude(GenerateExportHeader)\ninclude(WriteCompilerDetectionHeader)\n```\n\n### Project Meta Information\n\nThe declaration of project-wide information--that are used, e.g., within documentation, testing, and deployment--, is combined within the project meta information section in the main `CMakeLists.txt`.\n\n```cmake\n#\n# Project description and (meta) information\n#\n\n# Meta information about the project\nset(META_PROJECT_NAME        \"template\")\nset(META_PROJECT_DESCRIPTION \"CMake Project Template\")\nset(META_AUTHOR_ORGANIZATION \"CG Internals GmbH\")\nset(META_AUTHOR_DOMAIN       \"https://github.com/cginternals/cmake-init/\")\nset(META_AUTHOR_MAINTAINER   \"opensource@cginternals.com\")\nset(META_VERSION_MAJOR       \"2\")\nset(META_VERSION_MINOR       \"0\")\nset(META_VERSION_PATCH       \"0\")\nset(META_VERSION_REVISION    \"\u003cREVISION\u003e\")\nset(META_VERSION             \"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}\")\nset(META_NAME_VERSION        \"${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})\")\nset(META_CMAKE_INIT_SHA      \"\u003cCMAKE_INIT_REVISION\u003e\")\n\nstring(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)\nstring(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)\n```\n\n*cmake-init* supports the projects name, description, organization, domain, and maintainer email as well as detailed version information. For the version, we suggest to use [semantic versioning](https://semver.org/).\nDepending on your version control system, you may want to integrate the current revision of the software as well: see [Version Control System Integration](#version-control-system-integration). If you use the [cmake-init Template Check](#cmake-init-template-check) module, the cmake-init SHA is declared within this section, too.\n\nLast, *cmake-init* derives a project ID that complies with the naming schemes of C to be used within auto-generated and derived source code content (e.g., macro identifiers).\n\n\n### Project Meta Information Code Generation\n\nThe result of this module is the generation of a C header file that propagates the project meta information to your C and C++ projects.\nFor this, the CMake file configuration feature is used on the `version.h.in` header template.\n\n```c\n#define @META_PROJECT_ID@_PROJECT_NAME        \"@META_PROJECT_NAME@\"\n#define @META_PROJECT_ID@_PROJECT_DESCRIPTION \"@META_PROJECT_DESCRIPTION@\"\n\n#define @META_PROJECT_ID@_AUTHOR_ORGANIZATION \"@META_AUTHOR_ORGANIZATION@\"\n#define @META_PROJECT_ID@_AUTHOR_DOMAIN       \"@META_AUTHOR_DOMAIN@\"\n#define @META_PROJECT_ID@_AUTHOR_MAINTAINER   \"@META_AUTHOR_MAINTAINER@\"\n\n#define @META_PROJECT_ID@_VERSION_MAJOR       \"@META_VERSION_MAJOR@\"\n#define @META_PROJECT_ID@_VERSION_MINOR       \"@META_VERSION_MINOR@\"\n#define @META_PROJECT_ID@_VERSION_PATCH       \"@META_VERSION_PATCH@\"\n#define @META_PROJECT_ID@_VERSION_REVISION    \"@META_VERSION_REVISION@\"\n\n#define @META_PROJECT_ID@_VERSION             \"@META_VERSION@\"\n#define @META_PROJECT_ID@_NAME_VERSION        \"@META_NAME_VERSION@\"\n```\n\nThe template file is configured with the project meta information and the result is stored within the build directory. Beware that this header is stored in a path derived from your project name. You should adopt this as required.\n\n```cmake\n# Generate version-header\nconfigure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME}/${META_PROJECT_NAME}-version.h)\n```\n\nWe suggest to deploy this header disregarding its internal or even public use.\n\n```cmake\n#\n# Deployment\n#\n\n# Deploy generated headers\ninstall(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME} DESTINATION include COMPONENT dev)\n```\n\n\n### Project Build Options\n\n## Maintainer Modules\n\n### cmake-init Template Check\n\nThis module allows to check the actuality of the used cmake-init template for own projects.\nThis module is usable when the following is integrated into the `CMakeLists.txt`.\n\n```cmake\n# Add cmake-init template check cmake targets\nadd_check_template_target(\u003cCMAKE_INIT_SHA\u003e \u003cCMAKE_INIT_BRANCH\u003e)\n```\n\nHere, the `\u003cCMAKE_INIT_SHA\u003e` contains the git hash of the used cmake-init template.\nFurther, the files `cmake/HealthCheck.cmake` and `cmake/CheckTemplate.cmake` are required.\n\nThe hash is usually configured using\n\n```cmake\n# Meta information about the project\nset(META_CMAKE_INIT_SHA      \"\u003cCMAKE_INIT_SHA\u003e\")\nset(META_CMAKE_INIT_BRANCH   \"\u003cCMAKE_INIT_BRANCH\u003e\")\n\n# Add cmake-init template check cmake targets\nadd_check_template_target(\u003cCMAKE_INIT_SHA\u003e \u003cCMAKE_INIT_BRANCH\u003e)\n```\n\nCorrectly configures, this module adds a cmake build target named `check-template` that compares the passed `\u003cCMAKE_INIT_SHA\u003e` with the current master commit hash of this repository and provides a link for a diff view.\n\n## Development Modules\n\n### Version Control System Integration\n\n```cmake\n# Get git revision\nget_git_head_revision(GIT_REFSPEC GIT_SHA1)\nstring(SUBSTRING \"${GIT_SHA1}\" 0 12 GIT_REV)\nif(NOT GIT_SHA1)\n    set(GIT_REV \"0\")\nendif()\n```\n\n### Build Targets\n\n### Documentation\n\n### Tests\n\nTests are available using the Google testing frameworks `googletest` and `googlemock`.\ncmake-init assumes an external installment of both frameworks.\nTypically, package managers of each system provides a sufficient installment.\nFor example, on Ubuntu you can install the `libgmock-dev` package.\nOn macOS using Homebrew, this package is named `googletest\n\n### Linter\n\n### Continuous Integration\n\n### Deployment\n\n### Packaging\n\n### Run-time Assets\n","funding_links":[],"categories":["TODO scan for Android support in followings","Cmake","Examples / Templates"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcginternals%2Fcmake-init","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcginternals%2Fcmake-init","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcginternals%2Fcmake-init/lists"}