| Upgrade the nanopb checkout to 0.4.7 plus some important build fixes, and |
| change the build/install process to be more reliable. |
| |
| This should be upstreamed, but some pieces of this are not upstreamable in their |
| current state. |
| |
| Upstream-Status: Pending |
| Signed-off-by: Ross Burton <ross.burton@arm.com> |
| |
| diff --git a/external/nanopb/fix-pyhon-name.patch b/external/nanopb/fix-pyhon-name.patch |
| deleted file mode 100644 |
| index ab0e84c..0000000 |
| --- a/external/nanopb/fix-pyhon-name.patch |
| +++ /dev/null |
| @@ -1,41 +0,0 @@ |
| -This patch fixes two issues: |
| - |
| -1. On windows the python3 executable is not allways called "python3". As a result |
| - "protoc" execution can fail due to the shebang in the file. This patch fixes |
| - this by running protoc with the intepreter. |
| - |
| -2. In addition when not running from a virtualenv, the install path for python file |
| - is set to the "user site-packages" to avoid needing elevated access rights. |
| - |
| -diff --git a/CMakeLists.txt b/CMakeLists.txt |
| -index 31c86e7..e827015 100644 |
| ---- a/CMakeLists.txt |
| -+++ b/CMakeLists.txt |
| -@@ -54,13 +54,25 @@ if(nanopb_BUILD_GENERATOR) |
| - string(REGEX REPLACE "([^;]+)" "\\1_pb2.py" generator_proto_py_file "${generator_proto}") |
| - add_custom_command( |
| - OUTPUT ${generator_proto_py_file} |
| -- COMMAND ${nanopb_PROTOC_PATH} --python_out=${PROJECT_BINARY_DIR} -I${PROJECT_SOURCE_DIR}/generator/proto ${generator_proto_file} |
| -+ COMMAND ${Python_EXECUTABLE} ${nanopb_PROTOC_PATH} --python_out=${PROJECT_BINARY_DIR} -I${PROJECT_SOURCE_DIR}/generator/proto ${generator_proto_file} |
| - DEPENDS ${generator_proto_file} |
| - ) |
| - add_custom_target("generate_${generator_proto_py_file}" ALL DEPENDS ${generator_proto_py_file}) |
| -+ |
| -+ if (DEFINED ENV{VIRTUAL_ENV}) |
| -+ set(PYTHON_INSTALL_DIR ${Python_SITELIB} CACHE PATH "Install location for generated python modules.") |
| -+ else() |
| -+ execute_process( |
| -+ COMMAND ${Python_EXECUTABLE} -m site --user-site |
| -+ OUTPUT_VARIABLE PYTHON_USER_SITE |
| -+ OUTPUT_STRIP_TRAILING_WHITESPACE |
| -+ ) |
| -+ set(PYTHON_INSTALL_DIR ${PYTHON_USER_SITE} CACHE PATH "Install location for generated python modules.") |
| -+ endif() |
| -+ |
| - install( |
| - FILES ${PROJECT_BINARY_DIR}/${generator_proto_py_file} |
| -- DESTINATION ${Python_SITELIB} |
| -+ DESTINATION ${PYTHON_INSTALL_DIR} |
| - ) |
| - endforeach() |
| - endif() |
| diff --git a/external/nanopb/nanopb-init-cache.cmake.in b/external/nanopb/nanopb-init-cache.cmake.in |
| index fb8104d..8df41dd 100644 |
| --- a/external/nanopb/nanopb-init-cache.cmake.in |
| +++ b/external/nanopb/nanopb-init-cache.cmake.in |
| @@ -12,11 +12,15 @@ set(BUILD_STATIC_LIBS On CACHE BOOL "") |
| set(nanopb_BUILD_RUNTIME On CACHE BOOL "") |
| set(nanopb_BUILD_GENERATOR On CACHE BOOL "") |
| set(nanopb_MSVC_STATIC_RUNTIME Off BOOL "") |
| -set(nanopb_PROTOC_PATH ${CMAKE_SOURCE_DIR}/generator/protoc CACHE STRING "") |
| + |
| +set(Python_EXECUTABLE "@Python_EXECUTABLE@" CACHE PATH "Location of python3 executable") |
| |
| string(TOUPPER @CMAKE_CROSSCOMPILING@ CMAKE_CROSSCOMPILING) # CMake expects TRUE |
| if (CMAKE_CROSSCOMPILING) |
| set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "") |
| endif() |
| |
| +set(nanopb_PYTHON_INSTDIR_OVERRIDE "@BUILD_INSTALL_DIR@/lib/python" CACHE PATH "") |
| +set(NANOPB_GENERATOR_DIR "@BUILD_INSTALL_DIR@/lib/python" CACHE PATH "") |
| + |
| @_cmake_fragment@ |
| diff --git a/external/nanopb/nanopb.cmake b/external/nanopb/nanopb.cmake |
| index 36465f6..57cf3d6 100644 |
| --- a/external/nanopb/nanopb.cmake |
| +++ b/external/nanopb/nanopb.cmake |
| @@ -28,7 +28,7 @@ running this module. |
| |
| set(NANOPB_URL "https://github.com/nanopb/nanopb.git" |
| CACHE STRING "nanopb repository URL") |
| -set(NANOPB_REFSPEC "nanopb-0.4.2" |
| +set(NANOPB_REFSPEC "nanopb-0.4.7" |
| CACHE STRING "nanopb git refspec") |
| set(NANOPB_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/nanopb-src" |
| CACHE PATH "nanopb source-code") |
| @@ -85,7 +85,7 @@ find_package(Python3 REQUIRED COMPONENTS Interpreter) |
| |
| find_file(NANOPB_GENERATOR_PATH |
| NAMES nanopb_generator.py |
| - PATHS ${nanopb_SOURCE_DIR}/generator |
| + PATHS ${NANOPB_INSTALL_DIR}/bin |
| DOC "nanopb protobuf compiler" |
| NO_DEFAULT_PATH |
| ) |
| @@ -186,11 +186,10 @@ function(protobuf_generate) |
| target_include_directories(${PARAMS_TGT} PRIVATE ${_OUT_DIR_BASE}) |
| endif() |
| |
| - get_filename_component(NANOPB_GENERATOR_DIR "${NANOPB_GENERATOR_PATH}" DIRECTORY CACHE "Location of nanopb generator.") |
| #Append a protobuf generator command to the nanopb_generate target. |
| add_custom_command(OUTPUT "${_OUT_C}" "${_OUT_H}" |
| COMMAND |
| - ${CMAKE_COMMAND} -E env PYTHONPATH=${NANOPB_GENERATOR_DIR} |
| + ${CMAKE_COMMAND} -E env PYTHONPATH=${NANOPB_INSTALL_DIR}/lib/python |
| ${Python3_EXECUTABLE} ${NANOPB_GENERATOR_PATH} |
| -I ${PARAMS_BASE_DIR} |
| -D ${_OUT_DIR_BASE} |