Skip to content

Commit

Permalink
Use namespaced absl::abseil_dll imported target instead of abseil_dll…
Browse files Browse the repository at this point in the history
… to correctly propagate CMake usage requirements defined in abseil build on Windows (#162)

automerged PR by conda-forge/automerge-action
  • Loading branch information
github-actions[bot] authored Jun 5, 2023
2 parents 194faf4 + f8d4b2f commit ac8134a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
28 changes: 24 additions & 4 deletions recipe/cmake_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
project(cf_dummy LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.12)
# CMake seems to prefer its own FindProtobuf to the
# protobuf-config.cmake being distributed by this
# feedstock; make sure things work
find_package(Protobuf REQUIRED)
# We need to specify CONFIG to make sure that CMake
# uses protobuf-config.cmake instead of relying on its
# own FindProtobuf.cmake that does not know about
# abseil transitive depedendency and about C++ version
# required, see https://github.com/conda-forge/conda-forge-pinning-feedstock/issues/4075#issuecomment-1569242816
find_package(Protobuf CONFIG REQUIRED)

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/struct_example.cc
"
#include <iostream>
#include <google/protobuf/struct.pb.h>
int main()
{
google::protobuf::Struct myStruct;
}
"
)

add_executable(struct_example ${CMAKE_CURRENT_BINARY_DIR}/struct_example.cc)
target_link_libraries(struct_example PRIVATE protobuf::libprotobuf)
10 changes: 7 additions & 3 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ source:
- patches/0004-always-look-for-shared-abseil-builds.patch
- patches/0005-be-more-lenient-with-abseil-version.patch
- patches/0006-add-PROTOBUF_EXPORT-for-google-protobuf-io-SafeDoubl.patch
# backport https://github.com/protocolbuffers/protobuf/pull/12978
- patches/0007-use-namespaced-abseil-dll-imported-target-backport-12978.patch

build:
number: 2
number: 3

outputs:
- name: libprotobuf
Expand Down Expand Up @@ -87,10 +89,11 @@ outputs:
# binary
- protoc --help

# more CMake integration (CMake uses its own FindProtobuf)
# more CMake integration
- cd cmake_test
- cmake -GNinja $CMAKE_ARGS . # [unix]
- cmake -GNinja %CMAKE_ARGS% . # [win]
- cmake --build .

- name: libprotobuf-static
script: build-lib.sh # [unix]
Expand Down Expand Up @@ -129,10 +132,11 @@ outputs:
- if not exist %LIBRARY_LIB%\{{ each_lib }}-static.lib exit 1 # [win]
{% endfor %}

# more CMake integration (CMake uses its own FindProtobuf)
# more CMake integration
- cd cmake_test
- cmake -GNinja $CMAKE_ARGS . # [unix]
- cmake -GNinja %CMAKE_ARGS% . # [win]
- cmake --build .

about:
home: https://developers.google.com/protocol-buffers/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/cmake/abseil-cpp.cmake b/cmake/abseil-cpp.cmake
index e7bfb2b15f8..c668f4d9b01 100644
--- a/cmake/abseil-cpp.cmake
+++ b/cmake/abseil-cpp.cmake
@@ -39,8 +39,19 @@ set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFI

if (BUILD_SHARED_LIBS AND MSVC)
# On MSVC Abseil is bundled into a single DLL.
- set(protobuf_ABSL_USED_TARGETS abseil_dll)
-
+ # This condition 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 https://github.com/abseil/abseil-cpp/pull/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
+ if(protobuf_ABSL_PROVIDER STREQUAL "package")
+ set(protobuf_ABSL_USED_TARGETS absl::abseil_dll)
+ else()
+ set(protobuf_ABSL_USED_TARGETS abseil_dll)
+ endif()
+ # Not all build of abseil found by find_package provide the absl::abseil_test_dll target, so for
+ # it we stick to the non-namespaced definition
set(protobuf_ABSL_USED_TEST_TARGETS abseil_test_dll)
else()
set(protobuf_ABSL_USED_TARGETS

0 comments on commit ac8134a

Please sign in to comment.