paleolimbot commented on code in PR #205:
URL: https://github.com/apache/arrow-nanoarrow/pull/205#discussion_r1237103440


##########
extensions/nanoarrow_device/CMakeLists.txt:
##########
@@ -0,0 +1,221 @@
+# 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.
+
+message(STATUS "Building using CMake version: ${CMAKE_VERSION}")
+cmake_minimum_required(VERSION 3.14)
+include(FetchContent)
+
+if(NOT DEFINED CMAKE_C_STANDARD)
+  set(CMAKE_C_STANDARD 11)
+endif()
+
+project(nanoarrow_device)
+
+option(NANOARROW_DEVICE_BUILD_TESTS "Build tests" OFF)
+option(NANOARROW_DEVICE_BUNDLE "Create bundled nanoarrow_device.h and 
nanoarrow_device.c" OFF)
+option(NANOARROW_DEVICE_WITH_METAL "Build Apple metal extension" OFF)
+option(NANOARROW_DEVICE_WITH_CUDA "Build CUDA extension" OFF)
+
+
+option(NANOARROW_DEVICE_CODE_COVERAGE "Enable coverage reporting" OFF)
+add_library(device_coverage_config INTERFACE)
+
+if (NANOARROW_DEVICE_BUILD_TESTS OR NOT NANOARROW_DEVICE_BUNDLE)
+  # Add the nanoarrow dependency. nanoarrow is not linked into the
+  # nanoarrow_device library (the caller must link this themselves);
+  # however, we need nanoarrow.h to build nanoarrow_device.c.
+  FetchContent_Declare(
+    nanoarrow
+    SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
+
+  # Don't install nanoarrow because of this configuration
+  FetchContent_GetProperties(nanoarrow)
+  if(NOT nanoarrow_POPULATED)
+    FetchContent_Populate(nanoarrow)
+    add_subdirectory(${nanoarrow_SOURCE_DIR} ${nanoarrow_BINARY_DIR} 
EXCLUDE_FROM_ALL)
+  endif()
+endif()
+
+if (NANOARROW_DEVICE_BUNDLE)
+  # The CMake build step is creating nanoarrow_device.c and nanoarrow_device.h;
+  # the CMake install step is copying them to a specific location
+  file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/amalgamation)
+  file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow)
+
+  # nanoarrow_device.h is currently standalone
+  set(NANOARROW_DEVICE_H_TEMP 
${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow_device.h)
+  file(READ src/nanoarrow/nanoarrow_device.h SRC_FILE_CONTENTS)
+  file(WRITE ${NANOARROW_DEVICE_H_TEMP} "${SRC_FILE_CONTENTS}")
+
+  # nanoarrow_device.c is currently standalone
+  set(NANOARROW_DEVICE_C_TEMP 
${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow_device.c)
+  file(READ src/nanoarrow/nanoarrow_device.c SRC_FILE_CONTENTS)
+  file(WRITE ${NANOARROW_DEVICE_C_TEMP} "${SRC_FILE_CONTENTS}")
+
+  # Add a library that the tests can link against (but don't install it)
+  if(NANOARROW_DEVICE_BUILD_TESTS)
+    add_library(nanoarrow_device ${NANOARROW_DEVICE_C_TEMP})
+
+    target_include_directories(nanoarrow_device PUBLIC
+      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
+      $<BUILD_INTERFACE:${nanoarrow_SOURCE_DIR}/src/nanoarrow>
+      $<BUILD_INTERFACE:${nanoarrow_BINARY_DIR}/generated>
+      $<BUILD_INTERFACE:${NANOARROW_DEVICE_FLATCC_INCLUDE_DIR}>)
+  endif()
+
+  # Install the amalgamated header and sources
+  install(FILES
+    ${NANOARROW_DEVICE_H_TEMP}
+    ${NANOARROW_DEVICE_C_TEMP}
+    DESTINATION ".")
+else()
+  # This is a normal CMake build that builds + installs some includes and a 
static lib
+  if (NANOARROW_DEVICE_WITH_METAL)
+    if (NOT EXISTS "${CMAKE_BINARY_DIR}/metal-cpp")
+      message(STATUS "Fetching metal-cpp")
+      file(DOWNLOAD
+        
"https://developer.apple.com/metal/cpp/files/metal-cpp_macOS12_iOS15.zip";
+        "${CMAKE_BINARY_DIR}/metal-cpp.zip")
+      file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/metal-cpp.zip DESTINATION 
${CMAKE_BINARY_DIR})
+    endif()
+
+    if(NOT DEFINED CMAKE_CXX_STANDARD)
+      set(CMAKE_CXX_STANDARD 17)
+    endif()
+    set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+    find_library(METAL_LIBRARY Metal REQUIRED)
+    message(STATUS "Metal framework found at '${METAL_LIBRARY}'")
+
+    find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
+    message(STATUS "Foundation framework found at '${FOUNDATION_LIBRARY}'")
+
+    find_library(QUARTZ_CORE_LIBRARY QuartzCore REQUIRED)
+    message(STATUS "CoreFoundation framework found at 
'${QUARTZ_CORE_LIBRARY}'")
+
+    set(NANOARROW_DEVICE_SOURCES_METAL src/nanoarrow/nanoarrow_device_metal.cc)
+    set(NANOARROW_DEVICE_INCLUDE_METAL ${CMAKE_BINARY_DIR}/metal-cpp)
+    set(NANOARROW_DEVICE_LIBS_METAL ${METAL_LIBRARY} ${FOUNDATION_LIBRARY} 
${QUARTZ_CORE_LIBRARY})
+    set(NANOARROW_DEVICE_DEFS_METAL "NANOARROW_DEVICE_WITH_METAL")
+  endif()
+
+  if (NANOARROW_DEVICE_WITH_CUDA)
+    find_package(CUDAToolkit REQUIRED)
+    set(NANOARROW_DEVICE_SOURCES_CUDA src/nanoarrow/nanoarrow_device_cuda.c)
+    set(NANOARROW_DEVICE_LIBS_CUDA CUDA::cudart)

Review Comment:
   Driver library is a definite yes (just haven't gotten there yet).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to