FindNanopb.cmake: use --nanopb_opt for option passing by default (#752)
The version check gave confusing error messages when protoc was not
found. Because protoc 3.6.0 is now more than 4 years old and present
in all major distributions, the check was removed.
diff --git a/docs/migration.md b/docs/migration.md
index 65d02c5..52711b5 100644
--- a/docs/migration.md
+++ b/docs/migration.md
@@ -18,6 +18,19 @@
only have to call it directly, like this for example:
`strcpy(myvar, NANOPB_VERSION);`
+### FindNanopb.cmake now requires protoc 3.6.0 or newer by default
+
+**Changes:** The default options passing method now uses `--plugin-opt` which
+is supported by protoc 3.6.0 and newer (released in 2018).
+
+**Required actions:** Update `protoc` if needed, or alternatively install
+`grpcio-tools` package from `pip`. If neither is possible, the
+`NANOPB_PROTOC_OLDER_THAN_3_6_0` cmake option can be used to restore the old
+style option passing. Note that it has problems with special characters such
+as `:`.
+
+**Error indications:** "`protoc: Unknown flag: --nanopb_opt`"
+
Nanopb-0.4.4 (2020-11-25)
-------------------------
diff --git a/extra/FindNanopb.cmake b/extra/FindNanopb.cmake
index 4a23aba..a10d794 100644
--- a/extra/FindNanopb.cmake
+++ b/extra/FindNanopb.cmake
@@ -258,17 +258,9 @@
# We need to pass the path to the option files to the nanopb plugin. There are two ways to do it.
# - An older hacky one using ':' as option separator in protoc args preventing the ':' to be used in path.
# - Or a newer one, using --nanopb_opt which requires a version of protoc >= 3.6
- # So we will determine which version of protoc we have available and choose accordingly.
- execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version OUTPUT_VARIABLE PROTOC_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE)
- string(REGEX MATCH "[(0-9)].*.[(0-9)].*.[(0-9)].*" PROTOC_VERSION ${PROTOC_VERSION_STRING})
-
- if(PROTOC_VERSION VERSION_LESS "3.6.0")
- #try to use the older way
- string(REGEX MATCH ":" HAS_COLON_IN_PATH ${NANOPB_PLUGIN_OPTIONS} ${NANOPB_OUT})
- if(HAS_COLON_IN_PATH)
- message(FATAL_ERROR "Your path includes a ':' character used as an option separator for nanopb. Upgrade to protoc version >= 3.6.0 or use a different path.")
- endif()
- set(NANOPB_OPT_STRING "--nanopb_out=${NANOPB_PLUGIN_OPTIONS}:${NANOPB_OUT}")
+ # Since nanopb 0.4.6, --nanopb_opt is the default.
+ if(DEFINED NANOPB_PROTOC_OLDER_THAN_3_6_0)
+ set(NANOPB_OPT_STRING "--nanopb_out=${NANOPB_PLUGIN_OPTIONS}:${NANOPB_OUT}")
else()
set(NANOPB_OPT_STRING "--nanopb_opt=${NANOPB_PLUGIN_OPTIONS}" "--nanopb_out=${NANOPB_OUT}")
endif()