jvanstraten commented on a change in pull request #12457:
URL: https://github.com/apache/arrow/pull/12457#discussion_r812385234



##########
File path: cpp/cmake_modules/ThirdpartyToolchain.cmake
##########
@@ -1605,6 +1623,85 @@ if(ARROW_WITH_PROTOBUF)
   message(STATUS "Found protobuf headers: ${PROTOBUF_INCLUDE_DIR}")
 endif()
 
+# ----------------------------------------------------------------------
+# Substrait (required by compute engine)
+
+macro(build_substrait)
+  message("Building Substrait from source")
+
+  set(SUBSTRAIT_PROTOS
+      capabilities
+      expression
+      extensions/extensions
+      function
+      parameterized_types
+      plan
+      relations
+      type
+      type_expressions)
+
+  externalproject_add(substrait_ep
+                      CONFIGURE_COMMAND ""
+                      BUILD_COMMAND ""
+                      INSTALL_COMMAND ""
+                      URL ${SUBSTRAIT_SOURCE_URL}
+                      URL_HASH 
"SHA256=${ARROW_SUBSTRAIT_BUILD_SHA256_CHECKSUM}")
+
+  externalproject_get_property(substrait_ep SOURCE_DIR)
+  set(SUBSTRAIT_LOCAL_DIR ${SOURCE_DIR})
+
+  set(SUBSTRAIT_CPP_DIR "${CMAKE_CURRENT_BINARY_DIR}/substrait_ep-generated")
+
+  set(SUBSTRAIT_SUPPRESSED_WARNINGS)
+  if(MSVC)
+    # Protobuf generated files trigger some spurious warnings on MSVC.
+
+    # Implicit conversion from uint64_t to uint32_t:
+    list(APPEND SUBSTRAIT_SUPPRESSED_WARNINGS "/wd4244")
+
+    # Missing dll-interface:
+    list(APPEND SUBSTRAIT_SUPPRESSED_WARNINGS "/wd4251")
+  endif()
+
+  set(SUBSTRAIT_SOURCES)
+  set(SUBSTRAIT_PROTO_GEN_ALL)
+  foreach(SUBSTRAIT_PROTO ${SUBSTRAIT_PROTOS})
+    set(SUBSTRAIT_PROTO_GEN 
"${SUBSTRAIT_CPP_DIR}/substrait/${SUBSTRAIT_PROTO}.pb")
+
+    foreach(EXT h cc)
+      set_source_files_properties("${SUBSTRAIT_PROTO_GEN}.${EXT}"
+                                  PROPERTIES COMPILE_OPTIONS
+                                             "${SUBSTRAIT_SUPPRESSED_WARNINGS}"
+                                             GENERATED TRUE
+                                             SKIP_UNITY_BUILD_INCLUSION TRUE)
+      add_custom_command(OUTPUT "${SUBSTRAIT_PROTO_GEN}.${EXT}"
+                         COMMAND ${ARROW_PROTOBUF_PROTOC} 
"-I${SUBSTRAIT_LOCAL_DIR}/proto"
+                                 "--cpp_out=${SUBSTRAIT_CPP_DIR}"
+                                 
"${SUBSTRAIT_LOCAL_DIR}/proto/substrait/${SUBSTRAIT_PROTO}.proto"
+                         DEPENDS ${PROTO_DEPENDS} substrait_ep)
+      list(APPEND SUBSTRAIT_PROTO_GEN_ALL "${SUBSTRAIT_PROTO_GEN}.${EXT}")
+    endforeach()
+
+    list(APPEND SUBSTRAIT_SOURCES "${SUBSTRAIT_PROTO_GEN}.cc")
+  endforeach()
+
+  add_custom_target(substrait_gen ALL DEPENDS ${SUBSTRAIT_PROTO_GEN_ALL})
+
+  set(SUBSTRAIT_INCLUDES ${SUBSTRAIT_CPP_DIR} ${PROTOBUF_INCLUDE_DIR})
+
+  add_library(substrait STATIC ${SUBSTRAIT_SOURCES})
+  set_target_properties(substrait PROPERTIES POSITION_INDEPENDENT_CODE ON)
+  target_include_directories(substrait PUBLIC ${SUBSTRAIT_INCLUDES})
+  target_link_libraries(substrait INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
+  add_dependencies(substrait substrait_gen)

Review comment:
       Added in 3d7bac9
   
   The removal of `add_dependencies(substrait substrait_gen)` seems unrelated. 
I suppose it's technically redundant, since CMake will generate the .cc files 
by way of needing them as input for compiling `substrait`, and the .h files 
just so happen to be generated by the same command. If for whatever reason only 
the generated .h files are removed though, CMake won't know to recreate them 
without that rule.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to