1name: Test CMake-based installation and compilation
2
3on:
4  workflow_dispatch:
5  workflow_call:
6  push:
7    paths:
8      - '**CMakeLists**'
9      - '**cmake**'
10  pull_request:
11    paths:
12      - '**CMakeLists**'
13      - '**cmake**'
14
15jobs:
16  build_cmake_linux:
17    name: CMake on Ubuntu 22.04
18    runs-on: ubuntu-22.04
19    steps:
20      - uses: actions/checkout@v4
21
22      - name: Install dependencies
23        run: |
24          python3 -m pip install protobuf grpcio-tools
25
26      - name: Build with CMake
27        run: |
28          mkdir build
29          cd build
30          cmake ..
31          cmake --build .
32          sudo cmake --install .
33
34      - name: Compile example against installed library
35        run: |
36          cd examples/simple
37          nanopb_generator simple.proto
38          gcc -Wall -Werror -osimple simple.pb.c simple.c -lprotobuf-nanopb -I/usr/local/include/nanopb
39          ./simple
40
41  build_cmake_windows:
42    name: CMake on Windows 2022
43    runs-on: windows-2022
44    steps:
45      - uses: actions/checkout@v4
46
47      - uses: actions/setup-python@v4
48        with:
49          python-version: '3.12'
50
51      - name: Install dependencies
52        run: |
53          pip install protobuf grpcio-tools
54
55      - name: Build with CMake
56        run: |
57          mkdir build
58          cd build
59          cmake ..
60          cmake --build . --config Release
61          cmake --install . --config Release --prefix C:/nanopb-test
62
63      - name: Compile example against installed library
64        shell: cmd
65        run: |
66          call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
67          cd examples/simple
68          call C:\nanopb-test\bin\nanopb_generator simple.proto
69          cl simple.pb.c simple.c /IC:\nanopb-test\include\nanopb C:\nanopb-test\lib\protobuf-nanopb.lib /link /out:simple.exe
70          simple.exe
71
72