Skip to content

Commit add7d28

Browse files
authored
feat(c/driver): add support for CMake packages of Go based drivers (#2561)
Fixes #2506.
1 parent 89c52bf commit add7d28

12 files changed

+192
-6
lines changed

c/cmake_modules/BuildUtils.cmake

+7-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ function(arrow_install_cmake_package PACKAGE_NAME EXPORT_NAME)
8585
set(INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}")
8686
install(FILES "${BUILT_CONFIG_CMAKE}" "${BUILT_CONFIG_VERSION_CMAKE}"
8787
DESTINATION "${INSTALL_CMAKEDIR}")
88-
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
89-
install(EXPORT ${EXPORT_NAME}
90-
DESTINATION "${INSTALL_CMAKEDIR}"
91-
NAMESPACE "${PACKAGE_NAME}::"
92-
FILE "${TARGETS_CMAKE}")
88+
if(EXPORT_NAME)
89+
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
90+
install(EXPORT ${EXPORT_NAME}
91+
DESTINATION "${INSTALL_CMAKEDIR}"
92+
NAMESPACE "${PACKAGE_NAME}::"
93+
FILE "${TARGETS_CMAKE}")
94+
endif()
9395
endfunction()
9496

9597
# \arg OUTPUTS list to append built targets to

c/cmake_modules/GoUtils.cmake

+51
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,53 @@
1818
find_program(GO_BIN "go" REQUIRED)
1919
message(STATUS "Detecting Go executable: Found ${GO_BIN}")
2020

21+
set(ADBC_GO_PACKAGE_INIT
22+
[=[
23+
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
24+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
25+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
26+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
27+
if(_IMPORT_PREFIX STREQUAL "/")
28+
set(_IMPORT_PREFIX "")
29+
endif()
30+
31+
function(adbc_add_shared_library target_name base_name)
32+
set(shared_base_name
33+
"${CMAKE_SHARED_LIBRARY_PREFIX}${base_name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
34+
set(prefix "${_IMPORT_PREFIX}/${ADBC_INSTALL_LIBDIR}")
35+
add_library(${target_name} SHARED IMPORTED)
36+
if(WINDOWS)
37+
set(import_base_name
38+
"${CMAKE_IMPORT_LIBRARY_PREFIX}${base_name}${CMAKE_IMPORT_LIBRARY_SUFFIX}")
39+
set_target_properties(${target_name}
40+
PROPERTIES
41+
IMPORTED_IMPLIB "${prefix}/${import_base_name}"
42+
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/${shared_base_name}")
43+
else()
44+
set_target_properties(${target_name}
45+
PROPERTIES
46+
IMPORTED_LOCATION "${prefix}/${shared_base_name}.${ADBC_FULL_SO_VERSION}"
47+
IMPORTED_SONAME "${prefix}/${shared_base_name}.${ADBC_SO_VERSION}")
48+
endif()
49+
endfunction()
50+
51+
function(adbc_add_static_library target_name base_name)
52+
set(static_base_name
53+
"${CMAKE_STATIC_LIBRARY_PREFIX}${base_name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
54+
add_library(${target_name} STATIC IMPORTED)
55+
if(WINDOWS)
56+
set_target_properties(${target_name}
57+
PROPERTIES
58+
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/${static_base_name}")
59+
else()
60+
set(prefix "${_IMPORT_PREFIX}/${ADBC_IMPORT_LIB_DIR}")
61+
set_target_properties(${target_name}
62+
PROPERTIES
63+
IMPORTED_LOCATION "${prefix}/${static_base_name}")
64+
endif()
65+
endfunction()
66+
]=])
67+
2168
function(add_go_lib GO_MOD_DIR GO_LIBNAME)
2269
set(options)
2370
set(one_value_args
@@ -245,6 +292,10 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
245292
install(FILES "${LIBOUT_STATIC}" TYPE LIB)
246293
endif()
247294

295+
if(ARG_CMAKE_PACKAGE_NAME)
296+
arrow_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} "")
297+
endif()
298+
248299
if(ARG_PKG_CONFIG_NAME)
249300
arrow_add_pkg_config("${ARG_PKG_CONFIG_NAME}")
250301
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
@PACKAGE_INIT@
19+
20+
set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
21+
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
22+
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
23+
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
24+
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
25+
set(ADBC_VERSION "@ADBC_VERSION@")
26+
27+
@ADBC_GO_PACKAGE_INIT@
28+
29+
if(ADBC_BUILD_SHARED)
30+
adbc_add_shared_library(
31+
AdbcDriverBigQuery::adbc_driver_bigquery_shared
32+
adbc_driver_bigquery)
33+
endif()
34+
35+
if(ADBC_BUILD_STATIC)
36+
adbc_add_shared_library(
37+
AdbcDriverBigQuery::adbc_driver_bigquery_static
38+
adbc_driver_bigquery)
39+
endif()
40+
41+
check_required_components(AdbcDriverBigQuery)

c/driver/bigquery/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/bigquery/"
2626
utils.c
2727
BUILD_TAGS
2828
driverlib
29+
CMAKE_PACKAGE_NAME
30+
AdbcDriverBigQuery
2931
PKG_CONFIG_NAME
3032
adbc-driver-bigquery
3133
SHARED_LINK_FLAGS

c/driver/bigquery/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
under the License.
1818
-->
1919

20-
# ADBC Snowflake Driver
20+
# ADBC BigQuery Driver
2121

2222
This driver provides an interface to
2323
[BigQuery](https://cloud.google.com/bigquery) using ADBC.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
@PACKAGE_INIT@
19+
20+
set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
21+
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
22+
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
23+
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
24+
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
25+
set(ADBC_VERSION "@ADBC_VERSION@")
26+
27+
@ADBC_GO_PACKAGE_INIT@
28+
29+
if(ADBC_BUILD_SHARED)
30+
adbc_add_shared_library(
31+
AdbcDriverFlightSQL::adbc_driver_flightsql_shared
32+
adbc_driver_flightsql)
33+
endif()
34+
35+
if(ADBC_BUILD_STATIC)
36+
adbc_add_shared_library(
37+
AdbcDriverFlightSQL::adbc_driver_flightsql_static
38+
adbc_driver_flightsql)
39+
endif()
40+
41+
check_required_components(AdbcDriverFlightSQL)

c/driver/flightsql/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/flightsql/"
2626
utils.c
2727
BUILD_TAGS
2828
driverlib
29+
CMAKE_PACKAGE_NAME
30+
AdbcDriverFlightSQL
2931
PKG_CONFIG_NAME
3032
adbc-driver-flightsql
3133
SHARED_LINK_FLAGS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
@PACKAGE_INIT@
19+
20+
set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
21+
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
22+
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
23+
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
24+
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
25+
set(ADBC_VERSION "@ADBC_VERSION@")
26+
27+
@ADBC_GO_PACKAGE_INIT@
28+
29+
if(ADBC_BUILD_SHARED)
30+
adbc_add_shared_library(
31+
AdbcDriverSnowflake::adbc_driver_snowflake_shared
32+
adbc_driver_snowflake)
33+
endif()
34+
35+
if(ADBC_BUILD_STATIC)
36+
adbc_add_shared_library(
37+
AdbcDriverSnowflake::adbc_driver_snowflake_static
38+
adbc_driver_snowflake)
39+
endif()
40+
41+
check_required_components(AdbcDriverSnowflake)

c/driver/snowflake/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/snowflake/"
2626
utils.c
2727
BUILD_TAGS
2828
driverlib
29+
CMAKE_PACKAGE_NAME
30+
AdbcDriverSnowflake
2931
PKG_CONFIG_NAME
3032
adbc-driver-snowflake
3133
SHARED_LINK_FLAGS
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usr/lib/*/cmake/AdbcDriverFlightSQL/
12
usr/lib/*/libadbc_driver_flightsql.a
23
usr/lib/*/libadbc_driver_flightsql.so
34
usr/lib/*/pkgconfig/adbc-driver-flightsql.pc
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usr/lib/*/cmake/AdbcDriverSnowflake/
12
usr/lib/*/libadbc_driver_snowflake.a
23
usr/lib/*/libadbc_driver_snowflake.so
34
usr/lib/*/pkgconfig/adbc-driver-snowflake.pc

ci/linux-packages/yum/apache-arrow-adbc.spec.in

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Libraries and header files for ADBC Flight SQL driver.
215215
%defattr(-,root,root,-)
216216
%doc README.md
217217
%license LICENSE.txt NOTICE.txt
218+
%{_libdir}/cmake/AdbcDriverFlightSQL/
218219
%{_libdir}/libadbc_driver_flightsql.a
219220
%{_libdir}/libadbc_driver_flightsql.so
220221
%{_libdir}/pkgconfig/adbc-driver-flightsql.pc
@@ -244,6 +245,7 @@ Libraries and header files for ADBC Snowflake driver
244245
%defattr(-,root,root,-)
245246
%doc README.md
246247
%license LICENSE.txt NOTICE.txt
248+
%{_libdir}/cmake/AdbcDriverSnowflake/
247249
%{_libdir}/libadbc_driver_snowflake.a
248250
%{_libdir}/libadbc_driver_snowflake.so
249251
%{_libdir}/pkgconfig/adbc-driver-snowflake.pc

0 commit comments

Comments
 (0)