include(CMakeFindDependencyMacro)
find_package(OpenSSL REQUIRED)
set(OPENSSL_TARGET OpenSSL::Crypto)

find_package(Protobuf)
if(Protobuf_FOUND)
    if(Protobuf_VERSION VERSION_LESS 3.5)
        message(FATAL_ERROR "Version of Protobuf too old (${Protobuf_VERSION}), should be >=3.5.")
    elseif(NOT TARGET protobuf::libprotobuf)
        message(AUTHOR_WARNING "Cmake too old to define protobuf::libprotobuf, will try PkgConfig instead.")
    else()
        set(PROTOBUF_TARGET protobuf::libprotobuf)
    endif()
endif()

if(NOT DEFINED PROTOBUF_TARGET)
    find_dependency(PkgConfig)
    pkg_check_modules(protobuf REQUIRED IMPORTED_TARGET protobuf>=3.5)
    set(PROTOBUF_TARGET PkgConfig::protobuf)
    set(PROTOBUF_INCLUDE_DIRS ${protobuf_INCLUDE_DIRS})
endif()

find_package(gRPC)
if(gRPC_FOUND)
    set(GRPC_TARGET gRPC::grpc++)
else()
    find_dependency(PkgConfig)
    pkg_check_modules(grpc++ REQUIRED IMPORTED_TARGET grpc++>=1.10)
    set(GRPC_TARGET PkgConfig::grpc++)
endif()

if(NOT APPLE)
    find_dependency(PkgConfig)
    pkg_check_modules(uuid REQUIRED IMPORTED_TARGET uuid)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/BuildboxGlogSetup.cmake")

include("${CMAKE_CURRENT_LIST_DIR}/BuildboxCommonTargets.cmake")
