{"id":19878538,"url":"https://github.com/dezashibi-c/cmake_template","last_synced_at":"2026-05-05T08:33:05.194Z","repository":{"id":254672573,"uuid":"847220108","full_name":"dezashibi-c/cmake_template","owner":"dezashibi-c","description":"A very beginner friendly cmake template for c projects with unit testing","archived":false,"fork":false,"pushed_at":"2024-11-13T05:13:55.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-25T12:43:39.257Z","etag":null,"topics":["c","cmake","gcc","linux","msvc","osx","template","unit-testing","windows"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dezashibi-c.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,"zenodo":null}},"created_at":"2024-08-25T07:29:12.000Z","updated_at":"2024-11-13T05:13:59.000Z","dependencies_parsed_at":"2024-09-10T15:31:37.208Z","dependency_job_id":"574ca3a2-62b6-477e-948b-03891880ed68","html_url":"https://github.com/dezashibi-c/cmake_template","commit_stats":null,"previous_names":["dezashibi-c/b-cmake_template","dezashibi-c/cmake_template"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/dezashibi-c/cmake_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dezashibi-c%2Fcmake_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dezashibi-c%2Fcmake_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dezashibi-c%2Fcmake_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dezashibi-c%2Fcmake_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dezashibi-c","download_url":"https://codeload.github.com/dezashibi-c/cmake_template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dezashibi-c%2Fcmake_template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32642007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"online","status_checked_at":"2026-05-05T02:00:06.033Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","gcc","linux","msvc","osx","template","unit-testing","windows"],"created_at":"2024-11-12T17:05:53.388Z","updated_at":"2026-05-05T08:33:05.180Z","avatar_url":"https://github.com/dezashibi-c.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CMake Template\n\nThis is a beginner friendly `cmake` for `C` projects. while it's not by all means the **\"best\"** approach but it's clearly crafted together and commented for you to be able to adjust it to your needs.\n\n## Structure\n\n- `cmake` any utility and re-usable files for your cmakes goes here.\n- `extern` folder is where you put your external dependencies, as an example I have used `clove-unit` library for unit testing.\n- `include` is where you put your exported header files.\n- `src` is where your `.c` files must be placed.\n- `tests` are written using `clove-unit` framework which is a lightweight and single header library.\n\n**👉 NOTE:** You can refer to [here](https://github.com/fdefelici/clove-unit) for more information about `clove-unit`.\n\n**👉 NOTE:** There is also `.clang-format` available for you to use.\n\n**👉 NOTE:** All the build artifacts will be placed in `out` folder, all the build artifacts for tests will be placed in `out_tests` folder.\n\n## `CMakeLists.txt` files\n\nBy reading their source codes as they are fully commented you can understand pretty much everything you need.\n\nBut the main workflow of using this template is like this:\n\n- in main `CMakeLists.txt`:\n  1. Rename project name  in [line 12](/CMakeLists.txt#L12).\n  2. Rename your desired executable file `main_exe_file` on lines [20](/CMakeLists.txt#L20), [25](/CMakeLists.txt#L25), [37](/CMakeLists.txt#L37) and [46](/CMakeLists.txt#L46).\n  3. Every time you add a new `.c` file you add it in `EXECUTABLE TARGETS` section to one or more of your executable files.\n  4. If you want to add another Target aka. executable or library feel free to repeat what's on lines [20 to 23](/CMakeLists.txt#L20-L23) also make sure to rename the variables to meet your needs.\n  5. In case you want also to enable pre build testing meaning re-building and running tests every time you build certain target look at [line 37](/CMakeLists.txt#L37).\n\n- Testing (`tests/CMakeLists.txt`):\n  1. You create a new `.c` file in `tests` folder, name it like `test_\u003cwhatever\u003e.c`, it's for readability but you don't have to.\n  2. Follow `clove-unit` library guide and write your test.\n  3. use `add_clove_test` with the exact name `test_\u003cwhatever\u003e` without `.c` in `CMakeLists.txt` of `tests` directory to register your test.\n  4. **👉 NOTE:** Make sure to [read the guide](/tests/CMakeLists.txt#L15-L22) in the `tests` folder cmake file.\n\n- Visual Studio Code Users:\n  1. Make sure [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) and [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extensions are installed.\n  2. If you're on Windows and you haven't installed your tools yet, make sure to check out [here](https://github.com/dezashibi-c/b-hello-world?tab=readme-ov-file#portable-development-environment-for-windows-users).\n  3. Just open the folder like normal and let the magic happen.\n\n- CodeBlocks and Visual Studio 2022 Users:\n  1. You need to create corresponding projects first.\n  2. Open terminal in the folder (make sure you've deleted `build` folder if it already exists):\n     1. Enter `cmake -B build -G\"CodeBlocks - Unix Makefiles\"` if you need CodeBlocks project.\n     2. Enter `cmake -B build -G\"Visual Studio 17 2022\"` if you need Visual Studio project.\n  3. Now open up the `build` folder and you can find project or solution for your IDE.\n\n- KDevelop Users just open the folder and the IDE itself recognizes the `CMakeLists.txt` and will guide you through it.\n\n- **Adding Configurations to define macros**:\n\n    You can use `define_macro_option(\u003ctarget name\u003e \u003cmacro name in your code\u003e \u003cdefault value ON/OFF\u003e)` after your executables or libraries. this will add `\u003ctarget name\u003e_ENABLE_\u003cmacro name you've provided\u003e` cmake option.\n\n    **👉 Example:** Checkout [usage example](/CMakeLists.txt#L25) and its corresponding effect in [the main source](/src/main.c#L10-L12).\n\n- **Adding post build file copy**:\n  \n    You can use `define_post_built_copy(\u003ctarget name\u003e \u003crelative destination\u003e \u003cfiles...\u003e)` to enable copying of any files relative to\n    executables or libraries.\n\n    **👉 NOTE:** no `./` is needed in destination, pass `\"\"` if you want the files being copied to the root of the output directory.\n\n    **👉 Example:** Checkout [usage example](/CMakeLists.txt#L42-L44).\n\n## `Raylib` Helper\n\nLooking at the official cmake template of the `raylib` I thought it might be good to add it to my template as well.\n\nAs it is mentioned in the [line 7](/CMakeLists.txt#L7) you can remove that line when your project don't need raylib.\n\nEnabling `raylib` is as simple as just using `enable_raylib_for` command like `enable_raylib_for(game_example)` at [line 31](/CMakeLists.txt#L31).\n\n**👉 NOTE:** To include and manage your resources, use resources folder with a subfolder per game project.\n\n## Resources for learning `CMake`\n\nCheck out [this place](https://cliutils.gitlab.io/modern-cmake/README.html). it's a good book and I highly recommend you to read it if you want to get more into cmake.\n\n## Third-party Libraries\n\n- [Clove-Unit](https://github.com/fdefelici/clove-unit) ([MIT License - Copyright (c) 2021-2024 Federico De Felici](/extern/clove-unit/LICENSE))\n\n## License\n\nBSD 3-Clause License\n\nCopyright (c) 2024, Navid Dezashibi \u003cnavid@dezashibi.com\u003e\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this\n   list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice,\n   this list of conditions and the following disclaimer in the documentation\n   and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holder nor the names of its\n   contributors may be used to endorse or promote products derived from\n   this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdezashibi-c%2Fcmake_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdezashibi-c%2Fcmake_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdezashibi-c%2Fcmake_template/lists"}