Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2023-10-19 13:05:18 +0300
committerPetteri Aimonen <jpa@github.mail.kapsi.fi>2023-10-27 13:37:50 +0300
commit79549005b9116d7d990f3af5f3470f2bc692a264 (patch)
tree6c3bcaed34d8fc9488aee83f69b4c9aed5a841f6
parent5896c28cd23ba76c9cd02253a59240a3dcbb42e0 (diff)
Add GitHub workflow for testing CMake installation
-rw-r--r--.github/workflows/cmake.yml71
-rw-r--r--CMakeLists.txt14
2 files changed, 83 insertions, 2 deletions
diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml
new file mode 100644
index 0000000..ac0e641
--- /dev/null
+++ b/.github/workflows/cmake.yml
@@ -0,0 +1,71 @@
+name: Test CMake-based installation and compilation
+
+on:
+ workflow_dispatch:
+ workflow_call:
+ push:
+ paths:
+ - '**CMakeLists**'
+ - '**cmake**'
+ pull_request:
+ paths:
+ - '**CMakeLists**'
+ - '**cmake**'
+
+jobs:
+ build_cmake_linux:
+ name: CMake on Ubuntu 22.04
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Install dependencies
+ run: |
+ python3 -m pip install protobuf grpcio-tools
+
+ - name: Build with CMake
+ run: |
+ mkdir build
+ cd build
+ cmake ..
+ cmake --build .
+ sudo cmake --install .
+
+ - name: Compile example against installed library
+ run: |
+ cd examples/simple
+ nanopb_generator simple.proto
+ gcc -Wall -Werror -osimple simple.pb.c simple.c -lprotobuf-nanopb
+ ./simple
+
+ build_cmake_windows:
+ name: CMake on Windows 2022
+ runs-on: windows-2022
+ steps:
+ - uses: actions/checkout@v2
+
+ - uses: actions/setup-python@v4
+ with:
+ python-version: '3.12'
+
+ - name: Install dependencies
+ run: |
+ pip install protobuf grpcio-tools
+
+ - name: Build with CMake
+ run: |
+ mkdir build
+ cd build
+ cmake ..
+ cmake --build . --config Release
+ cmake --install . --config Release --prefix C:/nanopb-test
+
+ - name: Compile example against installed library
+ shell: cmd
+ run: |
+ call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
+ cd examples/simple
+ C:\nanopb-test\bin\nanopb_generator simple.proto
+ cl /out:simple.exe simple.pb.c simple.c C:\nanopb-test\nanopb\lib\protobuf-nanopb.lib
+ simple.exe
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0a6a7b0..d359c8f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -86,6 +86,16 @@ if(nanopb_BUILD_GENERATOR)
install( FILES generator/__init__.py
DESTINATION ${PYTHON_INSTDIR}/nanopb/ )
+ # Include the full path to Python executable in Windows .bat scripts, in case it is not in PATH
+ if(WIN32)
+ file(READ generator/protoc-gen-nanopb.bat FILE_CONTENTS)
+ string(REPLACE "python" ${Python_EXECUTABLE} FILE_CONTENTS "${FILE_CONTENTS}")
+ file(WRITE ${PROJECT_BINARY_DIR}/protoc-gen-nanopb.bat "${FILE_CONTENTS}")
+
+ file(READ generator/nanopb_generator.bat FILE_CONTENTS)
+ string(REPLACE "python" ${Python_EXECUTABLE} FILE_CONTENTS "${FILE_CONTENTS}")
+ file(WRITE ${PROJECT_BINARY_DIR}/nanopb_generator.bat "${FILE_CONTENTS}")
+ endif()
endif()
# Install small script wrappers to invoke the generator from the installed module
@@ -93,8 +103,8 @@ if(WIN32)
install(
PROGRAMS
extra/script_wrappers/nanopb_generator.py
- generator/protoc-gen-nanopb.bat
- generator/nanopb_generator.bat
+ ${PROJECT_BINARY_DIR}/protoc-gen-nanopb.bat
+ ${PROJECT_BINARY_DIR}/nanopb_generator.bat
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
else()