Skip to content

Commit

Permalink
Support JAVA rely on certain C++ version
Browse files Browse the repository at this point in the history
  • Loading branch information
acezen committed Oct 8, 2023
1 parent e60f0a2 commit a448cc8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
9 changes: 6 additions & 3 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.6)
project(gar-java)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -std=c++17 -Wall")

file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target/generated-sources/annotations/*.cc" "${CMAKE_CURRENT_SOURCE_DIR}/target/generated-test-sources/test-annotations/*.cc"
Expand All @@ -19,10 +20,12 @@ include_directories("src/main/native")
include_directories("src/test/native")

find_package(Arrow REQUIRED)
find_package(gar REQUIRED)
include(graphar-cpp)
build_graphar_cpp()

add_library(${LIBNAME} SHARED ${SOURCES})
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} gar)
target_include_directories(${LIBNAME} SYSTEM BEFORE PRIVATE ${GAR_INCLUDE_DIR})
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} ${GAR_DYNAMIC_LIB})
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} Arrow::arrow_static)

set_target_properties(${LIBNAME} PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
3 changes: 1 addition & 2 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ NOTE: This project is still under development, and we will release it soon.
### C++

- CMake 3.5 or higher
- [GraphAr C++ library](../cpp/README.md)
- [GraphAr C++ library v0.9.0](../cpp/README.md)
- LLVM 11

Tips:
- To install GraphAr C++ library, you can refer to our [C++ CI](../.github/workflows/ci.yml) on Ubuntu and CentOS;
- To install LLVM 11, you can refer to our [Java CI](../.github/workflows/java.yml) on Ubuntu or compile from source with [this script](https://github.com/alibaba/fastFFI/blob/main/docker/install-llvm11.sh).

## Build, Test and Install
Expand Down
74 changes: 74 additions & 0 deletions java/cmake/graphar-cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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.

# This cmake file is referred and derived from
# https://github.com/apache/arrow/blob/master/matlab/CMakeLists.txt


# Build the GraphAr C++ libraries.
function(build_graphar_cpp)
set(one_value_args)
set(multi_value_args)

cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if (ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif ()

# If GraphAr needs to be built, the default location will be within the build tree.
set(GAR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/graphar_ep-prefix")

set(GAR_DYNAMIC_LIBRARY_DIR "${GAR_PREFIX}/lib")

set(GAR_DYNAMIC_LIB_FILENAME
"${CMAKE_STATIC_LIBRARY_PREFIX}arrow${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(GAR_DYNAMIC_LIB "${GAR_DYNAMIC_LIBRARY_DIR}/${GAR_DYNAMIC_LIB_FILENAME}")

set(GAR_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/graphar_ep-build")
set(GAR_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${GAR_PREFIX}")

set(GAR_INCLUDE_DIR "${GAR_PREFIX}/include" CACHE INTERNAL "graphar cpp include directory")
set(GAR_BUILD_BYPRODUCTS "${GAR_DYNAMIC_LIB}")

set(GAR_VERSION_TO_BUILD "v0.9.0" CACHE INTERNAL "GraphAr version")
set(GAR_ARROW_SOURCE_FILE "https://www.apache.org/dyn/closer.lua?action=download&filename=arrow/arrow-${ARROW_VERSION_TO_BUILD}/apache-arrow-${ARROW_VERSION_TO_BUILD}.tar.gz")

include(ExternalProject)
ExternalProject_Add(graphar_ep
GIT_REPOSITORY https://github.com/alibaba/GraphAr.git
GIT_TAG ${GAR_VERSION_TO_BUILD}
GIT_SHALLOW TRUE
GIT_SUBMODULES ""
SOURCE_SUBDIR cpp
BINARY_DIR "${GAR_BINARY_DIR}"
CMAKE_ARGS "${GAR_CMAKE_ARGS}"
BUILD_BYPRODUCTS "${GAR_BUILD_BYPRODUCTS}")

set(GAR_LIBRARY_TARGET gar_dynamic)

file(MAKE_DIRECTORY "${GAR_INCLUDE_DIR}")
add_library(${GAR_LIBRARY_TARGET} STATIC IMPORTED)
set_target_properties(${GAR_LIBRARY_TARGET}
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${GAR_INCLUDE_DIR}
IMPORTED_LOCATION ${GAR_DYNAMIC_LIB})

add_dependencies(${GAR_LIBRARY_TARGET} graphar_ep)
endfunction()

0 comments on commit a448cc8

Please sign in to comment.