kou commented on pull request #12457: URL: https://github.com/apache/arrow/pull/12457#issuecomment-1046348832
How about using just an OBJECT library https://cmake.org/cmake/help/latest/command/add_library.html#object-lib instead of `arrow_add_lib()`? ```diff diff --git a/cpp/cmake_modules/BuildUtils.cmake b/cpp/cmake_modules/BuildUtils.cmake index 391c43e0ac..3afecfc562 100644 --- a/cpp/cmake_modules/BuildUtils.cmake +++ b/cpp/cmake_modules/BuildUtils.cmake @@ -297,6 +297,14 @@ function(ADD_ARROW_LIB LIB_NAME) target_precompile_headers(${LIB_NAME}_objlib PRIVATE ${ARG_PRECOMPILED_HEADERS}) endif() set(LIB_DEPS $<TARGET_OBJECTS:${LIB_NAME}_objlib>) + # We need to specify $<TARGET_OBJECTS:XXX> explicitly to SHARED + # library and STATIC library because $<TARGET_OBJECTS:XXX> in + # OBJECT isn't propagated to SHARED library and STATIC library. + foreach(ARG_SOURCE ${ARG_SOURCES}) + if(ARG_SOURCE MATCHES "^\\$<TARGET_OBJECTS:") + list(APPEND LIB_DEPS ${ARG_SOURCE}) + endif() + endforeach() set(LIB_INCLUDES) set(EXTRA_DEPS) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 8b53272452..9143550df9 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -1687,22 +1687,13 @@ macro(build_substrait) add_custom_target(substrait_gen ALL DEPENDS ${SUBSTRAIT_PROTO_GEN_ALL}) - add_arrow_lib(arrow_substrait - SOURCES - ${SUBSTRAIT_SOURCES} - DEPENDENCIES - substrait_gen - SHARED_LINK_LIBS - ${ARROW_PROTOBUF_LIBPROTOBUF} - STATIC_LINK_LIBS - ${ARROW_PROTOBUF_LIBPROTOBUF} - PRIVATE_INCLUDES - ${SUBSTRAIT_CPP_DIR}) - - set(SUBSTRAIT_DEPENDENCIES substrait_gen) - set(SUBSTRAIT_SHARED arrow_substrait_shared) - set(SUBSTRAIT_STATIC arrow_substrait_static) - set(SUBSTRAIT_INCLUDES ${SUBSTRAIT_CPP_DIR}) + add_library(substrait OBJECT ${SUBSTRAIT_SOURCES}) + set_target_properties(substrait + PROPERTIES + INCLUDE_DIRECTORIES ${SUBSTRAIT_CPP_DIR} + POSITION_INDEPENDENT_CODE ON) + add_dependencies(substrait substrait_gen) + get_target_property(SUBSTRAIT_INCLUDES substrait INCLUDE_DIRECTORIES) endmacro() if(ARROW_WITH_SUBSTRAIT) diff --git a/cpp/src/arrow/engine/CMakeLists.txt b/cpp/src/arrow/engine/CMakeLists.txt index 50a84464c0..ff88f47e4a 100644 --- a/cpp/src/arrow/engine/CMakeLists.txt +++ b/cpp/src/arrow/engine/CMakeLists.txt @@ -36,9 +36,10 @@ add_arrow_lib(arrow_engine OUTPUTS ARROW_ENGINE_LIBRARIES DEPENDENCIES - ${SUBSTRAIT_DEPENDENCIES} + substrait SOURCES ${ARROW_ENGINE_SRCS} + $<TARGET_OBJECTS:substrait> PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:arrow/engine/pch.h>" SHARED_LINK_FLAGS @@ -46,11 +47,9 @@ add_arrow_lib(arrow_engine SHARED_LINK_LIBS arrow_shared arrow_dataset_shared - ${SUBSTRAIT_SHARED} STATIC_LINK_LIBS arrow_static arrow_dataset_static - ${SUBSTRAIT_STATIC} PRIVATE_INCLUDES ${SUBSTRAIT_INCLUDES}) ``` -- 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