Skip to content

Commit

Permalink
Add support for win32
Browse files Browse the repository at this point in the history
  • Loading branch information
xychen committed Jun 16, 2022
1 parent dd692d3 commit 1b0d176
Show file tree
Hide file tree
Showing 11 changed files with 891 additions and 4 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,61 @@ jobs:
tag: ${{ github.ref }}
repo_token: ${{ secrets.GITHUB_TOKEN }}

build-win32:
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- { name: win32-x64, os: windows-latest }

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive

- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
release: false
install: >-
git
zip
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-cmake
mingw-w64-x86_64-ninja
- name: Build
shell: msys2 {0}
run: |
cmake -G Ninja -B build
cmake --build build --config Release
ctest --test-dir build --build-config Release --output-on-failure
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: cp2102-${{ matrix.name }}
path: |
build/cp2102/cp2102.exe
build/cp2102/CP210xRuntime.dll
if-no-files-found: error

- name: Pack release assets
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: msys2 {0}
run: zip -9 -j cp2102-${{ matrix.name }}.zip build/cp2102/cp2102.exe build/cp2102/CP210xRuntime.dll

- name: Release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: svenstaro/upload-release-action@v2
with:
file: cp2102-${{ matrix.name }}.zip
tag: ${{ github.ref }}
repo_token: ${{ secrets.GITHUB_TOKEN }}

build-docker:
runs-on: ubuntu-latest

Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ add_subdirectory(cp2102)
add_subdirectory(libcp2102_usb)
add_subdirectory(liblog)

add_subdirectory(libusb)
if(NOT WIN32)
add_subdirectory(libusb)
endif()
8 changes: 8 additions & 0 deletions cp2102/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ target_compile_options(
-DGIT_INCREMENT=${GIT_INCREMENT}
)

if(WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE_DIR:cp2102_usb>/CP210xRuntime.dll
${PROJECT_BINARY_DIR}
)
endif()

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
26 changes: 23 additions & 3 deletions libcp2102_usb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
project(cp2102_usb)

set(SRCS "src/cp2102_libusb.c")
set(SRCS)

if(WIN32)
list(APPEND SRCS "src/cp2102_win32.c")
else()
list(APPEND SRCS "src/cp2102_libusb.c")
endif()

if(APPLE)
list(APPEND SRCS "src/tty_utils_darwin.c")
elseif(UNIX)
list(APPEND SRCS "src/tty_utils_linux.c")
else()
elseif(NOT WIN32)
list(APPEND SRCS "src/tty_utils_dummy.c")
endif()

Expand All @@ -18,7 +24,21 @@ target_include_directories(
)

target_link_libraries(${PROJECT_NAME} log)
target_link_libraries(${PROJECT_NAME} usb)

if(WIN32)
set(CP210XRT_DIR ${PROJECT_SOURCE_DIR}/cp210xrt)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CP210XRT_DIR}/CP210xRuntime.dll
${PROJECT_BINARY_DIR}
)

target_include_directories(${PROJECT_NAME} PRIVATE ${CP210XRT_DIR})
target_link_libraries(${PROJECT_NAME} ${CP210XRT_DIR}/CP210xRuntime.dll)
else()
target_link_libraries(${PROJECT_NAME} usb)
endif()

if(APPLE)
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
Expand Down
Binary file added libcp2102_usb/cp210xrt/CP210xRuntime.dll
Binary file not shown.
Binary file added libcp2102_usb/cp210xrt/CP210xRuntime.lib
Binary file not shown.
Loading

0 comments on commit 1b0d176

Please sign in to comment.