From db14b7793fb7e6cb9a5492fd34f992707a34cc4b Mon Sep 17 00:00:00 2001
From: miro <mdrahos@aurisrobotics.com>
Date: Wed, 22 Jun 2016 16:54:30 -0700
Subject: [PATCH] Removing semicolon in FindProtobuf.cmake and adding a test
 for FindProtobuf

---
 Modules/FindProtobuf.cmake                | 12 ++++++------
 Tests/CMakeLists.txt                      |  4 ++++
 Tests/FindProtobuf/CMakeLists.txt         | 24 ++++++++++++++++++++++++
 Tests/FindProtobuf/Test/TestMessage.proto |  5 +++++
 Tests/FindProtobuf/Test/main.cxx          | 10 ++++++++++
 5 files changed, 49 insertions(+), 6 deletions(-)
 create mode 100644 Tests/FindProtobuf/CMakeLists.txt
 create mode 100644 Tests/FindProtobuf/Test/TestMessage.proto
 create mode 100644 Tests/FindProtobuf/Test/main.cxx

diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index c90a0a2..f1cf5db 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -122,11 +122,11 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
       get_filename_component(ABS_PATH ${ABS_FIL} PATH)
       list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
       if(${_contains_already} EQUAL -1)
-          list(APPEND _protobuf_include_path -I ${ABS_PATH})
+          list(APPEND _protobuf_include_path "-I${ABS_PATH}")
       endif()
     endforeach()
   else()
-    set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+    set(_protobuf_include_path "-I${CMAKE_CURRENT_SOURCE_DIR}")
   endif()
 
   if(DEFINED Protobuf_IMPORT_DIRS)
@@ -134,7 +134,7 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
       get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
       list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
       if(${_contains_already} EQUAL -1)
-          list(APPEND _protobuf_include_path -I ${ABS_PATH})
+          list(APPEND _protobuf_include_path "-I${ABS_PATH}")
       endif()
     endforeach()
   endif()
@@ -180,11 +180,11 @@ function(PROTOBUF_GENERATE_PYTHON SRCS)
       get_filename_component(ABS_PATH ${ABS_FIL} PATH)
       list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
       if(${_contains_already} EQUAL -1)
-          list(APPEND _protobuf_include_path -I ${ABS_PATH})
+          list(APPEND _protobuf_include_path "-I${ABS_PATH}")
       endif()
     endforeach()
   else()
-    set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+    set(_protobuf_include_path "-I${CMAKE_CURRENT_SOURCE_DIR}")
   endif()
 
   if(DEFINED Protobuf_IMPORT_DIRS)
@@ -192,7 +192,7 @@ function(PROTOBUF_GENERATE_PYTHON SRCS)
       get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
       list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
       if(${_contains_already} EQUAL -1)
-          list(APPEND _protobuf_include_path -I ${ABS_PATH})
+          list(APPEND _protobuf_include_path "-I${ABS_PATH}")
       endif()
     endforeach()
   endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 5911682..79d2faa 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1401,6 +1401,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
     add_subdirectory(FindPNG)
   endif()
 
+  if(CMake_TEST_FindProtobuf)
+    add_subdirectory(FindProtobuf)
+  endif()
+
   if(CMake_TEST_FindTIFF)
     add_subdirectory(FindTIFF)
   endif()
diff --git a/Tests/FindProtobuf/CMakeLists.txt b/Tests/FindProtobuf/CMakeLists.txt
new file mode 100644
index 0000000..c6ce75c
--- /dev/null
+++ b/Tests/FindProtobuf/CMakeLists.txt
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindProtobuf CXX)
+include(CTest)
+
+#CMake does not actually provide FindProtobuf publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(Protobuf REQUIRED)
+
+#Run protoc to generate the cpp sources:
+protobuf_generate_cpp(
+  ProtoSources ProtoHeaders # outputs
+  ${CMAKE_CURRENT_SOURCE_DIR}/Test/TestMessage.proto # input
+  )
+
+#build the binary and add test
+add_executable(test_protobuf
+  ${CMAKE_CURRENT_SOURCE_DIR}/Test/main.cxx
+  ${ProtoSources}
+  ${ProtoHeaders}
+  )
+target_include_directories(test_protobuf PRIVATE ${Protobuf_INCLUDE_DIRS})
+target_link_libraries(test_protobuf ${Protobuf_LIBRARIES})
+add_test(NAME test_FindProtobuf COMMAND test_protobuf)
diff --git a/Tests/FindProtobuf/Test/TestMessage.proto b/Tests/FindProtobuf/Test/TestMessage.proto
new file mode 100644
index 0000000..4e38f43
--- /dev/null
+++ b/Tests/FindProtobuf/Test/TestMessage.proto
@@ -0,0 +1,5 @@
+// Dummy protobuf message
+message TestMessage
+{
+    optional string testfield = 1;
+}
diff --git a/Tests/FindProtobuf/Test/main.cxx b/Tests/FindProtobuf/Test/main.cxx
new file mode 100644
index 0000000..70da58e
--- /dev/null
+++ b/Tests/FindProtobuf/Test/main.cxx
@@ -0,0 +1,10 @@
+#include "TestMessage.pb.h" // generated by protoc
+
+//==================================================
+int main(int, char**)
+{
+  TestMessage message;
+  message.set_testfield("works!");
+
+  return 0;
+}
-- 
2.5.0

