From dec076c4abe7bd5518abab7a8da4e624c49ec655 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 18 Jan 2018 18:26:54 +0100 Subject: fix protobuf usage in the example --- examples/cpp/helloworld/CMakeLists.txt | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'examples/cpp') diff --git a/examples/cpp/helloworld/CMakeLists.txt b/examples/cpp/helloworld/CMakeLists.txt index 49684a13b0..c3ce4d5ba6 100644 --- a/examples/cpp/helloworld/CMakeLists.txt +++ b/examples/cpp/helloworld/CMakeLists.txt @@ -16,15 +16,22 @@ endif() find_package(Protobuf REQUIRED) message(STATUS "Using protobuf ${protobuf_VERSION}") -if(Protobuf_FOUND) - # Protobuf_FOUND is set for package type "CONFIG" - set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) - set(_PROTOBUF_PROTOC protobuf::protoc) -elseif(PROTOBUF_FOUND) - # PROTOBUF_FOUND is set for package type "MODULE" - set(_PROTOBUF_LIBPROTOBUF ${PROTOBUF_LIBRARIES}) - set(_PROTOBUF_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE}) - include_directories(${PROTOBUF_INCLUDE_DIRS}) +# {Protobuf,PROTOBUF}_FOUND is defined based on find_package type ("MODULE" vs "CONFIG"). +# For "MODULE", the case has also changed between cmake 3.5 and 3.6. +# We use the legacy uppercase version for *_LIBRARIES AND *_INCLUDE_DIRS variables +# as newer cmake versions provide them too for backward compatibility. +if(Protobuf_FOUND OR PROTOBUF_FOUND) + if(TARGET protobuf::libprotobuf) + set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) + else() + set(_PROTOBUF_LIBPROTOBUF ${PROTOBUF_LIBRARIES}) + include_directories(${PROTOBUF_INCLUDE_DIRS}) + endif() + if(TARGET protobuf::protoc) + set(_PROTOBUF_PROTOC $) + else() + set(_PROTOBUF_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE}) + endif() else() message(WARNING "Failed to locate libprotobuf and protoc!") endif() -- cgit v1.2.3