Wifi provisioning sample not working with nanopb in 2.7.0

Dear Devzone,

I can no longer build Nordic's Wifi provisioning (BLE) sample together with custom nanopb code using SDK version 2.7.0. It worked fine in 2.6.1. 

Steps to reproduce:

1) Create a new application based on Wifi provisioning (BLE) sample

2) Add the following to your CMakeLists.txt between project() and target_sources:

list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

zephyr_nanopb_sources(app src/simple.proto)

3) Add `simple.proto` and `simple.options` to your `src` folder (files taken from Zephyr's nanopb sample)

4) The following error appears while building:

CMake Error at C:/ncs/v2.7.0/modules/lib/nanopb/extra/FindNanopb.cmake:406 (add_library):
add_library cannot create target "nanopb" because another target with the
same name already exists. The existing target is a static library created
in source directory
"C:/ncs/v2.7.0/nrf/subsys/bluetooth/services/wifi_prov". See documentation
for policy CMP0002 for more details.
Call Stack (most recent call first):
C:/ncs/v2.7.0/zephyr/modules/nanopb/nanopb.cmake:10 (find_package)
CMakeLists.txt:13 (include)

Could you please tell me how to fix this?

Thanks!

  • Hi,

     

    Thank you for providing a method of reproducing the issue.

    I am checking internally with R&D to see if there is something that we can do here. I will get back to you within a few business days with more information.

     

    Kind regards,

    Håkon

  • Hi,

     

    Thank you for your patience in this matter.

    CMake Error at C:/ncs/v2.7.0/modules/lib/nanopb/extra/FindNanopb.cmake:406 (add_library):
    add_library cannot create target "nanopb" because another target with the
    same name already exists. The existing target is a static library created
    in source directory
    "C:/ncs/v2.7.0/nrf/subsys/bluetooth/services/wifi_prov". See documentation
    for policy CMP0002 for more details.
    Call Stack (most recent call first):
    C:/ncs/v2.7.0/zephyr/modules/nanopb/nanopb.cmake:10 (find_package)
    CMakeLists.txt:13 (include)

    The issue is that nanopb is included twice, once in wifi_prov and once in the application. Omitting the find_package() and following the similar "setup" as in the wifi_prov:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.7.0/subsys/bluetooth/services/wifi_prov/CMakeLists.txt#L8-L19

     

    Here's a snapshot of my CMakeLists.txt for testing:

    #
    # Copyright (c) 2022 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    set(PROTOC_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
    set(NANOPB_OPTIONS "nanopb_BUILD_RUNTIME OFF")
    set(CMAKE_MODULE_PATH ${ZEPHYR_NANOPB_MODULE_DIR}/extra)
    set(NANOPB_GENERATE_CPP_STANDALONE FALSE)
    nanopb_generate_cpp(proto_sources proto_headers
      src/simple.proto
    )
    
    project(wifi_ble_provisioning)
    
    target_sources(app PRIVATE src/main.c)

     

    Could you try this and see if that works as expected on your end?

     

    Kind regards,

    Håkon

  • Good suggestions but I have to tweak a little to make it work. Here is what I have

    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    set(PROTOC_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
    set(NANOPB_OPTIONS "-I${CMAKE_SOURCE_DIR}")
    set(NANOPB_OPTIONS "nanopb_BUILD_RUNTIME OFF")
    set(CMAKE_MODULE_PATH ${ZEPHYR_NANOPB_MODULE_DIR}/extra)
    set(NANOPB_GENERATE_CPP_STANDALONE FALSE)
    nanopb_generate_cpp(proto_sources proto_headers RELPATH .
      src/Simple.proto
    )
    
    zephyr_library_include_directories(${CMAKE_CURRENT_BINARY_DIR})
    target_sources(app PRIVATE ${proto_sources} ${proto_headers} src/main.c)

  • Hi,

    Glad to hear that you were able to get it running as expected!

     

    Kind regards,

    Håkon

Related