Skip to content

Commit 01c46cc

Browse files
committed
FYI: [C++] Use CMake target instead of add_definitions() for xxHash
1 parent 2284234 commit 01c46cc

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

cpp/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,6 @@ endif()
351351

352352
include(SetupCxxFlags)
353353

354-
if(${CMAKE_CXX_FLAGS_DEBUG} MATCHES "-Og")
355-
# GH-47475: xxhash fails inlining when -Og is used.
356-
# See: https://github.com/Cyan4973/xxHash/issues/943
357-
add_definitions(-DXXH_NO_INLINE_HINTS)
358-
endif()
359-
360354
#
361355
# Linker flags
362356
#

cpp/cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ add_library(arrow::flatbuffers INTERFACE IMPORTED)
371371
target_include_directories(arrow::flatbuffers
372372
INTERFACE "${THIRDPARTY_DIR}/flatbuffers/include")
373373

374+
add_library(arrow::xxhash INTERFACE IMPORTED)
375+
# GH-47475: xxhash fails inlining when -Og is
376+
# used. -DCMAKE_BUILD_TYPE=Debug may use -Og.
377+
# See: https://github.com/Cyan4973/xxHash/issues/943
378+
target_compile_definitions(arrow::xxhash
379+
INTERFACE "$<$<CONFIG:Debug>:XXH_NO_INLINE_HINTS>")
380+
374381
# ----------------------------------------------------------------------
375382
# Some EP's require other EP's
376383

cpp/src/arrow/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ arrow_add_object_library(ARROW_ARRAY
402402
array/statistics.cc
403403
array/util.cc
404404
array/validate.cc)
405+
foreach(target ${ARROW_ARRAY_TARGETS})
406+
target_link_libraries(${target} PRIVATE arrow::xxhash)
407+
endforeach()
405408

406409
arrow_add_object_library(ARROW_IO
407410
io/buffered.cc
@@ -865,6 +868,7 @@ if(ARROW_COMPUTE)
865868
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
866869
)
867870
foreach(LIB_TARGET ${ARROW_COMPUTE_LIBRARIES})
871+
target_link_libraries(${LIB_TARGET} PRIVATE arrow::xxhash)
868872
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_COMPUTE_EXPORTING)
869873
endforeach()
870874

@@ -874,6 +878,9 @@ if(ARROW_COMPUTE)
874878
endif()
875879

876880
arrow_add_object_library(ARROW_COMPUTE_CORE ${ARROW_COMPUTE_SRCS})
881+
foreach(target ${ARROW_COMPUTE_CORE_TARGETS})
882+
target_link_libraries(${target} PRIVATE arrow::xxhash)
883+
endforeach()
877884

878885
if(ARROW_USE_XSIMD)
879886
foreach(ARROW_COMPUTE_CORE_TARGET ${ARROW_COMPUTE_CORE_TARGETS})
@@ -1167,6 +1174,7 @@ if(ARROW_BUILD_STATIC AND WIN32)
11671174
endif()
11681175

11691176
foreach(LIB_TARGET ${ARROW_LIBRARIES})
1177+
target_link_libraries(${LIB_TARGET} PRIVATE arrow::xxhash)
11701178
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_EXPORTING)
11711179
# C++17 is required to compile against Arrow C++ headers and libraries
11721180
target_compile_features(${LIB_TARGET} PUBLIC cxx_std_17)

cpp/src/arrow/engine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ add_arrow_lib(arrow_substrait
6767
${SUBSTRAIT_INCLUDES})
6868

6969
foreach(LIB_TARGET ${ARROW_SUBSTRAIT_LIBRARIES})
70+
target_link_libraries(${LIB_TARGET} PRIVATE arrow::xxhash)
7071
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_ENGINE_EXPORTING)
7172
endforeach()
7273

cpp/src/arrow/util/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ else()
3838
set(IO_UTIL_TEST_SOURCES io_util_test.cc)
3939
endif()
4040

41-
set(ARROW_UTILITY_TEST_LINK_LIBS Boost::headers)
41+
set(ARROW_UTILITY_TEST_LINK_LIBS Boost::headers arrow::xxhash)
4242
if(ARROW_USE_XSIMD)
4343
list(APPEND ARROW_UTILITY_TEST_LINK_LIBS ${ARROW_XSIMD})
4444
endif()

cpp/src/gandiva/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ add_arrow_lib(gandiva
174174
LLVM::LLVM_LIBS)
175175

176176
foreach(LIB_TARGET ${GANDIVA_LIBRARIES})
177+
target_link_libraries(${LIB_TARGET} PRIVATE arrow::xxhash)
177178
target_compile_definitions(${LIB_TARGET} PRIVATE GANDIVA_EXPORTING)
178179
endforeach()
179180

cpp/src/parquet/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ add_arrow_lib(parquet
309309
if(WIN32 AND NOT (ARROW_TEST_LINKAGE STREQUAL "static"))
310310
add_library(parquet_test_support STATIC
311311
"${PARQUET_THRIFT_SOURCE_DIR}/parquet_types.cpp")
312-
target_link_libraries(parquet_test_support thrift::thrift)
312+
target_link_libraries(parquet_test_support PRIVATE thrift::thrift)
313313
list(PREPEND PARQUET_TEST_LINK_LIBS parquet_test_support)
314314
list(APPEND PARQUET_LIBRARIES parquet_test_support)
315315
endif()
@@ -339,8 +339,9 @@ endif()
339339
add_definitions(-DPARQUET_THRIFT_VERSION_MAJOR=${Thrift_VERSION_MAJOR})
340340
add_definitions(-DPARQUET_THRIFT_VERSION_MINOR=${Thrift_VERSION_MINOR})
341341

342-
# Thrift requires these definitions for some types that we use
343342
foreach(LIB_TARGET ${PARQUET_LIBRARIES})
343+
target_link_libraries(${LIB_TARGET} PRIVATE arrow::xxhash)
344+
# Thrift requires these definitions for some types that we use
344345
target_compile_definitions(${LIB_TARGET}
345346
PRIVATE PARQUET_EXPORTING
346347
PRIVATE HAVE_INTTYPES_H

0 commit comments

Comments
 (0)