Skip to content

Commit

Permalink
apacheGH-37410: [C++][Gandiva] Add support for using LLVM shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 29, 2023
1 parent 5720f7c commit f42ae12
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
3 changes: 3 additions & 0 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ takes precedence over ccache if a storage backend is configured" ON)
"Rely on jemalloc shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

define_option(ARROW_LLVM_USE_SHARED "Rely on LLVM shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

define_option(ARROW_LZ4_USE_SHARED "Rely on lz4 shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

Expand Down
55 changes: 29 additions & 26 deletions cpp/cmake_modules/FindLLVMAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ if(NOT LLVM_FOUND)
endif()

if(LLVM_FOUND)
# Find the libraries that correspond to the LLVM components
llvm_map_components_to_libnames(LLVM_LIBS
core
mcjit
native
ipo
bitreader
target
linker
analysis
debuginfodwarf)

find_program(LLVM_LINK_EXECUTABLE llvm-link HINTS ${LLVM_TOOLS_BINARY_DIR})

find_program(CLANG_EXECUTABLE
Expand All @@ -94,22 +82,37 @@ if(LLVM_FOUND)
INTERFACE_COMPILE_FLAGS "${LLVM_DEFINITIONS}")

add_library(LLVM::LLVM_LIBS INTERFACE IMPORTED)
set_target_properties(LLVM::LLVM_LIBS PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_LIBS}")
if(ARROW_LLVM_USE_SHARED)
target_link_libraries(LLVM::LLVM_LIBS INTERFACE LLVM)
else()
# Find the libraries that correspond to the LLVM components
llvm_map_components_to_libnames(LLVM_LIBS
core
mcjit
native
ipo
bitreader
target
linker
analysis
debuginfodwarf)
target_link_libraries(LLVM::LLVM_LIBS INTERFACE ${LLVM_LIBS})

if(TARGET LLVMSupport AND NOT ARROW_ZSTD_USE_SHARED)
get_target_property(LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES LLVMSupport
INTERFACE_LINK_LIBRARIES)
list(FIND LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES zstd::libzstd_shared
LLVM_SUPPORT_LIBZSTD_INDEX)
if(NOT LLVM_SUPPORT_LIBZSTD_INDEX EQUAL -1)
list(REMOVE_AT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX})
list(INSERT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX}
zstd::libzstd_static)
if(TARGET LLVMSupport AND NOT ARROW_ZSTD_USE_SHARED)
get_target_property(LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES LLVMSupport
INTERFACE_LINK_LIBRARIES)
list(FIND LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES zstd::libzstd_shared
LLVM_SUPPORT_LIBZSTD_INDEX)
if(NOT LLVM_SUPPORT_LIBZSTD_INDEX EQUAL -1)
list(REMOVE_AT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES
${LLVM_SUPPORT_LIBZSTD_INDEX})
list(INSERT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX}
zstd::libzstd_static)
endif()
set_target_properties(LLVMSupport
PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES}")
endif()
set_target_properties(LLVMSupport
PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES}")
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ add_dependencies(gandiva ${GANDIVA_LIBRARIES})
arrow_install_all_headers("gandiva")

set(GANDIVA_STATIC_TEST_LINK_LIBS gandiva_static ${ARROW_TEST_LINK_LIBS})
set(GANDIVA_SHARED_TEST_LINK_LIBS gandiva_shared ${ARROW_TEST_LINK_LIBS})
set(GANDIVA_SHARED_TEST_LINK_LIBS gandiva_shared ${ARROW_TEST_LINK_LIBS} LLVM::LLVM_LIBS)
if(ARROW_WITH_UTF8PROC)
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS utf8proc::utf8proc)
list(APPEND GANDIVA_STATIC_TEST_LINK_LIBS utf8proc::utf8proc)
endif()
if(WIN32)
list(APPEND GANDIVA_STATIC_TEST_LINK_LIBS ${GANDIVA_OPENSSL_TARGETS})
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS LLVM::LLVM_LIBS ${GANDIVA_OPENSSL_TARGETS})
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS ${GANDIVA_OPENSSL_TARGETS})
endif()

function(ADD_GANDIVA_TEST REL_TEST_NAME)
Expand Down

0 comments on commit f42ae12

Please sign in to comment.