Skip to content

Commit

Permalink
Merge pull request #8 from jcralmeida/get-arrow-with-cmake-and-git
Browse files Browse the repository at this point in the history
Fix mac build issues
  • Loading branch information
Rafael Telles authored Jan 12, 2022
2 parents 92aac3c + c278668 commit 7310967
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 16 deletions.
9 changes: 9 additions & 0 deletions flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ cmake-build-*/

.idea
vcpkg_installed
*-prefix
_deps
lib

build.*
.ninja_*
*lib*.a
*arrow_odbc_spi_impl_cli
*arrow_odbc_spi_impl_test
15 changes: 15 additions & 0 deletions flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,20 @@ set(CMAKE_CXX_STANDARD 11)

project(flightsql_odbc)

# Add Boost dependencies. Should be pre-installed (Brew on Mac).
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Fetch and include GTest
# Adapted from Google's documentation: https://google.github.io/googletest/quickstart-cmake.html#set-up-a-project
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

add_subdirectory(flight_sql)
add_subdirectory(spi)
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,113 @@ set(CMAKE_CXX_STANDARD 11)
include_directories(${CMAKE_SOURCE_DIR}/spi)

SET(Arrow_STATIC ON)
find_package(Arrow REQUIRED)
find_package(ArrowFlight REQUIRED PATHS /usr/local/lib/cmake/arrow/)
find_package(ArrowFlightSql REQUIRED PATHS /usr/local/lib/cmake/arrow/)
find_package(GTest REQUIRED)

# Get Arrow using git.
include(ExternalProject)

set(ARROW_CMAKE_ARGS
-DARROW_FLIGHT=ON
-DARROW_FLIGHT_SQL=ON
-DARROW_IPC=ON
-DARROW_COMPUTE=OFF
-DARROW_BUILD_SHARED=OFF
-DARROW_BUILD_STATIC=ON
-DARROW_COMPUTE=ON
-DARROW_BUILD_TESTS=OFF
-DARROW_DEPENDENCY_USE_SHARED=OFF
-DCMAKE_DEPENDS_USE_COMPILER=FALSE
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ApacheArrow-prefix/src/ApacheArrow-install
${CMAKE_CURRENT_BINARY_DIR}/ApacheArrow-prefix/src/ApacheArrow/cpp
)

if(NOT ARROW_GIT_REPOSITORY)
set(ARROW_GIT_REPOSITORY https://github.com/apache/arrow.git)
endif()
if(NOT ARROW_GIT_TAG)
set(ARROW_GIT_TAG master)
endif()

message("Using Arrow from ${ARROW_GIT_REPOSITORY} on tag ${ARROW_GIT_TAG}")
ExternalProject_Add(ApacheArrow
GIT_REPOSITORY ${ARROW_GIT_REPOSITORY}
GIT_TAG ${ARROW_GIT_TAG}
CMAKE_ARGS ${ARROW_CMAKE_ARGS})

include_directories(${CMAKE_CURRENT_BINARY_DIR}/ApacheArrow-prefix/src/ApacheArrow-install/include)
link_directories(${CMAKE_CURRENT_BINARY_DIR}/ApacheArrow-prefix/src/ApacheArrow-install/lib)

# Add Zlib dependencies needed by Arrow Flight. Should be pre-installed.
find_package(ZLIB REQUIRED)

# Add Protobuf dependencies needed by Arrow Flight. Should be pre-installed.
set(Protobuf_USE_STATIC_LIBS ON)
find_package(Protobuf REQUIRED)

# Add OpenSSL dependencies needed by Arrow Flight. Should be pre-installed.
# May need to set OPENSSL_ROOT_DIR first. On Mac if using brew:
# brew install [email protected]
# add to the cmake line -DOPENSSL_ROOT_DIR=/usr/local/Cellar/[email protected]/1.1.1m
if (NOT DEFINED OPENSSL_ROOT_DIR AND DEFINED APPLE)
set(OPENSSL_ROOT_DIR /usr/local/Cellar/[email protected]/1.1.1m)
endif()
# This is based on Arrow's FindOpenSSL module. It's not clear if both variables
# need to be set.
set(OpenSSL_USE_STATIC_LIBS ON)
set(OPENSSL_USE_STATIC_LIBS ON)
find_package(OpenSSL REQUIRED)

# Add gRPC dependencies needed by Arrow Flight. Should be pre-installed.
find_package(gRPC 1.36 CONFIG REQUIRED)

enable_testing()

add_library(flight_odbc_driver flight_sql_driver.cc flight_sql_connection.cc flight_sql_auth_method.cc)
target_link_libraries(flight_odbc_driver spi arrow_static arrow_flight arrow_flight_sql)
target_include_directories(flight_odbc_driver PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set(ARROW_ODBC_SPI_SOURCES
flight_sql_driver.cc
flight_sql_connection.cc
flight_sql_auth_method.cc
)

set(ARROW_ODBC_SPI_THIRDPARTY_LIBS
arrow_flight_sql
arrow_flight
arrow
arrow_bundled_dependencies
${ZLIB_LIBRARIES}
${Protobuf_LIBRARIES}
gRPC::grpc++
)

add_library(arrow_odbc_spi_impl ${ARROW_ODBC_SPI_SOURCES})
add_dependencies(arrow_odbc_spi_impl ApacheArrow)

set_target_properties(arrow_odbc_spi_impl
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
)

target_link_libraries(arrow_odbc_spi_impl spi ${ARROW_ODBC_SPI_THIRDPARTY_LIBS})
target_include_directories(arrow_odbc_spi_impl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# CLI
add_executable(flight_odbc_driver_cli main.cc)
target_link_libraries(flight_odbc_driver_cli flight_odbc_driver)
add_executable(arrow_odbc_spi_impl_cli main.cc)
set_target_properties(arrow_odbc_spi_impl_cli
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/bin
)
target_link_libraries(arrow_odbc_spi_impl_cli arrow_odbc_spi_impl)

# Unit tests
add_executable(flight_odbc_driver_test flight_sql_connection_test.cc)
target_link_libraries(flight_odbc_driver_test flight_odbc_driver GTest::gtest GTest::gtest_main)
add_test(connection_test flight_odbc_driver_test)
set(ARROW_ODBC_SPI_TEST_SOURCES
flight_sql_connection_test.cc
)

add_executable(arrow_odbc_spi_impl_test ${ARROW_ODBC_SPI_TEST_SOURCES})
add_dependencies(arrow_odbc_spi_impl_test ApacheArrow)
set_target_properties(arrow_odbc_spi_impl_test
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/$<CONFIG>/bin
)
target_link_libraries(arrow_odbc_spi_impl_test arrow_odbc_spi_impl gtest gtest_main)
add_test(connection_test arrow_odbc_spi_impl_test)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "connection.h"
#include <arrow/flight/api.h>
#include <arrow/flight/flight_sql/api.h>
#include <arrow/flight/sql/api.h>

namespace driver {
namespace flight_sql {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "flight_sql_driver.h"
#include <arrow/flight/api.h>
#include <arrow/flight/flight_sql/api.h>
#include <arrow/flight/sql/api.h>
#include <iostream>

using arrow::Status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
include(FindODBC)

add_library(spi connection.cc exceptions.cc)
set_target_properties(spi
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib
)
target_link_libraries(spi ${ODBC_LIBRARIES})
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DriverException::DriverException(std::string message)
: message_(std::move(message)) {}

const char *
DriverException::what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW {
DriverException::what() const throw() {
return message_.c_str();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DriverException : public std::exception {
public:
explicit DriverException(std::string message);

const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
const char *what() const throw() override;

private:
const std::string message_;
Expand Down

0 comments on commit 7310967

Please sign in to comment.