Skip to content

Commit 9aaf0e4

Browse files
authored
Fix macOS build (#18)
* Fix macOS build * Add macOS to CI
1 parent 797b6dd commit 9aaf0e4

File tree

3 files changed

+53
-52
lines changed

3 files changed

+53
-52
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
#
2525
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
2626
matrix:
27-
os: [ubuntu-latest, windows-latest]
27+
os: [ubuntu-latest, windows-latest, macos-latest]
2828
build_type: [Release]
2929
c_compiler: [gcc, clang, cl]
3030
include:
@@ -37,68 +37,67 @@ jobs:
3737
- os: ubuntu-latest
3838
c_compiler: clang
3939
cpp_compiler: clang++
40+
- os: macos-latest
41+
c_compiler: clang
42+
cpp_compiler: clang++
43+
- os: macos-latest
44+
c_compiler: gcc
45+
cpp_compiler: g++
4046
exclude:
4147
- os: windows-latest
4248
c_compiler: gcc
4349
- os: windows-latest
4450
c_compiler: clang
4551
- os: ubuntu-latest
4652
c_compiler: cl
53+
- os: macos-latest
54+
c_compiler: cl
4755

4856
steps:
49-
- uses: actions/checkout@v4
57+
- uses: actions/checkout@v4
5058

51-
- name: Set reusable strings
52-
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
53-
id: strings
54-
shell: bash
55-
run: |
56-
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
59+
- name: Set reusable strings
60+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
61+
id: strings
62+
shell: bash
63+
run: |
64+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
5765
58-
- name: Install dependency libraries (Windows)
59-
id: vars
60-
if: runner.os == 'Windows'
61-
run: |
62-
git clone https://github.com/Microsoft/vcpkg.git
63-
cd vcpkg
64-
.\bootstrap-vcpkg.bat
65-
.\vcpkg integrate install
66-
.\vcpkg install libusb
67-
echo ("VCPKG_ROOT=" + "$PWD") >> $env:GITHUB_ENV
66+
- name: Install dependency libraries (Windows)
67+
id: vars
68+
if: runner.os == 'Windows'
69+
run: |
70+
git clone https://github.com/Microsoft/vcpkg.git
71+
cd vcpkg
72+
.\bootstrap-vcpkg.bat
73+
.\vcpkg integrate install
74+
.\vcpkg install libusb
75+
echo ("VCPKG_ROOT=" + "$PWD") >> $env:GITHUB_ENV
6876
69-
- name: Install dependency libraries (Linux)
70-
if: runner.os == 'Linux'
71-
run:
72-
sudo apt-get install libusb-1.0-0-dev
77+
- name: Install dependency libraries (Linux)
78+
if: runner.os == 'Linux'
79+
run:
80+
sudo apt install libusb-1.0-0-dev
7381

74-
- name: Configure CMake (Windows)
75-
if: runner.os == 'Windows'
76-
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
77-
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
78-
run: >
79-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
80-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
81-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
82-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
83-
-S ${{ github.workspace }}
82+
- name: Install dependency libraries (macOS)
83+
if: runner.os == 'macOS'
84+
run:
85+
brew install libusb
8486

85-
- name: Configure CMake (Linux)
86-
if: runner.os == 'Linux'
87-
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
88-
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
89-
run: >
90-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
91-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
92-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
93-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
94-
-S ${{ github.workspace }}
87+
- name: Configure CMake
88+
run: >
89+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
90+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
91+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
92+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
93+
-S ${{ github.workspace }}
9594
96-
- name: Build
97-
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
98-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
95+
- name: Build
96+
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
97+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
9998

100-
- name: Test
101-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
102-
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
103-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
104-
run: ctest --build-config ${{ matrix.build_type }}
99+
- name: Test
100+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
101+
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
102+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
103+
run: ctest --build-config ${{ matrix.build_type }}

src/RtlUsbAdapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "RtlUsbAdapter.h"
22

33
#include <chrono>
4-
#if defined(__ANDROID__) || defined(_MSC_VER)
4+
#if defined(__ANDROID__) || defined(_MSC_VER) || defined(__APPLE__)
55
#include <libusb.h>
66
#else
77
#include <libusb-1.0/libusb.h>

txdemo/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#define fork() (0)
1111
#define sleep(seconds) Sleep((seconds)*1000)
1212
#elif defined(__ANDROID__)
13-
// On Android, include the libusb header as required.
13+
#include <libusb.h>
14+
#elif defined(__APPLE__)
15+
#include <unistd.h>
1416
#include <libusb.h>
1517
#else
1618
#include <libusb-1.0/libusb.h>

0 commit comments

Comments
 (0)