[ 
https://issues.apache.org/jira/browse/ARROW-11888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17300689#comment-17300689
 ] 

Kouhei Sutou commented on ARROW-11888:
--------------------------------------

This is caused by calling {{Findre2.cmake}} provided by gRPC twice.

Apache Arrow itself uses re2. So Apache Arrow calls {{find_package(re2)}} (from 
{{Findre2Alt.cmake}} in Apache Arrow). If re2 provides {{re2Config.cmake}}, the 
{{find_package(re2)}} uses the {{re2Config.cmake}}. If {{re2Config.cmake}} 
doesn't exist, it uses {{Findre2.cmake}} provided by gRPC. {{Findre2.cmake}} 
defines {{re2::re2}} CMake target.

Apache Arrow Flight uses gRPC. gRPC uses re2. So gRPC tries to find re2 by 
{{find_package(re2 CONFIG)}}. It uses {{re2Config.cmake}}. Note that we can use 
{{re2Config.cmake}} multiple times. Because {{re2Config.cmake}} doesn't define 
{{re2::re2}} CMake target if there is already {{re2::re2}} CMake target. If 
{{re2Config.cmake}} doesn't exist, {{Findre2.cmake}} in gRPC defines 
{{re2::re2}} CMake target. Note that it doesn't check {{re2::re2}} CMake target 
existence. So using {{Findre2.cmake}} in gRPC without {{re2Config.cmake}} twice 
causes the error.

There are some solutions:

1. re2 provides {{re2Config.cmake}}

2. gRPC's {{Findre2.cmake}} doesn't define {{re2::re2}} multiple times:

{noformat}
diff --git a/cmake/modules/Findre2.cmake b/cmake/modules/Findre2.cmake
index 41df454713..906aabfeba 100644
--- a/cmake/modules/Findre2.cmake
+++ b/cmake/modules/Findre2.cmake
@@ -26,26 +26,28 @@ find_package(PkgConfig REQUIRED)
 pkg_check_modules(RE2 QUIET re2)
 if(RE2_FOUND)
   set(re2_FOUND "${RE2_FOUND}")
-  add_library(re2::re2 INTERFACE IMPORTED)
-  if(RE2_INCLUDE_DIRS)
-    set_property(TARGET re2::re2 PROPERTY
-                 INTERFACE_INCLUDE_DIRECTORIES "${RE2_INCLUDE_DIRS}")
-  endif()
-  if(RE2_CFLAGS_OTHER)
-    # Filter out the -std flag, which is handled by CMAKE_CXX_STANDARD.
-    # TODO(junyer): Use the FILTER option whenever CMake 3.6 (or newer)
-    # becomes the minimum required: that will allow this to be concise.
-    foreach(flag IN LISTS RE2_CFLAGS_OTHER)
-      if("${flag}" MATCHES "^-std=")
-        list(REMOVE_ITEM RE2_CFLAGS_OTHER "${flag}")
-      endif()
-    endforeach()
-    set_property(TARGET re2::re2 PROPERTY
-                 INTERFACE_COMPILE_OPTIONS "${RE2_CFLAGS_OTHER}")
-  endif()
-  if(RE2_LDFLAGS)
-    set_property(TARGET re2::re2 PROPERTY
-                 INTERFACE_LINK_LIBRARIES "${RE2_LDFLAGS}")
+  if(NOT TARGET re2::re2)
+    add_library(re2::re2 INTERFACE IMPORTED)
+    if(RE2_INCLUDE_DIRS)
+      set_property(TARGET re2::re2 PROPERTY
+                  INTERFACE_INCLUDE_DIRECTORIES "${RE2_INCLUDE_DIRS}")
+    endif()
+    if(RE2_CFLAGS_OTHER)
+      # Filter out the -std flag, which is handled by CMAKE_CXX_STANDARD.
+      # TODO(junyer): Use the FILTER option whenever CMake 3.6 (or newer)
+      # becomes the minimum required: that will allow this to be concise.
+      foreach(flag IN LISTS RE2_CFLAGS_OTHER)
+       if("${flag}" MATCHES "^-std=")
+         list(REMOVE_ITEM RE2_CFLAGS_OTHER "${flag}")
+       endif()
+      endforeach()
+      set_property(TARGET re2::re2 PROPERTY
+                  INTERFACE_COMPILE_OPTIONS "${RE2_CFLAGS_OTHER}")
+    endif()
+    if(RE2_LDFLAGS)
+      set_property(TARGET re2::re2 PROPERTY
+                  INTERFACE_LINK_LIBRARIES "${RE2_LDFLAGS}")
+    endif()
   endif()
   message(STATUS "Found RE2 via pkg-config.")
   return()
{noformat}

3. Apache Arrow doesn't find dependencies (re2, gRPC and so on) if 
{{libarrow.a}} isn't required.

{{find_package(Arrow)}} in pyarrow always find Apache Arrow dependencies but 
it's only for {{libarrow.a}}. {{libarrow.so}} doesn't need to find them. 
pyarrow only uses {{libarrow.so}}. So we can avoid calling 
{{find_package(re2)}} and {{find_package(gRPC)}} for just building pyarrow.

1. will be the easiest solution if MacPorts accepts it.

2. may be an acceptable solution if gRPC accepts it.

3. will be implemented in the future. We'll improve our {{find_package(Arrow)}} 
to support component feature of {{find_package}}. 3. will be implemented in the 
improvement.


> Cmake build of Apache Arrow fails using grpc's Findre2.cmake with 
> "add_library cannot create imported target "RE2::re2" because another target 
> with the same name already exists."
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: ARROW-11888
>                 URL: https://issues.apache.org/jira/browse/ARROW-11888
>             Project: Apache Arrow
>          Issue Type: Bug
>    Affects Versions: 3.0.0
>         Environment: macOS 10.15.7 19H524
> Xcode 12.4 12D4e
>            Reporter: Steven Smith
>            Priority: Major
>         Attachments: main.log
>
>
> I'm trying to create a MacPorts port of Apache Arrow. See 
> [https://github.com/macports/macports-ports/pull/7791]
> I'm using a library install of grpc, version 1.36.2. This issue is also 
> observed with grpc version 1.35.0.
> The grpc cmake file 
> [Findre2.cmake|https://github.com/grpc/grpc/blob/master/cmake/modules/Findre2.cmake]
>  causes this cmake error when building pyarrow.
> I see that there is also a fileĀ Findre2.cmake created and installed in the 
> cmake build of arrow. Also see this issue raised at grpc, 
> [https://github.com/grpc/grpc/issues/25434]
> Error:
> :info:build CMake Error at /opt/local/lib/cmake/grpc/modules/Findre2.cmake:29 
> (add_library):
> :info:build add_library cannot create imported target "re2::re2" because 
> another target
> :info:build with the same name already exists.
> Related:
>  * 
> [http://mail-archives.apache.org/mod_mbox/arrow-dev/202009.mbox/%3c6ecb7d60-844f-410d-8840-24f2ce261...@yahoo.com%3E]
> [http://mail-archives.apache.org/mod_mbox/arrow-jira/202009.mbox/%3cjira.13327607.1600156125000.372264.1600157460...@atlassian.jira%3E]
>  * [https://www.mail-archive.com/dev@arrow.apache.org/msg20631.html]
>  * [https://github.com/macports/macports-ports/pull/7791]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to