From 645eb88ebd5dcc737b1754b1d8347011f45e075f Mon Sep 17 00:00:00 2001 From: Corey Kosak Date: Sun, 5 Nov 2023 15:19:42 -0500 Subject: [PATCH] C++ Client: making build work for both Linux and Windows --- cpp-client/.gitignore | 3 +- cpp-client/deephaven/CMakeLists.txt | 4 +- cpp-client/deephaven/CMakePresets.json | 62 +++++++++++++++++++ cpp-client/deephaven/dhclient/CMakeLists.txt | 29 ++++++--- cpp-client/deephaven/dhcore/CMakeLists.txt | 53 ++++++---------- cpp-client/deephaven/tests/CMakeLists.txt | 9 ++- cpp-client/deephaven/vcpkg-configuration.json | 14 +++++ cpp-client/deephaven/vcpkg.json | 17 +++++ 8 files changed, 142 insertions(+), 49 deletions(-) create mode 100644 cpp-client/deephaven/CMakePresets.json create mode 100644 cpp-client/deephaven/vcpkg-configuration.json create mode 100644 cpp-client/deephaven/vcpkg.json diff --git a/cpp-client/.gitignore b/cpp-client/.gitignore index 99df1040061..1893d77be34 100644 --- a/cpp-client/.gitignore +++ b/cpp-client/.gitignore @@ -1,4 +1,5 @@ *~ cmake-build-debug cmake-build-release -cmake-build-relwithdebinfo \ No newline at end of file +cmake-build-relwithdebinfo +vcpkg_installed diff --git a/cpp-client/deephaven/CMakeLists.txt b/cpp-client/deephaven/CMakeLists.txt index 9f615ecbaa4..dd104c9daab 100644 --- a/cpp-client/deephaven/CMakeLists.txt +++ b/cpp-client/deephaven/CMakeLists.txt @@ -13,8 +13,6 @@ set(CMAKE_CXX_STANDARD 17) # for CMAKE_INSTALL_{dir} include(GNUInstallDirs) -add_compile_options(-Wall -Werror -Wno-deprecated-declarations) - # To enable address sanitizer, add `-DSANITIZE_ADDRESS=ON` to # the list of options you pass for running cmake. option(SANITIZE_ADDRESS "Enable address sanitizer" "OFF") @@ -36,7 +34,7 @@ install(DIRECTORY dhcore/include/public/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -install(TARGETS dhclient dhcore_static dhcore +install(TARGETS dhclient dhcore EXPORT deephavenConfig ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/cpp-client/deephaven/CMakePresets.json b/cpp-client/deephaven/CMakePresets.json new file mode 100644 index 00000000000..a6893f58f5f --- /dev/null +++ b/cpp-client/deephaven/CMakePresets.json @@ -0,0 +1,62 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "windows-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-debug", + "displayName": "x64 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-release", + "displayName": "x64 Release", + "inherits": "x64-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x86-debug", + "displayName": "x86 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x86-release", + "displayName": "x86 Release", + "inherits": "x86-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ] +} diff --git a/cpp-client/deephaven/dhclient/CMakeLists.txt b/cpp-client/deephaven/dhclient/CMakeLists.txt index 0d482549520..bf72d72ff31 100644 --- a/cpp-client/deephaven/dhclient/CMakeLists.txt +++ b/cpp-client/deephaven/dhclient/CMakeLists.txt @@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD 17) # for CMAKE_INSTALL_{dir} include(GNUInstallDirs) -find_package(Arrow REQUIRED) -find_package(ArrowFlight REQUIRED HINTS ${Arrow_DIR}) +find_package(Arrow CONFIG REQUIRED) +find_package(ArrowFlight CONFIG REQUIRED) find_package(Immer REQUIRED) find_package(Protobuf CONFIG REQUIRED) find_package(gRPC CONFIG REQUIRED) @@ -97,26 +97,35 @@ set(ALL_FILES proto/deephaven/proto/ticket.pb.h ) -add_library(dhclient ${ALL_FILES}) -# In order to make a shared library suitable for Cython. -set_property(TARGET dhclient PROPERTY POSITION_INDEPENDENT_CODE ON) +add_library(dhclient SHARED ${ALL_FILES}) # This is so deephaven::client works both when using the installed CMake config # and when using this project as a CMake subdirectory of your own project. add_library(deephaven::client ALIAS dhclient) -target_compile_options(dhclient PRIVATE -Wall -Werror -Wno-deprecated-declarations) + +set_property(TARGET dhclient PROPERTY POSITION_INDEPENDENT_CODE ON) + +if (LINUX) + target_compile_options(dhclient PRIVATE -Wall -Werror -Wno-deprecated-declarations) +endif() + +if (WIN32) + # /Wall is a bit too chatty so we stick with /W3 + # /bigobj needed because ticking/immer_table_state.cc compiles to something too large apparently + target_compile_options(dhclient PRIVATE /W3 /bigobj) +endif() target_include_directories(dhclient PRIVATE include/private) target_include_directories(dhclient PUBLIC $) - # Protos and flatbuf are doing their own thing. target_include_directories(dhclient PRIVATE "./proto") target_include_directories(dhclient PRIVATE "./flatbuf") -target_link_libraries(dhclient PUBLIC dhcore) +# same as above +target_link_libraries(dhclient PUBLIC deephaven::dhcore) -target_link_libraries(dhclient PUBLIC arrow_flight_static) -target_link_libraries(dhclient PUBLIC arrow_static) +target_link_libraries(dhclient PUBLIC ArrowFlight::arrow_flight_shared) +target_link_libraries(dhclient PUBLIC Arrow::arrow_shared) target_link_libraries(dhclient PUBLIC immer) target_link_libraries(dhclient PUBLIC protobuf::libprotobuf) target_link_libraries(dhclient PUBLIC gRPC::grpc++) diff --git a/cpp-client/deephaven/dhcore/CMakeLists.txt b/cpp-client/deephaven/dhcore/CMakeLists.txt index 4e4cec1b09a..19f0400280a 100644 --- a/cpp-client/deephaven/dhcore/CMakeLists.txt +++ b/cpp-client/deephaven/dhcore/CMakeLists.txt @@ -98,23 +98,6 @@ set(ALL_FILES third_party/date/include/date/date.h ) -add_library(dhcore_objlib OBJECT ${ALL_FILES}) -# In order to make a shared library suitable for Cython. -set_property(TARGET dhcore_objlib PROPERTY POSITION_INDEPENDENT_CODE ON) - -target_compile_options(dhcore_objlib PRIVATE -Wall -Werror -Wno-deprecated-declarations) - -target_include_directories(dhcore_objlib PRIVATE include/private) -target_include_directories(dhcore_objlib PRIVATE third_party/flatbuffers/include) -target_include_directories(dhcore_objlib PRIVATE third_party/date/include) -target_include_directories(dhcore_objlib PRIVATE third_party/roaring/include) -target_include_directories(dhcore_objlib PUBLIC $) - -# The flatbuf include directory is in its own part of the tree. -target_include_directories(dhcore_objlib PRIVATE "./flatbuf") - -target_link_libraries(dhcore_objlib PUBLIC immer) - # # shared and static libraries built from the same object files # https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-library-at-the-sam @@ -122,27 +105,29 @@ target_link_libraries(dhcore_objlib PUBLIC immer) # https://stackoverflow.com/questions/38832528/transitive-target-include-directories-on-object-libraries # -get_property(object_link_libs TARGET dhcore_objlib PROPERTY LINK_LIBRARIES) +add_library(dhcore SHARED ${ALL_FILES}) + +# This is so deephaven::dhcore works both when using the installed CMake config +# and when using this project as a CMake subdirectory of your own project. +add_library(deephaven::dhcore ALIAS dhcore) + +set_property(TARGET dhcore PROPERTY POSITION_INDEPENDENT_CODE ON) + +if (LINUX) + target_compile_options(dhcore PRIVATE -Wall -Werror -Wno-deprecated-declarations) +endif() + +if (WIN32) + # /Wall is a bit too chatty so we stick with /W3 + # /bigobj needed because ticking/immer_table_state.cc compiles to something too large apparently + target_compile_options(dhcore PRIVATE /W3 /bigobj) +endif() -add_library(dhcore SHARED $) -# TODO: How to avoid repetition here for target_include_directories? target_include_directories(dhcore PRIVATE include/private) target_include_directories(dhcore PRIVATE third_party/date/include) target_include_directories(dhcore PRIVATE third_party/flatbuffers/include) target_include_directories(dhcore PRIVATE third_party/roaring/include) +target_include_directories(dhcore PRIVATE flatbuf) target_include_directories(dhcore PUBLIC $) -target_link_libraries(dhcore PUBLIC ${object_link_libs}) +target_link_libraries(dhcore PUBLIC immer) -add_library(dhcore_static STATIC $) -# TODO: How to avoid repetition here for target_include_directories? -target_include_directories(dhcore_static PRIVATE include/private) -target_include_directories(dhcore_static PRIVATE third_party/date/include) -target_include_directories(dhcore_static PRIVATE third_party/flatbuffers/include) -target_include_directories(dhcore_static PRIVATE third_party/roaring/include) -target_include_directories(dhcore_static PUBLIC $) -target_link_libraries(dhcore_static PUBLIC ${object_link_libs}) - -# This is so deephaven::dhcore works both when using the installed CMake config -# and when using this project as a CMake subdirectory of your own project. -add_library(deephaven::dhcore ALIAS dhcore) -add_library(deephaven::dhcore_static ALIAS dhcore_static) diff --git a/cpp-client/deephaven/tests/CMakeLists.txt b/cpp-client/deephaven/tests/CMakeLists.txt index c5710d66392..9c58099723e 100644 --- a/cpp-client/deephaven/tests/CMakeLists.txt +++ b/cpp-client/deephaven/tests/CMakeLists.txt @@ -36,7 +36,14 @@ add_executable(tests third_party/catch.hpp ) -target_compile_options(tests PRIVATE -Wall -Werror) +if (LINUX) + target_compile_options(tests PRIVATE -Wall -Werror -Wno-deprecated-declarations) +endif() + +if (WIN32) + target_compile_options(tests PRIVATE /W3) +endif() + target_include_directories(tests PUBLIC "..") target_link_libraries(tests deephaven::client) diff --git a/cpp-client/deephaven/vcpkg-configuration.json b/cpp-client/deephaven/vcpkg-configuration.json new file mode 100644 index 00000000000..1da16750d5f --- /dev/null +++ b/cpp-client/deephaven/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "0dc005fb66801c8a8266e81bd2cedb4d5501f30e", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/cpp-client/deephaven/vcpkg.json b/cpp-client/deephaven/vcpkg.json new file mode 100644 index 00000000000..1731d32195a --- /dev/null +++ b/cpp-client/deephaven/vcpkg.json @@ -0,0 +1,17 @@ +{ + "dependencies": [ + "immer", + "grpc", + { + "name": "arrow", + "features": [ + "flight" + ] + } + ], + + "overrides": [ + { "name": "arrow", "version": "13.0.0#1" }, + { "name": "protobuf", "version": "3.21.2" } + ] +}