From 4f8e08444d6fd720ab917a97880f2fbdec77edfa Mon Sep 17 00:00:00 2001 From: dogun-anduril Date: Mon, 2 Dec 2024 21:55:55 -0800 Subject: [PATCH] Update CMakeLists.txt --- CMakeLists.txt | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a4f9b0..80cd7d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ include(CMakePackageConfigHelpers) +include(FetchContent) + cmake_minimum_required(VERSION 3.16) project(lattice-sdk-cpp LANGUAGES CXX) @@ -6,6 +8,8 @@ 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) @@ -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)