From 863dddca69983485fdc3faf58c7dd439d0d5bf5d Mon Sep 17 00:00:00 2001
From: Kyle Manna <kyle@kylemanna.com>
Date: Thu, 15 Oct 2015 13:56:20 -0700
Subject: [PATCH] cmake: Auto discover NANOPB_SRC_ROOT_FOLDER

* Use CMAKE_CURRENT_LIST_DIR to learn the path of the currently running
  file to determine location of NanoPB.
* Simplifies use in other projects.
---
 extra/FindNanopb.cmake | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/extra/FindNanopb.cmake b/extra/FindNanopb.cmake
index 7734a93..9afb21d 100644
--- a/extra/FindNanopb.cmake
+++ b/extra/FindNanopb.cmake
@@ -1,10 +1,6 @@
 # This is an example script for use with CMake projects for locating and configuring
 # the nanopb library.
 #
-# The following varialbes have to be set:
-#
-#   NANOPB_SRC_ROOT_FOLDER  - Path to nanopb source folder
-#
 # The following variables can be set and are optional:
 #
 #
@@ -217,6 +213,12 @@ if(NOT DEFINED NANOPB_GENERATE_CPP_APPEND_PATH)
   set(NANOPB_GENERATE_CPP_APPEND_PATH TRUE)
 endif()
 
+# Make a really good guess regarding location of NANOPB_SRC_ROOT_FOLDER
+if(NOT DEFINED NANOPB_SRC_ROOT_FOLDER)
+  get_filename_component(NANOPB_SRC_ROOT_FOLDER
+                         ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE)
+endif()
+
 # Find the include directory
 find_path(NANOPB_INCLUDE_DIRS
     pb.h
-- 
2.16.6