raulcd commented on code in PR #46922:
URL: https://github.com/apache/arrow/pull/46922#discussion_r2174475634


##########
cpp/src/arrow/compute/CMakeLists.txt:
##########
@@ -114,6 +114,46 @@ function(ADD_ARROW_COMPUTE_TEST REL_TEST_NAME)
                  ${ARG_UNPARSED_ARGUMENTS})
 endfunction()
 
+# This function is used to add a custom main to the benchmarks in order
+# to initialize the compute kernels registry before running them.
+# This is necessary for benchmarks that use compute kernels that are not
+# part of libarrow.
+# It will also link the compute libraries to the benchmark target.
+function(ADD_ARROW_COMPUTE_BENCHMARK REL_TEST_NAME)
+  set(options)
+  set(one_value_args PREFIX)
+  set(multi_value_args EXTRA_SOURCES)
+  cmake_parse_arguments(ARG
+                        "${options}"
+                        "${one_value_args}"
+                        "${multi_value_args}"
+                        ${ARGN})
+  if(ARG_PREFIX)
+    set(PREFIX ${ARG_PREFIX})
+  else()
+    set(PREFIX "arrow-compute")
+  endif()
+  set(EXTRA_SOURCES 
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/main_compute_benchmark.cc")
+  if(ARG_EXTRA_SOURCES)
+    list(APPEND EXTRA_SOURCES ${ARG_EXTRA_SOURCES})
+  endif()
+  add_benchmark(${REL_TEST_NAME}
+                PREFIX
+                ${PREFIX}
+                LABELS
+                "arrow-benchmarks"
+                EXTRA_SOURCES
+                ${EXTRA_SOURCES}
+                OUTPUT_BENCHMARK_NAME
+                COMPUTE_BENCHMARK_NAME
+                ${ARG_UNPARSED_ARGUMENTS})
+  if(ARROW_BUILD_STATIC)
+    target_link_libraries(${COMPUTE_BENCHMARK_NAME} PUBLIC 
arrow_compute_static)
+  else()
+    target_link_libraries(${COMPUTE_BENCHMARK_NAME} PUBLIC 
arrow_compute_shared)
+  endif()

Review Comment:
   Done!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to