# FetchContent protobuf and use for FindProtobuf functions

**URL:** https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739
**Category:** Code
**Created:** [February 29, 2020, 8:01pm UTC](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739 "2020-02-29T20:01:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Leonard\_Lausen](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/43a26b/32.png) [@Leonard\_Lausen](https://discourse.cmake.org/u/Leonard_Lausen)
#### Post date: [February 29, 2020, 8:01pm UTC](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739/1 "2020-02-29T20:01:48Z")

</div>

Following  
[https://gitlab.kitware.com/cmake/cmake/issues/19875#note\_705896](https://gitlab.kitware.com/cmake/cmake/issues/19875#note_705896) it is  
possible to FetchContent protobuf. Is it feasible to use that protobuf  
and it’s compiler for the protobuf\_generate\_cpp and  
protobuf\_generate\_python functions of FindProtobuf?

Those functions expect a protobuf compiler for compilation, but the  
compiler will only be available after the targets introduced by  
FetchContent have finished compilation.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 2, 2020, 3:48pm UTC](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739/2 "2020-03-02T15:48:26Z")

</div>

You can probably set the expected variables to some `$<TARGET_FILE:>` values. Those functions should be making custom commands rather than direct execution, so that should be fine.

Cc: @craig.scott

---

<div class="post-metadata">

### Author: ![ronhe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ronhe/32/505_2.png) [@ronhe](https://discourse.cmake.org/u/ronhe)
#### Post date: [April 11, 2020, 7:58am UTC](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739/3 "2020-04-11T07:58:08Z")

</div>

Bincrafters introduced some patches to Protobuf’s CMakeLists in their [Conan Protobuf package](https://github.com/bincrafters/conan-protobuf).  
Using Protobuf via Conan enables what described out of the box.  
If you rather not using Conan, I guess you could also just pick what you need from their patches.
