diff --git a/CMakeLists.txt b/CMakeLists.txt index 025d6c22..17185468 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,5 +63,7 @@ if(${SUBSTRAIT_CPP_BUILD_TESTING}) enable_testing() endif() +install(EXPORT SubstraitTargets DESTINATION lib/cmake/Substrait) + add_subdirectory(src/substrait) add_subdirectory(export) diff --git a/export/planloader/CMakeLists.txt b/export/planloader/CMakeLists.txt index e33353a9..e08e839c 100644 --- a/export/planloader/CMakeLists.txt +++ b/export/planloader/CMakeLists.txt @@ -5,11 +5,8 @@ add_library(planloader SHARED planloader.cpp) add_dependencies(planloader substrait_io) target_link_libraries(planloader substrait_io) -install( - TARGETS planloader - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCDIR}) - if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install(TARGETS planloader EXPORT SubstraitTargets) diff --git a/src/substrait/common/CMakeLists.txt b/src/substrait/common/CMakeLists.txt index d706c63f..70a1fc6a 100644 --- a/src/substrait/common/CMakeLists.txt +++ b/src/substrait/common/CMakeLists.txt @@ -1,9 +1,15 @@ # SPDX-License-Identifier: Apache-2.0 add_library(substrait_common Exceptions.cpp) +target_sources( + substrait_common PUBLIC FILE_SET HEADERS BASE_DIRS ../../../include/ FILES + ../../../include/substrait/common/Exceptions.h) target_link_libraries(substrait_common fmt::fmt-header-only) add_library(substrait_io STATIC Io.cpp) +target_sources(substrait_io PUBLIC FILE_SET HEADERS BASE_DIRS ../../../include/ + FILES ../../../include/substrait/common/Io.h) + add_dependencies( substrait_io substrait_proto @@ -24,10 +30,11 @@ if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() -install(TARGETS substrait_io LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES ../../../include/substrait/common/Io.h - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/substrait/common") - add_executable(plantransformer PlanTransformerTool.cpp) target_link_libraries(plantransformer substrait_io) + +install( + TARGETS substrait_common substrait_io plantransformer + EXPORT SubstraitTargets + LIBRARY FILE_SET HEADERS) diff --git a/src/substrait/expression/CMakeLists.txt b/src/substrait/expression/CMakeLists.txt index cdb1e7aa..9b1703b2 100644 --- a/src/substrait/expression/CMakeLists.txt +++ b/src/substrait/expression/CMakeLists.txt @@ -1,6 +1,10 @@ # SPDX-License-Identifier: Apache-2.0 add_library(substrait_expression DecimalLiteral.cpp) +target_sources( + substrait_expression + PUBLIC FILE_SET HEADERS BASE_DIRS ../../../include/ FILES + ../../../include/substrait/expression/DecimalLiteral.h) target_link_libraries(substrait_expression substrait_proto absl::numeric absl::strings) @@ -8,3 +12,8 @@ target_link_libraries(substrait_expression substrait_proto absl::numeric if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install( + TARGETS substrait_expression + EXPORT SubstraitTargets + FILE_SET HEADERS) diff --git a/src/substrait/function/CMakeLists.txt b/src/substrait/function/CMakeLists.txt index 218619a5..352ff43e 100644 --- a/src/substrait/function/CMakeLists.txt +++ b/src/substrait/function/CMakeLists.txt @@ -3,9 +3,25 @@ set(FUNCTION_SRCS Function.cpp Extension.cpp FunctionLookup.cpp) add_library(substrait_function ${FUNCTION_SRCS}) +target_sources( + substrait_function + PUBLIC FILE_SET + HEADERS + BASE_DIRS + ../../../include/ + FILES + ../../../include/substrait/function/Extension.h + ../../../include/substrait/function/Function.h + ../../../include/substrait/function/FunctionLookup.h + ../../../include/substrait/function/FunctionSignature.h) target_link_libraries(substrait_function substrait_type yaml-cpp) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install( + TARGETS substrait_function + EXPORT SubstraitTargets + FILE_SET HEADERS) diff --git a/src/substrait/proto/CMakeLists.txt b/src/substrait/proto/CMakeLists.txt index 47af3530..c6efa852 100644 --- a/src/substrait/proto/CMakeLists.txt +++ b/src/substrait/proto/CMakeLists.txt @@ -77,8 +77,17 @@ foreach(PROTO_FILE IN LISTS PROTOBUF_FILELIST) endforeach() # Add the generated protobuf C++ files to our exported library. -add_library(substrait_proto ${PROTO_SRCS} ${PROTO_HDRS} ProtoUtils.cpp - ProtoUtils.h) +add_library(substrait_proto ${PROTO_SRCS} ${PROTO_HDRS} ProtoUtils.cpp) +target_sources( + substrait_proto + PUBLIC FILE_SET + HEADERS + BASE_DIRS + ${PROTO_OUTPUT_TOPLEVEL_DIR}/src + ../.. + FILES + ${PROTO_HDRS} + ProtoUtils.h) # Include the protobuf library as a dependency to use this class. target_link_libraries(substrait_proto protobuf::libprotobuf) @@ -86,5 +95,12 @@ target_link_libraries(substrait_proto protobuf::libprotobuf) # Make sure we can see our own generated include files. target_include_directories( substrait_proto - PUBLIC "${PROTO_OUTPUT_TOPLEVEL_DIR}/src" - PUBLIC "${protobuf_SOURCE_DIR}/src") + PUBLIC $ + $ + PUBLIC $ + $) + +install( + TARGETS substrait_proto + EXPORT SubstraitTargets + LIBRARY FILE_SET HEADERS) diff --git a/src/substrait/textplan/CMakeLists.txt b/src/substrait/textplan/CMakeLists.txt index 2487fb28..a0237ff9 100644 --- a/src/substrait/textplan/CMakeLists.txt +++ b/src/substrait/textplan/CMakeLists.txt @@ -36,9 +36,12 @@ target_link_libraries( date::date) # Provide access to the generated protobuffer headers hierarchy. -target_include_directories(symbol_table - PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/../..") +target_include_directories( + symbol_table PUBLIC $) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install(TARGETS error_listener parse_result symbol_table + EXPORT SubstraitTargets) diff --git a/src/substrait/textplan/converter/CMakeLists.txt b/src/substrait/textplan/converter/CMakeLists.txt index dc2cfe77..0dad7373 100644 --- a/src/substrait/textplan/converter/CMakeLists.txt +++ b/src/substrait/textplan/converter/CMakeLists.txt @@ -53,3 +53,7 @@ add_library(substrait_textplan_normalizer ${NORMALIZER_SRCS}) target_link_libraries(substrait_textplan_normalizer substrait_textplan_converter) + +install(TARGETS planconverter substrait_textplan_converter + substrait_base_proto_visitor substrait_textplan_normalizer + EXPORT SubstraitTargets) diff --git a/src/substrait/textplan/parser/CMakeLists.txt b/src/substrait/textplan/parser/CMakeLists.txt index 36e24027..e593908e 100644 --- a/src/substrait/textplan/parser/CMakeLists.txt +++ b/src/substrait/textplan/parser/CMakeLists.txt @@ -43,3 +43,5 @@ target_link_libraries(planparser substrait_textplan_loader error_listener) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install(TARGETS planparser substrait_textplan_loader EXPORT SubstraitTargets) diff --git a/src/substrait/textplan/parser/grammar/CMakeLists.txt b/src/substrait/textplan/parser/grammar/CMakeLists.txt index 47d88944..df42f515 100644 --- a/src/substrait/textplan/parser/grammar/CMakeLists.txt +++ b/src/substrait/textplan/parser/grammar/CMakeLists.txt @@ -55,7 +55,10 @@ add_library(textplan_grammar ${ANTLR_SubstraitPlanLexer_CXX_OUTPUTS} message(STATUS "generated dir: ${GRAMMAR_DIR}/antlr4cpp_generated_src") -target_include_directories(textplan_grammar - PUBLIC "${GRAMMAR_DIR}/antlr4cpp_generated_src") +target_include_directories( + textplan_grammar + PUBLIC $) target_link_libraries(textplan_grammar antlr4_static) + +install(TARGETS textplan_grammar EXPORT SubstraitTargets) diff --git a/src/substrait/type/CMakeLists.txt b/src/substrait/type/CMakeLists.txt index 4b473701..f43daaff 100644 --- a/src/substrait/type/CMakeLists.txt +++ b/src/substrait/type/CMakeLists.txt @@ -3,9 +3,17 @@ set(TYPE_SRCS Type.cpp) add_library(substrait_type ${TYPE_SRCS}) +target_sources( + substrait_type PUBLIC FILE_SET HEADERS BASE_DIRS ../../../include/ FILES + ../../../include/substrait/type/Type.h) target_link_libraries(substrait_type substrait_common) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) endif() + +install( + TARGETS substrait_type + EXPORT SubstraitTargets + FILE_SET HEADERS) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index fb340296..0a5f605b 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +# Ensure `option()` in subdirectories honors normal variables set here. +set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + +set(ABSL_ENABLE_INSTALL ON) if(NOT ${ABSL_INCLUDED_WITH_PROTOBUF}) set(ABSL_PROPAGATE_CXX_STD ON) add_subdirectory(abseil-cpp) @@ -26,6 +30,7 @@ set(BUILD_TESTING OFF) add_subdirectory(protobuf-matchers) set(BUILD_TESTING ${PREVIOUS_BUILD_TESTING}) +set(YAML_CPP_INSTALL ON) set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Enable testing")