You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2022/08/29 13:34:05 UTC

[arrow-adbc] branch main updated: [C] Add support for CMake package (#90)

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 06821ec  [C] Add support for CMake package (#90)
06821ec is described below

commit 06821ec6b61a60779fbe77fa55ad1fc0c5d98bb0
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Mon Aug 29 22:34:00 2022 +0900

    [C] Add support for CMake package (#90)
    
    fix #89
---
 c/cmake_modules/BuildUtils.cmake                  | 42 ++++++++++++-----------
 c/driver_manager/AdbcDriverManagerConfig.cmake.in | 24 +++++++++++++
 c/driver_manager/CMakeLists.txt                   |  4 ++-
 3 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/c/cmake_modules/BuildUtils.cmake b/c/cmake_modules/BuildUtils.cmake
index 700d4c1..afb0931 100644
--- a/c/cmake_modules/BuildUtils.cmake
+++ b/c/cmake_modules/BuildUtils.cmake
@@ -30,6 +30,8 @@ set(ADBC_LIBRARY_PATH_SUFFIXES
     "Library/bin")
 set(ADBC_INCLUDE_PATH_SUFFIXES "include" "Library" "Library/include")
 
+include(CMakePackageConfigHelpers)
+
 function(add_thirdparty_lib LIB_NAME LIB_TYPE LIB)
   set(options)
   set(one_value_args)
@@ -149,6 +151,25 @@ function(create_merged_static_lib output_target)
   install(FILES ${output_lib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR})
 endfunction()
 
+function(arrow_install_cmake_package PACKAGE_NAME EXPORT_NAME)
+  set(CONFIG_CMAKE "${PACKAGE_NAME}Config.cmake")
+  set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
+  configure_package_config_file("${CONFIG_CMAKE}.in" "${BUILT_CONFIG_CMAKE}"
+                                INSTALL_DESTINATION "${ARROW_CMAKE_DIR}/${PACKAGE_NAME}")
+  set(CONFIG_VERSION_CMAKE "${PACKAGE_NAME}ConfigVersion.cmake")
+  set(BUILT_CONFIG_VERSION_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_CMAKE}")
+  write_basic_package_version_file("${BUILT_CONFIG_VERSION_CMAKE}"
+                                   COMPATIBILITY SameMajorVersion)
+  set(INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}")
+  install(FILES "${BUILT_CONFIG_CMAKE}" "${BUILT_CONFIG_VERSION_CMAKE}"
+          DESTINATION "${INSTALL_CMAKEDIR}")
+  set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
+  install(EXPORT ${EXPORT_NAME}
+          DESTINATION "${INSTALL_CMAKEDIR}"
+          NAMESPACE "${PACKAGE_NAME}::"
+          FILE "${TARGETS_CMAKE}")
+endfunction()
+
 # \arg OUTPUTS list to append built targets to
 function(ADD_ARROW_LIB LIB_NAME)
   set(options)
@@ -420,26 +441,7 @@ function(ADD_ARROW_LIB LIB_NAME)
   endif()
 
   if(ARG_CMAKE_PACKAGE_NAME)
-    arrow_install_cmake_find_module("${ARG_CMAKE_PACKAGE_NAME}")
-
-    set(TARGETS_CMAKE "${ARG_CMAKE_PACKAGE_NAME}Targets.cmake")
-    install(EXPORT ${LIB_NAME}_targets
-            FILE "${TARGETS_CMAKE}"
-            DESTINATION "${ADBC_CMAKE_INSTALL_DIR}")
-
-    set(CONFIG_CMAKE "${ARG_CMAKE_PACKAGE_NAME}Config.cmake")
-    set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
-    configure_package_config_file("${CONFIG_CMAKE}.in" "${BUILT_CONFIG_CMAKE}"
-                                  INSTALL_DESTINATION "${ADBC_CMAKE_INSTALL_DIR}")
-    install(FILES "${BUILT_CONFIG_CMAKE}" DESTINATION "${ADBC_CMAKE_INSTALL_DIR}")
-
-    set(CONFIG_VERSION_CMAKE "${ARG_CMAKE_PACKAGE_NAME}ConfigVersion.cmake")
-    set(BUILT_CONFIG_VERSION_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_CMAKE}")
-    write_basic_package_version_file(
-      "${BUILT_CONFIG_VERSION_CMAKE}"
-      VERSION ${${PROJECT_NAME}_VERSION}
-      COMPATIBILITY AnyNewerVersion)
-    install(FILES "${BUILT_CONFIG_VERSION_CMAKE}" DESTINATION "${ADBC_CMAKE_INSTALL_DIR}")
+    arrow_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} ${LIB_NAME}_targets)
   endif()
 
   if(ARG_PKG_CONFIG_NAME)
diff --git a/c/driver_manager/AdbcDriverManagerConfig.cmake.in b/c/driver_manager/AdbcDriverManagerConfig.cmake.in
new file mode 100644
index 0000000..37a835d
--- /dev/null
+++ b/c/driver_manager/AdbcDriverManagerConfig.cmake.in
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+@PACKAGE_INIT@
+
+set(ADBC_VERSION "@ADBC_VERSION@")
+
+include("${CMAKE_CURRENT_LIST_DIR}/AdbcDriverManagerTargets.cmake")
+
+check_required_components(AdbcDriverManager)
diff --git a/c/driver_manager/CMakeLists.txt b/c/driver_manager/CMakeLists.txt
index a64d8ad..db846d6 100644
--- a/c/driver_manager/CMakeLists.txt
+++ b/c/driver_manager/CMakeLists.txt
@@ -32,7 +32,9 @@ add_arrow_lib(adbc_driver_manager
               SOURCES
               adbc_driver_manager.cc
               OUTPUTS
-              ADBC_LIBRARIES)
+              ADBC_LIBRARIES
+              CMAKE_PACKAGE_NAME
+              AdbcDriverManager)
 include_directories(SYSTEM ${REPOSITORY_ROOT})
 include_directories(SYSTEM ${REPOSITORY_ROOT}/c/)
 foreach(LIB_TARGET ${ADBC_LIBRARIES})