Skip to content

Commit

Permalink
C++ Client: making build work for both Linux and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak committed Feb 8, 2024
1 parent f77e85a commit 645eb88
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 49 deletions.
3 changes: 2 additions & 1 deletion cpp-client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
cmake-build-debug
cmake-build-release
cmake-build-relwithdebinfo
cmake-build-relwithdebinfo
vcpkg_installed
4 changes: 1 addition & 3 deletions cpp-client/deephaven/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}
Expand Down
62 changes: 62 additions & 0 deletions cpp-client/deephaven/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
29 changes: 19 additions & 10 deletions cpp-client/deephaven/dhclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/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++)
Expand Down
53 changes: 19 additions & 34 deletions cpp-client/deephaven/dhcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,51 +98,36 @@ 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/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
# (see second answer, "Since CMake version 2.8.8, you can ...")
# 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 $<TARGET_OBJECTS:dhcore_objlib>)
# 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>)
target_link_libraries(dhcore PUBLIC ${object_link_libs})
target_link_libraries(dhcore PUBLIC immer)

add_library(dhcore_static STATIC $<TARGET_OBJECTS:dhcore_objlib>)
# 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/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)
9 changes: 8 additions & 1 deletion cpp-client/deephaven/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions cpp-client/deephaven/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
17 changes: 17 additions & 0 deletions cpp-client/deephaven/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}

0 comments on commit 645eb88

Please sign in to comment.