Prevent find_package failure if multiple versions are installed #16654
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The generated
protobuf-config-version.cmake
sets theProtobuf_WITH_ZLIB
,Protobuf_MSVC_STATIC_RUNTIME
andProtobuf_BUILD_SHARED_LIBS
unconditionally while executing the_check_and_save_build_option(...)
macro.If there are several Protobuf installations available the original code may lead to failure. An example with two installations:
3.12.4
.3.19.4
The user wants it's project to use the thirdparty one by doing:
The user is not setting the
Protobuf_XXX
variables in itsCMakeLitsts.txt
.If the first config processed is the system deployed it sets the variables to its desired variables, for example,
Protobuf_WITH_ZLIB=OFF
but is discarded due to the non-matched version.Then the thirdparty's config is processed but is discarded because requires
Protobuf_WITH_ZLIB=ON
which is not a real requirement and makes the find operation fail (despite of matching version).