@@ -262,6 +262,12 @@ if(ENABLE_GLUTEN_VCPKG AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
262262 target_link_options (
263263 velox PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map )
264264endif ()
265+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
266+ # Make libvelox.dylib own the Velox mono archive. Test utilities can then
267+ # resolve Velox symbols from the dylib instead of linking a second copy.
268+ target_link_options (velox PRIVATE
269+ "LINKER:-force_load,${VELOX_BUILD_PATH} /lib/libvelox.a" )
270+ endif ()
265271
266272find_protobuf ()
267273message (STATUS "Found Protobuf: ${PROTOBUF_LIBRARY} " )
@@ -289,6 +295,9 @@ target_include_directories(
289295 ${VELOX_HOME}
290296 ${PROTO_OUTPUT_DIR}
291297 ${PROTOBUF_INCLUDE} )
298+ if (GLUTEN_PREFIX_INCLUDE_DIRS)
299+ target_include_directories (velox BEFORE PUBLIC ${GLUTEN_PREFIX_INCLUDE_DIRS} )
300+ endif ()
292301
293302set_target_properties (velox PROPERTIES LIBRARY_OUTPUT_DIRECTORY
294303 ${root_directory} /releases)
@@ -308,6 +317,10 @@ target_link_libraries(velox PUBLIC gluten)
308317
309318# Requires VELOX_MONO_LIBRARY=ON when building Velox.
310319import_library (facebook::velox ${VELOX_BUILD_PATH} /lib/libvelox.a )
320+ set (GLUTEN_VELOX_LINK_SCOPE PUBLIC)
321+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
322+ set (GLUTEN_VELOX_LINK_SCOPE PRIVATE)
323+ endif ()
311324
312325if (BUILD_TESTS)
313326 add_duckdb ()
@@ -337,7 +350,7 @@ if(BUILD_TESTS)
337350 target_link_libraries (velox PUBLIC facebook::velox::exec_test_lib )
338351endif ()
339352
340- target_link_libraries (velox PUBLIC facebook::velox )
353+ target_link_libraries (velox ${GLUTEN_VELOX_LINK_SCOPE} facebook::velox )
341354
342355target_link_libraries (velox PUBLIC ${GLUTEN_ROARING_LINK_LIBRARY} )
343356
@@ -385,6 +398,24 @@ target_link_libraries(velox PUBLIC external::veloxthrift)
385398# `-DCMAKE_PREFIX_PATH="${folly lib path}" to cmake arguments. It is also
386399# applicable to other dependencies.
387400find_package (Folly REQUIRED CONFIG )
401+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND TARGET gflags_shared)
402+ # Folly's exported interface references the static gflags target while glog
403+ # links the shared gflags library. Loading both copies into one process makes
404+ # gflags register its built-in flags twice and abort test binaries. Point
405+ # folly's interface at the shared gflags target instead.
406+ foreach (FOLLY_TARGET Folly::folly Folly::folly_deps)
407+ if (TARGET ${FOLLY_TARGET} )
408+ get_target_property (FOLLY_LINK_LIBS ${FOLLY_TARGET}
409+ INTERFACE_LINK_LIBRARIES )
410+ if (FOLLY_LINK_LIBS MATCHES "gflags_static" )
411+ list (TRANSFORM FOLLY_LINK_LIBS REPLACE "gflags_static" "gflags_shared" )
412+ set_target_properties (
413+ ${FOLLY_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES
414+ "${FOLLY_LINK_LIBS} " )
415+ endif ()
416+ endif ()
417+ endforeach ()
418+ endif ()
388419target_link_libraries (velox PUBLIC Folly::folly )
389420
390421# Link thrift libraries - check vcpkg first, then fall back to system libraries
@@ -555,13 +586,15 @@ if(ENABLE_GPU)
555586 velox_curl )
556587endif ()
557588
558- add_custom_command (
559- TARGET velox
560- POST_BUILD
561- COMMAND ld $<TARGET_FILE :velox > || true
562- COMMENT "Checking ld result of libvelox.so" )
563- add_custom_command (
564- TARGET velox
565- POST_BUILD
566- COMMAND ldd $<TARGET_FILE :velox > || true
567- COMMENT "Checking ldd result of libvelox.so" )
589+ if (CMAKE_SYSTEM_NAME MATCHES "Linux" )
590+ add_custom_command (
591+ TARGET velox
592+ POST_BUILD
593+ COMMAND ld $<TARGET_FILE :velox > || true
594+ COMMENT "Checking ld result of libvelox.so" )
595+ add_custom_command (
596+ TARGET velox
597+ POST_BUILD
598+ COMMAND ldd $<TARGET_FILE :velox > || true
599+ COMMENT "Checking ldd result of libvelox.so" )
600+ endif ()
0 commit comments