diff options
author | Muxi Yan <mxyan@google.com> | 2018-01-19 17:35:33 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-01-19 17:35:33 -0800 |
commit | bc4b7891c808cf5f0d0ad473d5a9078e7d7a4394 (patch) | |
tree | c46e045df16608d4748d6c3bd97aeb548b244bfe /examples/cpp/helloworld | |
parent | 61bb29f1411db01732f9a9cd6e153882992726ee (diff) | |
parent | fb309a966b1782a5c4afe6956344770d1ddefe71 (diff) |
Merge remote-tracking branch 'upstream/master' into create-grpc-c++-podspec
Diffstat (limited to 'examples/cpp/helloworld')
-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()
|