diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/.gitignore b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/.gitignore index c8c0f0a42c1e5..f2f4387daf9eb 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/.gitignore +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/.gitignore @@ -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 diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/CMakeLists.txt b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/CMakeLists.txt index dc8a1ae13bd5d..037b6fcb9fad6 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/CMakeLists.txt +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/CMakeLists.txt @@ -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) diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/CMakeLists.txt b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/CMakeLists.txt index f7e4be1721765..e6653f79b1703 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/CMakeLists.txt +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/CMakeLists.txt @@ -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 openssl@1.1 +# add to the cmake line -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl@1.1/1.1.1m +if (NOT DEFINED OPENSSL_ROOT_DIR AND DEFINED APPLE) + set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl@1.1/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}/$/lib + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/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}/$/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/$/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) diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/flight_sql_connection.h b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/flight_sql_connection.h index 076486132cea1..81fee8485737a 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/flight_sql_connection.h +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/flight_sql_connection.h @@ -19,7 +19,7 @@ #include "connection.h" #include -#include +#include namespace driver { namespace flight_sql { diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/main.cc b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/main.cc index 8aec9848b8fa3..aff19a4bee3c0 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/main.cc +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/flight_sql/main.cc @@ -17,7 +17,7 @@ #include "flight_sql_driver.h" #include -#include +#include #include using arrow::Status; diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/CMakeLists.txt b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/CMakeLists.txt index 6c9e634629de6..558cc2dbcb40d 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/CMakeLists.txt +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/CMakeLists.txt @@ -18,4 +18,10 @@ include(FindODBC) add_library(spi connection.cc exceptions.cc) +set_target_properties(spi + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib + ) target_link_libraries(spi ${ODBC_LIBRARIES}) diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.cc b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.cc index c97976be44be5..26daa725f0dd8 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.cc +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.cc @@ -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(); } diff --git a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.h b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.h index d97b735e11160..be3ab854304d8 100644 --- a/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.h +++ b/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/spi/exceptions.h @@ -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_;