diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2018-01-18 18:26:54 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2018-01-18 19:34:20 +0100 |
commit | dec076c4abe7bd5518abab7a8da4e624c49ec655 (patch) | |
tree | db26b61c68562c05b1e461313702ff5e627c9170 /examples/cpp | |
parent | 1e9543deb9c4f8de31dd0dce4dcc429aaa53530d (diff) |
fix protobuf usage in the example
Diffstat (limited to 'examples/cpp')
-rw-r--r-- | examples/cpp/helloworld/CMakeLists.txt | 25 |
1 files changed, 16 insertions, 9 deletions
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 $<TARGET_FILE:protobuf::protoc>)
+ else()
+ set(_PROTOBUF_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
+ endif()
else()
message(WARNING "Failed to locate libprotobuf and protoc!")
endif()
|