{"id":15136952,"url":"https://github.com/zackmason/cpp_init","last_synced_at":"2026-02-04T02:39:12.883Z","repository":{"id":77527104,"uuid":"499289649","full_name":"ZackMason/cpp_init","owner":"ZackMason","description":"A crossplatform python script for creating templates of c/cpp projects that use cmake, with options for adding conan libraries and code templates","archived":false,"fork":false,"pushed_at":"2022-06-06T23:50:10.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T03:45:30.026Z","etag":null,"topics":["c","cmake","conan","cpp"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ZackMason.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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-02T21:01:23.000Z","updated_at":"2022-06-06T23:48:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"4036adf4-6ea6-43a3-9d74-9d37f5173aeb","html_url":"https://github.com/ZackMason/cpp_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/ZackMason%2Fcpp_init","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackMason%2Fcpp_init/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackMason%2Fcpp_init/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackMason%2Fcpp_init/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZackMason","download_url":"https://codeload.github.com/ZackMason/cpp_init/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430835,"owners_count":20937873,"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","cmake","conan","cpp"],"created_at":"2024-09-26T06:42:05.540Z","updated_at":"2026-02-04T02:39:12.852Z","avatar_url":"https://github.com/ZackMason.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpp_init\nA crossplatform python script for creating templates of c/cpp projects that use cmake, with options for adding conan libraries and code templates\n\nyou can expand much of the functionality by creating templates in ```~/.cpp_init/templates``` and setting the path in ```~/.cpp_init/config.yaml``` (more info below)\n\nright now there are only options for creating executable projects\nI plan on adding static libs and dynamic libs later\n\nThe default unit testing template for cpp requires cpp 20, if you are using an earlier version you need to write your own template\n\n## setup\n\nif you don't have ```pyyaml``` installed then run\n```\npython3 -m pip install --user pyyaml\n```\nor whatever your alias for python3 is\n\ninstall dependancies if you don't already have them\n+ cmake - https://cmake.org/\n+ conan (optional) - https://conan.io/ \n\nclone the repo\n\n```\ngit clone https://github.com/ZackMason/cpp_init\n```\n\nadd the directory to your PATH and open a new shell\n\nif you are on linux you might want to add a shebang to the top of ```cpp_init.py``` so bash knows where to find python3, idk I use windows\n\nif you are on windows make sure the default program to launch .py files is python3\n\nrun \n```\ncpp_init.py\n```\n\nthis will create ```~/.cpp_init/``` which holds the config file and a directory where you can store your templates\n\nconfig example (this will be expanded to have multiple profiles soon)\n\n```\nhpp_template: hpp_template.txt\ncpp_template: cpp_template.txt\ncpp_version_template: default\nc_version_template:   default\ncmake_template: default\ncmake_tests_template: default\nprologue: prologue.txt\nepilogue: none\ntypes_hpp_template: default\ncore_hpp_template: default\ntests_cpp_template: fmt_tests.cpp\ntests_c_template: default\nmain_cpp_template: main_cpp_template.txt\nmain_c_template: default\ncmake_version: default\n```\n\nnotice the use of ```none``` in ```epilogue``` which will use an empty string in its place, this is different than default which\nwill use my default templates.\n\n## Usage\n```\nusage: cpp_init.py [-h] [--create-project CREATE_PROJECT] [--languages LANGUAGES [LANGUAGES ...]] [--cpp-version CPP_VERSION]\n                   [--c-version C_VERSION] [--use-conan] [--unit-testing] [--no-vscode] [--create-class CREATE_CLASS [CREATE_CLASS ...]]    \n                   [--create-code CREATE_CODE [CREATE_CODE ...]] [--create-header CREATE_HEADER [CREATE_HEADER ...]]\n                   [--create-source CREATE_SOURCE [CREATE_SOURCE ...]]\n\noptions:\n  -h, --help            show this help message and exit\n  --create-project CREATE_PROJECT\n                        Create a cpp project in the current directory\n  --languages LANGUAGES [LANGUAGES ...]\n                        The languages used by the project\n  --cpp-version CPP_VERSION\n                        The cpp version to use\n  --c-version C_VERSION\n                        The c version to use\n  --use-conan           Using conan package manager\n  --unit-testing        Creates a seperate executable for unit testing\n  --no-vscode           Turns off the generator for .vscode/settings.json\n  --create-class CREATE_CLASS [CREATE_CLASS ...]\n                        Create a cpp and hpp file with boilerplate filled out, expects that you are in the root of your project\n  --create-code CREATE_CODE [CREATE_CODE ...]\n                        Create a c and h file with boilerplate filled out, expects that you are in the root of your project\n  --create-header CREATE_HEADER [CREATE_HEADER ...]\n                        Create an h file with boilerplate filled out, expects that you are in the root of your project\n  --create-source CREATE_SOURCE [CREATE_SOURCE ...]\n                        Create a c file with boilerplate filled out, expects that you are in the root of your project\n```\n\n\n## Creating and Building your project\n\nrun \n```\ncpp_init.py --create-project example --use-conan --languages CXX C --cpp-version 20 --unit-testing \n```\nif you don't want to use conan you can omit the ```--use-conan``` flag\n\nif there are dependancies that you need to use then add them to ```conanfile.txt```\n```\ncd example/build\nconan install .. -s build_type=%TYPE% // conan should give you instructions if something goes wrong here, most likely you need to --build\ncmake ..\ncmake --build . --config %TYPE% (for msvc specify build type, not needed on others I think??)\n```\n\n```cmake ..``` could also be replaced with\n```\ncmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%TYPE%\n```\nexample\n```\nconan install .. -s build_type=Release\ncmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release\ncmake --build . --config Release\n```\n\n## Example Templates\n\nc-style header\n```\n#ifndef %^^CODE_NAME%_H\n#define %^^CODE_NAME%_H\n\ntypedef struct %CODE_NAME%_t {\n\n} %CODE_NAME%_t;\n\n#endif /* %^^CODE_NAME%_H */\n```\n\n```%^^CODE_NAME%``` will capitalize all letters in the name passed into ```--create-code``` whereas\n```%^CODE_NAME%``` will only capitalize the first letter\n\n---\n\nc-style source\n```\n#include \"%HEADER_PATH%\"\n```\n\n---\n\ncpp-style header\n\ncpp style templates are created using ```--create-class```\n\n```\n#pragma once\n\nstruct %CLASS_NAME%_t {\n\n};\n```\n\n```%CODE_NAME%``` and ```%CLASS_NAME%``` are actually equivalent \n\nthe command ```cpp_init.py --create-class Graphics/window``` using the above template will produce \n\n```\n#pragma once\n\nstruct window_t {\n\n};\n```\n\n---\ntemplate header\n```\n#pragma once\n\ntemplate\u003ctypename T\u003e\nstruct %CLASS_NAME%_t {\n  T\u0026 get() const;\n  T value;\n};\n\n#include \"%SOURCE_PATH%\"\n\n```\n\n---\n\nprologue\n```\n// Author: Zackery Mason-Blaug\n// Date: %DATE%\n//////////////////////////////////////////////////////////\n\n```\n\n---\n\ndefault CMakeLists.txt\n```\ncmake_minimum_required(VERSION %CMAKE_VERSION%)\nproject(%PROJECT_NAME% %LANGUAGES%)\n\n%CPP_VERSION%\n%C_VERSION%\n\n%CONAN_SETUP%\n\nfile(GLOB_RECURSE src_files \n    ${PROJECT_SOURCE_DIR}/src/*.c*\n)\n\ninclude_directories(include)\n\nadd_executable(${PROJECT_NAME} ${src_files})\ntarget_compile_definitions(${PROJECT_NAME} PUBLIC CMAKE_ASSETS_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/assets/\")\n\n%CMAKE_TESTS%\n%CONAN_LINK%\n```\n\n---\n## TODO - feel free to help :)\n\n+ add vcpkg support\n+ multiple profiles in config.yaml\n+ emscripten support\n+ user defined project layout\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackmason%2Fcpp_init","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackmason%2Fcpp_init","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackmason%2Fcpp_init/lists"}