Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Add absl::abseil_dll ALIAS target for abseil_dll #1466

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

traversaro
Copy link
Contributor

This PR adds a absl::abseil_dll ALIAS target for the abseil_dll.

ALIAS targets are used in CMake to ensure that consumers that consume the library via CMake's FetchContent or in general via add_subdirectory can use the exact same targets found by consuming abseil via find_package(absl REQUIRED).

For all other absl targets, the ALIAS target is added by the absl_cc_library cmake function ( https://github.com/abseil/abseil-cpp/blob/20230125.3/CMake/AbseilHelpers.cmake#L53 ). However, the abseil_dll target is not created via the absl_cc_library but instead with a direct call to the add_library CMake function, so it is necessary to also add an ALIAS target explicitly.

After this PR, it is possible to just link absl::abseil_dll, both when abseil is obtained via FetchContent of via find_package. Before this PR, if abseil was obtained via FetchContent it was necessarry to link abseil_dll, while if find_package(absl REQUIRED) was used, it was necessary to link absl::abseil_dll.

@traversaro
Copy link
Contributor Author

fyi @h-vetinari

copybara-service bot pushed a commit to protocolbuffers/protobuf that referenced this pull request Jun 5, 2023
This additional if  is necessary as of abseil 20230125.3 when abseil is consumed via add_subdirectory,
the abseil_dll target  is named abseil_dll, while if abseil is consumed via find_package, the target is called `absl::abseil_dll` .

Once abseil/abseil-cpp#1466 is merged and released in the minimum version of  abseil required by protobuf, it is possible to always link `absl::abseil_dll` and `absl::abseil_test_dll` and remove the if.

You may wonder how linking worked at all before when `protobuf_ABSL_PROVIDER STREQUAL "package"`, as `abseil_dll` was not an imported target defined by `find_package(absl)`. The reason behind this is that if a name that is not an imported target is passed to `target_link_libraries`, it is just regarded as a C++ library name. So, in the end the `abseil_dll` library was correctly linked, simply all the transitive usage requirements defined by the `absl::abseil_dll` target were not propagated, that could lead to compilation errors if abseil was compiled with the `ABSL_PROPAGATE_CXX_STD` CMake option enabled.

Closes #12978

COPYBARA_INTEGRATE_REVIEW=#12978 from traversaro:patch-1 39dd074
PiperOrigin-RevId: 537990391
copybara-service bot pushed a commit to protocolbuffers/protobuf that referenced this pull request Jun 5, 2023
This additional if  is necessary as of abseil 20230125.3 when abseil is consumed via add_subdirectory,
the abseil_dll target  is named abseil_dll, while if abseil is consumed via find_package, the target is called `absl::abseil_dll` .

Once abseil/abseil-cpp#1466 is merged and released in the minimum version of  abseil required by protobuf, it is possible to always link `absl::abseil_dll` and `absl::abseil_test_dll` and remove the if.

You may wonder how linking worked at all before when `protobuf_ABSL_PROVIDER STREQUAL "package"`, as `abseil_dll` was not an imported target defined by `find_package(absl)`. The reason behind this is that if a name that is not an imported target is passed to `target_link_libraries`, it is just regarded as a C++ library name. So, in the end the `abseil_dll` library was correctly linked, simply all the transitive usage requirements defined by the `absl::abseil_dll` target were not propagated, that could lead to compilation errors if abseil was compiled with the `ABSL_PROPAGATE_CXX_STD` CMake option enabled.

Closes #12978

COPYBARA_INTEGRATE_REVIEW=#12978 from traversaro:patch-1 39dd074
FUTURE_COPYBARA_INTEGRATE_REVIEW=#12978 from traversaro:patch-1 39dd074
PiperOrigin-RevId: 537953985
h-vetinari pushed a commit to h-vetinari/protobuf that referenced this pull request Jun 5, 2023
…ocolbuffers#12978)

This additional if  is necessary as of abseil 20230125.3 when abseil is consumed via add_subdirectory,
the abseil_dll target  is named abseil_dll, while if abseil is consumed via find_package, the target is called `absl::abseil_dll` .

Once abseil/abseil-cpp#1466 is merged and released in the minimum version of  abseil required by protobuf, it is possible to always link `absl::abseil_dll` and `absl::abseil_test_dll` and remove the if.

You may wonder how linking worked at all before when `protobuf_ABSL_PROVIDER STREQUAL "package"`, as `abseil_dll` was not an imported target defined by `find_package(absl)`. The reason behind this is that if a name that is not an imported target is passed to `target_link_libraries`, it is just regarded as a C++ library name. So, in the end the `abseil_dll` library was correctly linked, simply all the transitive usage requirements defined by the `absl::abseil_dll` target were not propagated, that could lead to compilation errors if abseil was compiled with the `ABSL_PROPAGATE_CXX_STD` CMake option enabled.

Closes protocolbuffers#12978

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#12978 from traversaro:patch-1 39dd074
PiperOrigin-RevId: 537990391
@copybara-service copybara-service bot merged commit d49a30a into abseil:master Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants