Skip to content

Commit 1b0d176

Browse files
author
xychen
committed
1 parent dd692d3 commit 1b0d176

File tree

11 files changed

+891
-4
lines changed

11 files changed

+891
-4
lines changed

.github/workflows/build.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,61 @@ jobs:
4949
tag: ${{ github.ref }}
5050
repo_token: ${{ secrets.GITHUB_TOKEN }}
5151

52+
build-win32:
53+
runs-on: ${{ matrix.os }}
54+
55+
strategy:
56+
matrix:
57+
include:
58+
- { name: win32-x64, os: windows-latest }
59+
60+
steps:
61+
- uses: actions/checkout@v2
62+
with:
63+
fetch-depth: 0
64+
submodules: recursive
65+
66+
- name: Setup MSYS2
67+
uses: msys2/setup-msys2@v2
68+
with:
69+
msystem: MINGW64
70+
release: false
71+
install: >-
72+
git
73+
zip
74+
mingw-w64-x86_64-toolchain
75+
mingw-w64-x86_64-cmake
76+
mingw-w64-x86_64-ninja
77+
78+
- name: Build
79+
shell: msys2 {0}
80+
run: |
81+
cmake -G Ninja -B build
82+
cmake --build build --config Release
83+
ctest --test-dir build --build-config Release --output-on-failure
84+
85+
- name: Upload artifacts
86+
uses: actions/upload-artifact@v2
87+
with:
88+
name: cp2102-${{ matrix.name }}
89+
path: |
90+
build/cp2102/cp2102.exe
91+
build/cp2102/CP210xRuntime.dll
92+
if-no-files-found: error
93+
94+
- name: Pack release assets
95+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
96+
shell: msys2 {0}
97+
run: zip -9 -j cp2102-${{ matrix.name }}.zip build/cp2102/cp2102.exe build/cp2102/CP210xRuntime.dll
98+
99+
- name: Release
100+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
101+
uses: svenstaro/upload-release-action@v2
102+
with:
103+
file: cp2102-${{ matrix.name }}.zip
104+
tag: ${{ github.ref }}
105+
repo_token: ${{ secrets.GITHUB_TOKEN }}
106+
52107
build-docker:
53108
runs-on: ubuntu-latest
54109

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ add_subdirectory(cp2102)
66
add_subdirectory(libcp2102_usb)
77
add_subdirectory(liblog)
88

9-
add_subdirectory(libusb)
9+
if(NOT WIN32)
10+
add_subdirectory(libusb)
11+
endif()

cp2102/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ target_compile_options(
1818
-DGIT_INCREMENT=${GIT_INCREMENT}
1919
)
2020

21+
if(WIN32)
22+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
23+
COMMAND ${CMAKE_COMMAND} -E copy
24+
$<TARGET_FILE_DIR:cp2102_usb>/CP210xRuntime.dll
25+
${PROJECT_BINARY_DIR}
26+
)
27+
endif()
28+
2129
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

libcp2102_usb/CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
project(cp2102_usb)
22

3-
set(SRCS "src/cp2102_libusb.c")
3+
set(SRCS)
4+
5+
if(WIN32)
6+
list(APPEND SRCS "src/cp2102_win32.c")
7+
else()
8+
list(APPEND SRCS "src/cp2102_libusb.c")
9+
endif()
410

511
if(APPLE)
612
list(APPEND SRCS "src/tty_utils_darwin.c")
713
elseif(UNIX)
814
list(APPEND SRCS "src/tty_utils_linux.c")
9-
else()
15+
elseif(NOT WIN32)
1016
list(APPEND SRCS "src/tty_utils_dummy.c")
1117
endif()
1218

@@ -18,7 +24,21 @@ target_include_directories(
1824
)
1925

2026
target_link_libraries(${PROJECT_NAME} log)
21-
target_link_libraries(${PROJECT_NAME} usb)
27+
28+
if(WIN32)
29+
set(CP210XRT_DIR ${PROJECT_SOURCE_DIR}/cp210xrt)
30+
31+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
32+
COMMAND ${CMAKE_COMMAND} -E copy
33+
${CP210XRT_DIR}/CP210xRuntime.dll
34+
${PROJECT_BINARY_DIR}
35+
)
36+
37+
target_include_directories(${PROJECT_NAME} PRIVATE ${CP210XRT_DIR})
38+
target_link_libraries(${PROJECT_NAME} ${CP210XRT_DIR}/CP210xRuntime.dll)
39+
else()
40+
target_link_libraries(${PROJECT_NAME} usb)
41+
endif()
2242

2343
if(APPLE)
2444
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
1010 KB
Binary file not shown.
4.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)