protocolbuffers/protobuf

Define cmake target as PIC if BUILD_SHARED_LIBS

Open

#10.828 geöffnet am 27. Okt. 2022

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C++ (16.128 Forks)batch import
c++cmakehelp wanted

Repository-Metriken

Stars
 (71.223 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 11h) (185 gemergte PRs in 30 T)

Beschreibung

What language does this apply to? Generated C/C++ code and the specific cmake target.

Describe the problem you are trying to solve. When I link to the generated cmake target and set the BUILD_SHARED_LIBS variable globally I get linker errors because the protobuf created code is not relocateable.

Describe the solution you'd like In my user code I use something like the following:

# ensure relocateable code
if (BUILD_SHARED_LIBS)
  set_property(TARGET ${PROTO_TARGET} PROPERTY POSITION_INDEPENDENT_CODE TRUE)
endif ()

But this could be integrated in the cmake part of this project directly.

Describe alternatives you've considered It's not a big problem. But may be helpful for people that do not have that much cmake experience.

Additional context Nothing.

Contributor Guide