Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
dogun-anduril authored Dec 3, 2024
1 parent 9b6221b commit 4f8e084
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
include(CMakePackageConfigHelpers)
include(FetchContent)

cmake_minimum_required(VERSION 3.16)
project(lattice-sdk-cpp LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_ENABLE_INSTALL ON)
set(FETCHCONTENT_QUIET OFF)

## Get all the Proto generated files
file(GLOB_RECURSE lattice-sdk_SOURCES src/*.cc)
Expand All @@ -23,7 +27,72 @@ target_include_directories(${PROJECT_NAME}
)

# Find system-installed gRPC and Protobuf libraries
find_package(Protobuf 29.0.0 CONFIG REQUIRED)
find_package(gRPC 1.68.0 CONFIG REQUIRED)

# Specify the dependencies
option(USE_SYSTEM_GRPC_PROTOBUF "Use system installed gRPC" OFF)
if(USE_SYSTEM_GRPC_PROTOBUF)
# Find system-installed gRPC and Protobuf libraries
find_package(gRPC 1.68.0 CONFIG REQUIRED)
find_package(protobuf 29.0.0 CONFIG REQUIRED)
else()
find_package(ZLIB REQUIRED)

# Build gRPC and Protobuf using FetchContent
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/google/protobuf
GIT_TAG v29.0
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
USES_TERMINAL_DOWNLOAD TRUE
GIT_SUBMODULES_RECURSE TRUE
GIT_SUBMODULES ""
)
set(protobuf_BUILD_TESTS OFF)
set(protobuf_BUILD_CONFORMANCE OFF)
set(protobuf_BUILD_EXAMPLES OFF)
set(protobuf_BUILD_LIBPROTOC OFF)
set(protobuf_DISABLE_RTTI ON)
set(protobuf_MSVC_STATIC_RUNTIME ON)
set(protobuf_WITH_ZLIB OFF)

FetchContent_MakeAvailable(protobuf)
# Build gRPC and Protobuf using FetchContent
FetchContent_Declare(
gRPC
GIT_REPOSITORY https://github.com/grpc/grpc
GIT_TAG v1.68.0
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
USES_TERMINAL_DOWNLOAD TRUE
GIT_SUBMODULES_RECURSE TRUE
GIT_SUBMODULES
"third_party/cares"
"third_party/boringssl-with-bazel"
"third_party/re2"
"third_party/abseil-cpp"
)

set(gRPC_BUILD_TESTS OFF)
set(gRPC_BUILD_CODEGEN OFF) # for grpc_cpp_plugin
set(gRPC_BUILD_GRPC_CPP_PLUGIN OFF) # we want to use only C++ plugin
set(gRPC_BUILD_CSHARP_EXT OFF)
set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF)
set(gRPC_BUILD_GRPC_NODE_PLUGIN OFF)
set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF)
set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF)
set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF)
set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF)

set(gRPC_BENCHMARK_PROVIDER "none" CACHE STRING "" FORCE)
set(gRPC_PROTOBUF_PROVIDER "package" CACHE STRING "" FORCE)
set(gRPC_ZLIB_PROVIDER "package" CACHE STRING "" FORCE)

# use lite protobuf version, unless we start using features
# that require full protobuf
set(gRPC_USE_PROTO_LITE ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(gRPC)
endif()

target_link_libraries(${PROJECT_NAME} PUBLIC gRPC::grpc++ protobuf::libprotobuf)

0 comments on commit 4f8e084

Please sign in to comment.