{"id":16576186,"url":"https://github.com/emersonmello/libprg","last_synced_at":"2025-04-13T18:20:52.883Z","repository":{"id":179546008,"uuid":"663641998","full_name":"emersonmello/libprg","owner":"emersonmello","description":"A minimal C library template using Modern CMake","archived":false,"fork":false,"pushed_at":"2023-10-24T16:50:23.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":21,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T09:04:04.606Z","etag":null,"topics":["c","cmake","cmake-examples","library","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/emersonmello.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":"2023-07-07T19:18:36.000Z","updated_at":"2024-03-31T14:14:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"21e22ce5-31f6-4423-a352-9eb861ef220e","html_url":"https://github.com/emersonmello/libprg","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"5c913ec216e7c101b7852c083d907a494afbcc5a"},"previous_names":["emersonmello/libprg"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emersonmello%2Flibprg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emersonmello%2Flibprg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emersonmello%2Flibprg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emersonmello%2Flibprg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emersonmello","download_url":"https://codeload.github.com/emersonmello/libprg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758878,"owners_count":21157047,"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","cmake-examples","library","template"],"created_at":"2024-10-11T22:07:27.353Z","updated_at":"2025-04-13T18:20:52.858Z","avatar_url":"https://github.com/emersonmello.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A minimal C library template using Modern CMake\n\nAn example to demonstrate how to organize files for writing a library in the C language using Modern CMake.\n\n## Project structure\n\n```bash\n.\n|-- CMakeLists.txt\n|-- LICENSE\n|-- Readme.md\n`-- libprg\n    |-- CMakeLists.txt\n    `-- src\n        |-- include\n        |   `-- libprg\n        |       `-- libprg.h\n        `-- libprg\n            |-- libprg.c\n            |-- sub.c\n            `-- sum.c\n```\n\n## How to use this library in a C application using CMake\n\nCMake [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) can download this library directly from his GitHub repository and you must indicate from which branch or tag. In this example I will use the `main` branch or the `0.0.1` tag.\n\nCreate a new project (C executable) using CMake and your `CMakeLists.txt` file should look like this:\n\n```cmake\ncmake_minimum_required(VERSION 3.21)\nproject(myapp C)\n\nset(CMAKE_C_STANDARD 17)\n\ninclude(FetchContent)\n\nFetchContent_Declare(\n    libprg\n    GIT_REPOSITORY https://github.com/emersonmello/libprg.git\n    GIT_TAG origin/main \n    # or GIT_TAG 0.0.1\n    \n    # You can reference a local directory instead\n    # URL file:///${CMAKE_CURRENT_SOURCE_DIR}/../libprg\n)\nFetchContent_MakeAvailable(libprg)\n\nadd_executable(myapp main.c)\n\n# linking libprg\ntarget_link_libraries(myapp PUBLIC libprg)\n```\n\nAnd your `main.c`  should look like this:\n```c\n#include \u003cstdio.h\u003e\n#include \u003clibprg/libprg.h\u003e\n\nint main(void) {\n    int a = 1, b = 2;\n\n    result_t r = compute(a, b, SUM);\n    printf(\"%d + %d = %8.2f\", a, b, r.value);\n\n    return 0;\n}\n```\n\n# References\n\n- https://cliutils.gitlab.io/modern-cmake/\n- https://blog.feabhas.com/2021/08/cmake-part-3-source-file-organisation/\n- https://iakko.medium.com/creating-a-c-shared-library-with-cmake-50c6d2f97ee8\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femersonmello%2Flibprg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femersonmello%2Flibprg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femersonmello%2Flibprg/lists"}