{"id":20741809,"url":"https://github.com/copperlight/conan-cmake-protobuf-example","last_synced_at":"2025-08-25T07:37:54.541Z","repository":{"id":186641724,"uuid":"675490045","full_name":"copperlight/conan-cmake-protobuf-example","owner":"copperlight","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-20T20:21:10.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T12:14:23.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/copperlight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-07T03:43:21.000Z","updated_at":"2024-11-20T20:21:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"1e542de0-8d5f-4337-ace9-8928f730b87f","html_url":"https://github.com/copperlight/conan-cmake-protobuf-example","commit_stats":null,"previous_names":["copperlight/conan-cmake-protobuf-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/copperlight/conan-cmake-protobuf-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copperlight%2Fconan-cmake-protobuf-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copperlight%2Fconan-cmake-protobuf-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copperlight%2Fconan-cmake-protobuf-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copperlight%2Fconan-cmake-protobuf-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/copperlight","download_url":"https://codeload.github.com/copperlight/conan-cmake-protobuf-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copperlight%2Fconan-cmake-protobuf-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272025107,"owners_count":24860528,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"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":[],"created_at":"2024-11-17T06:43:06.472Z","updated_at":"2025-08-25T07:37:54.518Z","avatar_url":"https://github.com/copperlight.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/copperlight/conan-cmake-protobuf-example/actions/workflows/build.yml/badge.svg)](https://github.com/copperlight/conan-cmake-protobuf-example/actions/workflows/build.yml)\n\n# Conan 2.X + CMake + Protobuf Build Example\n\nI was trying to figure out how to use [protobuf] with a [Conan] 2.X + [CMake] project, and I found the following blog\npost.\n\n* [C++ Protobuf: Project Setup With Conan and CMake]\n\nThe initial advice to use the [`bincrafters`] distribution is no longer viable, so I had to find another way. The\n2022 edit gets closer to my final solution, but I think my variation here of using [`add_custom_command`] is a bit\nmore clear, because it establishes a direct dependency on the named generated files.\n\nThe `conan install` step builds `protobuf` from source (or uses a pre-built binary fetched from Artifactory), and as\na part of this work, we get a copy of `protoc` built for the current platform and matching the library version.\nAll we need to do is call this binary during the `cmake` build, to generate the files we need.\n\nWith the 2.X version, Conan provides a `tool_requires` configuration and a `conanbuild.sh` file in the build output\ndirectory. The combination of these two things results in modifying the `PATH` to include the binary specified in the\n`tool_requires` configuration. If you need to revert to your previous environment, there is a `deactivate_conanbuild.sh`\nscript.\n\nWith the locally compiled `protoc` binary available on the `PATH`, all we have to do is specify the output locations.\nWe need copies of the generated files in both the source directory and the binary directory.\n\n[CMakeLists.txt#L19-L23](https://github.com/copperlight/conan-cmake-protobuf-example/blob/main/CMakeLists.txt#L21-L25)\n\nAfter building the project, you can test the resulting executable as follows:\n\n```\n./cmake-build/pb-example\n\ncreated proto message with animal:\nspecies: Cat\nname: Tiffany\nage: 12\n```\n\nYou can see this output in the GitHub Actions `build` job under the `Test` step.\n\nThe main caveat here is that this is written for Conan 1.X. At some point, I will need to update this approach for\nConan 2.X. No fancy source directory structure was created here, because there are only two source files, plus the\ngenerated files. This technique can be applied to more complex directory structures, as needed.\n\n[protobuf]: https://conan.io/center/recipes/protobuf?version=5.27.0\n[Conan]: https://conan.io/\n[CMake]: https://cmake.org/\n[C++ Protobuf: Project Setup With Conan and CMake]: https://www.codingwiththomas.com/blog/protobuf-project-setup-with-conan-and-cmake\n[`bincrafters`]: https://bincrafters.github.io/\n[`add_custom_command`]: https://cmake.org/cmake/help/latest/command/add_custom_command.html\n\n## Local \u0026 IDE Configuration\n\n```shell\n# setup python venv and activate, to gain access to conan cli\n./setup-venv.sh\nsource venv/bin/activate\n\n./build.sh  # [clean|clean --confirm|skiptest]\n```\n\n* Install the Conan plugin for CLion.\n    * CLion \u003e Settings \u003e Plugins \u003e Marketplace \u003e Conan \u003e Install\n* Configure the Conan plugin.\n    * The easiest way to configure CLion to work with Conan is to build the project first from the command line.\n        * This will establish the `$PROJECT_HOME/CMakeUserPresets.json` file, which will allow you to choose the custom\n          CMake configuration created by Conan when creating a new CMake project. Using this custom profile will ensure\n          that sources are properly indexed and explorable.\n    * Open the project. The wizard will show three CMake profiles.\n        * Disable the default Cmake `Debug` profile.\n        * Enable the CMake `conan-debug` profile.\n    * CLion \u003e View \u003e Tool Windows \u003e Conan \u003e (gear) \u003e Conan Executable: `$PROJECT_HOME/venv/bin/conan`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopperlight%2Fconan-cmake-protobuf-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcopperlight%2Fconan-cmake-protobuf-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopperlight%2Fconan-cmake-protobuf-example/lists"}