Skip to content

Commit 7f201ce

Browse files
kounimesh1601
authored andcommitted
feat(build): Add support for CMake package (facebookincubator#14738)
Summary: Fixes facebookincubator#14275 Fixes facebookincubator#14756 This is not a complete CMake package support. This works only when: * `VELOX_BUILD_SHARED=ON` * `VELOX_BUILD_MINIMAL_WITH_DWIO=ON` * All dependencies are resolved from system (No bundled dependencies) FYI: I want to use this for Nimble: facebookincubator/nimble#215 Nimble uses `VELOX_BUILD_MINIMAL_WITH_DWIO=ON`. This is disabled by default. We can enabled this by specifying `VELOX_BUILD_CMAKE_PACKAGE=ON`. Users can find Velox by `find_package(Velox)`. We can expand supported cases step by step. How about this as the first step? Pull Request resolved: facebookincubator#14738 Reviewed By: mbasmanova Differential Revision: D81923615 Pulled By: Yuhta fbshipit-source-id: 8a7cb55c5e57c3b87b696fa7298cbd171e80d40d
1 parent 040be03 commit 7f201ce

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

CMake/VeloxConfig.cmake.in

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
@PACKAGE_INIT@
15+
16+
include(CMakeFindDependencyMacro)
17+
18+
block()
19+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
20+
21+
if("@Arrow_SOURCE@" STREQUAL "SYSTEM")
22+
find_dependency(Arrow)
23+
endif()
24+
if("@Boost_SOURCE@" STREQUAL "SYSTEM")
25+
find_dependency(Boost COMPONENTS "@BOOST_INCLUDE_LIBRARIES@")
26+
endif()
27+
find_dependency(double-conversion)
28+
if("@folly_SOURCE@" STREQUAL "SYSTEM")
29+
find_dependency(folly)
30+
endif()
31+
if("@fmt_SOURCE@" STREQUAL "SYSTEM")
32+
find_dependency(fmt)
33+
endif()
34+
if("@gflags_SOURCE@" STREQUAL "SYSTEM")
35+
find_dependency(gflags)
36+
endif()
37+
if("@glog_SOURCE@" STREQUAL "SYSTEM")
38+
find_dependency(glog)
39+
endif()
40+
if("@VELOX_ENABLE_COMPRESSION_LZ4@")
41+
find_dependency(lz4)
42+
endif()
43+
if("@Protobuf_SOURCE@" STREQUAL "SYSTEM")
44+
find_dependency(Protobuf)
45+
endif()
46+
if("@re2_SOURCE@" STREQUAL "SYSTEM")
47+
find_dependency(re2)
48+
endif()
49+
if("@stemmer_SOURCE@" STREQUAL "SYSTEM")
50+
find_dependency(stemmer)
51+
endif()
52+
if("@VELOX_BUILD_MINIMAL_WITH_DWIO@" OR "@VELOX_ENABLE_HIVE_CONNECTOR@")
53+
find_dependency(Snappy)
54+
find_dependency(ZLIB)
55+
find_dependency(zstd)
56+
endif()
57+
if("@simdjson_SOURCE@" STREQUAL "SYSTEM")
58+
find_dependency(simdjson)
59+
endif()
60+
if("@THRIFT_SOURCE@" STREQUAL "SYSTEM")
61+
find_dependency(Thrift)
62+
endif()
63+
if("@xsimd_SOURCE@" STREQUAL "SYSTEM")
64+
find_dependency(xsimd)
65+
endif()
66+
endblock()
67+
68+
include("${CMAKE_CURRENT_LIST_DIR}/VeloxTargets.cmake")
69+
70+
check_required_components(Velox)

CMake/VeloxUtils.cmake

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
include_guard(GLOBAL)
15+
16+
include(CMakePackageConfigHelpers)
17+
1518
function(velox_get_rpath_origin VAR)
1619
if(APPLE)
1720
set(_origin @loader_path)
@@ -99,7 +102,54 @@ function(velox_add_library TARGET)
99102
add_library(velox ${_type} ${ARGN})
100103
set_target_properties(velox PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
101104
set_target_properties(velox PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
102-
install(TARGETS velox DESTINATION lib/velox)
105+
install(TARGETS velox DESTINATION lib/velox EXPORT velox_targets)
106+
if(VELOX_BUILD_CMAKE_PACKAGE)
107+
set(package_cmake_dir "lib/cmake/Velox")
108+
set(config_cmake_in "${PROJECT_SOURCE_DIR}/CMake/VeloxConfig.cmake.in")
109+
set(config_cmake "${PROJECT_BINARY_DIR}/CMake/VeloxConfig.cmake")
110+
configure_package_config_file(
111+
"${config_cmake_in}"
112+
"${config_cmake}"
113+
INSTALL_DESTINATION "${package_cmake_dir}"
114+
)
115+
install(FILES "${config_cmake}" DESTINATION "${package_cmake_dir}")
116+
set(system_dependencies)
117+
if(Arrow_SOURCE STREQUAL "SYSTEM")
118+
list(APPEND system_dependencies Arrow)
119+
endif()
120+
if(glog_SOURCE STREQUAL "SYSTEM")
121+
list(APPEND system_dependencies glog)
122+
endif()
123+
if(VELOX_ENABLE_COMPRESSION_LZ4)
124+
list(APPEND system_dependencies lz4)
125+
endif()
126+
if(re2_SOURCE STREQUAL "SYSTEM")
127+
list(APPEND system_dependencies re2)
128+
endif()
129+
if(stemmer_SOURCE STREQUAL "SYSTEM")
130+
list(APPEND system_dependencies stemmer)
131+
endif()
132+
if(VELOX_BUILD_MINIMAL_WITH_DWIO OR VELOX_ENABLE_HIVE_CONNECTOR)
133+
list(APPEND system_dependencies Snappy zstd)
134+
endif()
135+
foreach(system_dependency ${system_dependencies})
136+
install(
137+
FILES "${PROJECT_SOURCE_DIR}/CMake/Find${system_dependency}.cmake"
138+
DESTINATION "${package_cmake_dir}"
139+
)
140+
endforeach()
141+
# TODO: We can enable this once we add version to Velox.
142+
# set(version_cmake "${PROJECT_BINARY_DIR}/CMake/VeloxConfigVersion.cmake")
143+
# write_basic_package_version_file("${version_cmake}"
144+
# COMPATIBILITY SameMajorVersion)
145+
# install(FILES "${version_cmake}" DESTINATION "${package_cmake_dir}")
146+
install(
147+
EXPORT velox_targets
148+
DESTINATION "${package_cmake_dir}"
149+
NAMESPACE "Velox::"
150+
FILE "VeloxTargets.cmake"
151+
)
152+
endif()
103153
endif()
104154
# create alias for compatability
105155
if(NOT TARGET ${TARGET})

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ option(
9090
option(VELOX_MONO_LIBRARY "Build single unified library." ON)
9191
option(ENABLE_ALL_WARNINGS "Enable -Wall and -Wextra compiler warnings." ON)
9292
option(VELOX_BUILD_SHARED "Build Velox as shared libraries." OFF)
93+
option(VELOX_BUILD_CMAKE_PACKAGE "Build CMake package for Velox." OFF)
9394
option(VELOX_SKIP_WAVE_BRANCH_KERNEL_TEST "Disable Wave branch kernel test." OFF)
9495
# While it's possible to build both in one go we currently want to build either
9596
# static or shared.
@@ -193,6 +194,14 @@ if(${VELOX_BUILD_MINIMAL} OR ${VELOX_BUILD_MINIMAL_WITH_DWIO})
193194
set(VELOX_ENABLE_S3 OFF)
194195
set(VELOX_ENABLE_GCS OFF)
195196
set(VELOX_ENABLE_ABFS OFF)
197+
else()
198+
if(VELOX_BUILD_CMAKE_PACKAGE)
199+
message(
200+
FATAL_ERROR
201+
"VELOX_BUILD_CMAKE_PACKAGE is only available with "
202+
"VELOX_BUILD_MINIMAL=ON or VELOX_BUILD_MINIMAL_WITH_DWIO=ON for now."
203+
)
204+
endif()
196205
endif()
197206

198207
if(${VELOX_ENABLE_BENCHMARKS})

velox/dwio/dwrf/common/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ velox_link_libraries(
4343
)
4444

4545
# required for the wrapped protobuf headers/sources
46-
velox_include_directories(velox_dwio_dwrf_common PUBLIC ${PROJECT_BINARY_DIR})
46+
velox_include_directories(
47+
velox_dwio_dwrf_common
48+
PUBLIC "$<BUILD_LOCAL_INTERFACE:${PROJECT_BINARY_DIR}>"
49+
)
4750

4851
if(NOT VELOX_MONO_LIBRARY)
4952
# trigger generation of pb files

velox/tpcds/gen/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ add_subdirectory(utils)
1717
add_subdirectory(dsdgen)
1818

1919
velox_add_library(velox_tpcds_gen TpcdsGen.cpp DSDGenIterator.cpp)
20-
velox_include_directories(velox_tpcds_gen PUBLIC dsdgen/include)
20+
velox_include_directories(
21+
velox_tpcds_gen
22+
PUBLIC "$<BUILD_LOCAL_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dsdgen/include>"
23+
)
2124
velox_link_libraries(
2225
velox_tpcds_gen
2326
PUBLIC velox_memory velox_tpcds_append_info

velox/tpch/gen/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ velox_add_library(velox_tpch_gen DBGenIterator.cpp TpchGen.cpp)
1818

1919
velox_include_directories(velox_tpch_gen PRIVATE dbgen/include)
2020

21-
velox_link_libraries(velox_tpch_gen velox_memory velox_vector dbgen)
21+
velox_link_libraries(
22+
velox_tpch_gen
23+
PUBLIC velox_memory velox_vector "$<BUILD_LOCAL_INTERFACE:dbgen>"
24+
)
2225

2326
if(${VELOX_BUILD_TESTING})
2427
add_subdirectory(tests)

0 commit comments

Comments
 (0)