From 9fd6b23ddc14d829567d00f49e4cec41d1b23172 Mon Sep 17 00:00:00 2001 From: martin4861 Date: Thu, 5 Jun 2025 19:58:51 +0200 Subject: [PATCH] Adapt FindNanopb.cmake to allow the usage of the official sources. Backwards compatibility is kept --- FindNanopb.cmake | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/FindNanopb.cmake b/FindNanopb.cmake index ed94fe2..2dd7487 100644 --- a/FindNanopb.cmake +++ b/FindNanopb.cmake @@ -12,8 +12,40 @@ include("GenericFindDependency") option(nanopb_BUILD_GENERATOR "" OFF) -GenericFindDependency( - TARGET protobuf-nanopb - SOURCE_DIR "nanopb" - SYSTEM_INCLUDES -) + +if(USE_OFFICIAL_NANOPB) + # Using official Nanopb from github and therefore manually including FindNanopb.cmake + GenericFindDependency( + TARGET protobuf-nanopb-static + SOURCE_DIR "nanopb" + SYSTEM_INCLUDES + ) + + # Instead of patches to the official Nanopb, we need to make all the adaptions here + include("${nanopb_SOURCE_DIR}/extra/FindNanopb.cmake") + target_include_directories( + protobuf-nanopb-static + PUBLIC + $ + ) + # without this, the compilations fails due to C99 asserts + target_compile_definitions( + protobuf-nanopb-static + PUBLIC + PB_NO_STATIC_ASSERT + ) + # This is needed to avoid warnings about switch statements on enum types + target_compile_options( + protobuf-nanopb-static + PUBLIC + -Wno-switch-enum + ) + # This is how the lib is used + add_library(protobuf-nanopb ALIAS protobuf-nanopb-static) +else() + GenericFindDependency( + TARGET protobuf-nanopb + SOURCE_DIR "nanopb" + SYSTEM_INCLUDES + ) +endif()