From a6cb58ba00d1ec57cc61d3973f904d457c086083 Mon Sep 17 00:00:00 2001 From: yh-sb Date: Mon, 7 Oct 2024 00:08:51 +0300 Subject: [PATCH] Use xmake instead of CMake --- .github/workflows/build.yml | 141 +++++++++++++++++++++--------------- .gitmodules | 3 - .vscode/launch.json | 4 +- .vscode/tasks.json | 19 +---- CMakeLists.txt | 55 -------------- Makefile | 26 ------- README.md | 25 ++----- icon.rc | 1 + serial/CMakeLists.txt | 18 ----- serial/xmake.lua | 11 +++ terminal/CMakeLists.txt | 10 --- terminal/xmake.lua | 8 ++ third_party/boost | 1 - xmake.lua | 24 ++++++ 14 files changed, 140 insertions(+), 206 deletions(-) delete mode 100644 .gitmodules delete mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 icon.rc delete mode 100644 serial/CMakeLists.txt create mode 100644 serial/xmake.lua delete mode 100644 terminal/CMakeLists.txt create mode 100644 terminal/xmake.lua delete mode 160000 third_party/boost create mode 100644 xmake.lua diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc930c8..7fa3d77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,18 +1,28 @@ -name: build - -on: [push, pull_request] +name: Build + +on: + push: + paths-ignore: + - '**/*.md' + - '.gitignore' + - '.vscode/**' + pull_request: + paths-ignore: + - '**/*.md' + - '.gitignore' + - '.vscode/**' jobs: - windows-gcc: + windows-mingw: runs-on: windows-latest steps: - name: Checkout with submodules - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Cache MinGW-w64 - uses: actions/cache@v3 + uses: actions/cache@v4 id: cache with: key: ${{ runner.OS }}-cache-${{ hashFiles('.github/workflows/build.yml') }} @@ -21,36 +31,42 @@ jobs: - name: Install MinGW-w64 (if cache not found) if: steps.cache.outputs.cache-hit != 'true' run: | - curl.exe -L https://github.com/brechtsanders/winlibs_mingw/releases/download/13.2.0-16.0.6-11.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-13.2.0-mingw-w64ucrt-11.0.0-r1.zip -o mingw64.zip - tar -xf mingw64.zip -C C:\ - Copy-Item C:\mingw64\bin\mingw32-make.exe C:\mingw64\bin\make.exe + curl.exe -L https://github.com/brechtsanders/winlibs_mingw/releases/download/15.0.0-snapshot20240616posix-12.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-15.0.0-snapshot20240616-mingw-w64ucrt-12.0.0-r1.7z -o mingw64.7z + Expand-7zipArchive -Path mingw64.7z -DestinationPath C:\ + + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest - name: Build run: | $env:Path = "C:\mingw64\bin;" + $env:Path - make - make install + xmake config -p mingw -y + xmake - name: clang-tidy run: ./check.ps1 - - name: Set artifacts suffix (if tag) - if: startsWith(github.ref, 'refs/tags/') == true - run: Add-Content $env:GITHUB_ENV "git_suffix=$(git describe --tags --abbrev=0)" - - - name: Set artifacts suffix (if branch) - if: startsWith(github.ref, 'refs/tags/') != true - run: Add-Content $env:GITHUB_ENV "git_suffix=$(Write-Output "$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)")" - - - name: Append branch name and hash to app filename + - name: Package to directory run: | - cd build/install - ren ${{github.event.repository.name}}.exe ${{github.event.repository.name}}-${{env.git_suffix}}.exe + # Copy all required files to app binary directory + xmake install -o build/install -v + + # Get git branch+hash or release tag + if ($env:GITHUB_REF.StartsWith('refs/tags/')) { + $git_artifact_suffix = git describe --tags --abbrev=0 + } else { + $git_artifact_suffix = "$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)" + } + Add-Content -Path $env:GITHUB_ENV -Value "git_artifact_suffix=$git_artifact_suffix" + + # Rename binary dir and append branch+hash or release tag + ren build/install/bin minicom2-$git_artifact_suffix-x64 - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{github.event.repository.name}}-windows-${{env.git_suffix}} + name: minicom2-${{env.git_artifact_suffix}}-windows-x64 path: build/install/* if-no-files-found: error @@ -58,71 +74,78 @@ jobs: runs-on: windows-latest steps: - name: Checkout with submodules - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + - name: Build - run: | - make msvc SHELL=cmd + run: xmake -y - name: clang-tidy run: ./check.ps1 - linux: + linux-gcc: runs-on: ubuntu-22.04 steps: - - name: Install dependencies - run: | - sudo apt update - sudo apt install g++ ninja-build libfuse2 - - name: Checkout with submodules - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive + - name: Install dependencies + run: | + sudo apt update + sudo apt install libfuse2 + - name: Cache linuxdeploy - uses: actions/cache@v3 + uses: actions/cache@v4 id: cache with: key: ${{ runner.OS }}-cache-${{ hashFiles('.github/workflows/build.yml') }} - path: ~/bin/linuxdeploy.AppImage + path: ~/.local/bin/linuxdeploy - name: Install linuxdeploy (if cache not found) if: steps.cache.outputs.cache-hit != 'true' run: | - mkdir -p ~/bin && cd $_ - wget https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20230713-1/linuxdeploy-x86_64.AppImage -O linuxdeploy.AppImage - chmod +x linuxdeploy.AppImage + mkdir -p ~/.local/bin && cd $_ + wget https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20240109-1/linuxdeploy-static-x86_64.AppImage -O linuxdeploy + chmod +x linuxdeploy + + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest - name: Build - run: | - # Add linuxdeploy to PATH - export PATH=~/bin:$PATH - # Build - make - make install + run: xmake -y - name: clang-tidy run: ./check.sh - - name: Set artifacts suffix (if tag) - if: startsWith(github.ref, 'refs/tags/') == true - run: echo "git_suffix=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV - - - name: Set artifacts suffix (if branch) - if: startsWith(github.ref, 'refs/tags/') != true - run: echo "git_suffix=$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - - name: Append branch name and hash to .AppImage filename + - name: Package to .AppImage run: | - cd build/install - mv *.AppImage $(basename *.AppImage .AppImage)-${{env.git_suffix}}.AppImage + # Create AppImage + xmake install -o build/appdir/usr -v + cd build + xrepo env linuxdeploy --appdir appdir --desktop-file ../app.desktop --icon-file ../icon.png --output appimage + + # Get git branch+hash or release tag + if [[ "$GITHUB_REF" == refs/tags/* ]]; then + git_artifact_suffix=$(git describe --tags --abbrev=0) + else + git_artifact_suffix="$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)" + fi + echo "git_artifact_suffix=$git_artifact_suffix" >> $GITHUB_ENV + + # Append branch name and hash (or release tag) to .AppImage filename + mv *.AppImage $(basename *.AppImage -x86_64.AppImage)-$git_artifact_suffix-x64.AppImage - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{github.event.repository.name}}-linux-${{env.git_suffix}} - path: build/install/* + name: minicom2-${{env.git_artifact_suffix}}-linux-x64 + path: build/*.AppImage if-no-files-found: error diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 5ecfbc8..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "third_party/boost"] - path = third_party/boost - url = https://github.com/boostorg/boost.git diff --git a/.vscode/launch.json b/.vscode/launch.json index 42fbe21..94c6399 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "args": ["COM4", "--baudrate", "115200", "--databits", "8", "--parity", "none", "--stopbits", "1", "--flowctrl", "none"], "cwd": "${workspaceFolder}/build", "miDebuggerPath": "gdb", - "preLaunchTask": "make gcc", + "preLaunchTask": "xmake", "postDebugTask": "hide terminal", "showDisplayString": true, "visualizerFile": "${workspaceFolder}/.vscode/stl.gcc.natvis" @@ -21,7 +21,7 @@ "request": "launch", "program": "${workspaceFolder}/build/minicom2", "cwd": "${workspaceFolder}/build", - "preLaunchTask": "make msvc", + "preLaunchTask": "xmake", "postDebugTask": "hide terminal" } ] diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fa6f5c9..9558404 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,22 +2,11 @@ "tasks": [ { - "label": "make gcc", + "label": "xmake", "type": "shell", - "command": "make", - "args": [ "gcc" ], - "presentation": { "showReuseMessage": false, "clear": true }, - "group": { "kind": "build" }, - "problemMatcher": ["$gcc"] - }, - { - "label": "make msvc", - "type": "shell", - "command": "make", - "args": [ "msvc" ], - "presentation": { "showReuseMessage": false, "clear": true }, - "group": { "kind": "build" }, - "problemMatcher": ["$msCompile"] + "command": "xmake", + "presentation": { "showReuseMessage": false, "panel": "shared" }, + "problemMatcher": ["$gcc", "$msCompile"] }, { "label": "hide terminal", diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 1903ce2..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(minicom2) - -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - -add_subdirectory(serial) -add_subdirectory(terminal) - -set(BOOST_INCLUDE_LIBRARIES asio program_options) -add_subdirectory(third_party/boost) - -add_executable(${CMAKE_PROJECT_NAME} - main.cpp - cli_options.cpp - $<$:${CMAKE_BINARY_DIR}/icon.rc> -) - -target_link_options(${CMAKE_PROJECT_NAME} PRIVATE - $<$:-static-libgcc;-static-libstdc++;$<$:-static>> -) - -target_link_libraries(${CMAKE_PROJECT_NAME} - PRIVATE - serial - terminal - Boost::program_options - $<$:pthread> -) - -# Deploy -if(WIN32) - # Create resource file to set .exe icon - file(WRITE ${CMAKE_BINARY_DIR}/icon.rc "IDI_ICON1 ICON DISCARDABLE \"${CMAKE_CURRENT_LIST_DIR}/icon.ico\"") - install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION .) -else() - # Create AppImage - install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION "${CMAKE_BINARY_DIR}/appdir/usr/bin") - install(CODE "execute_process( - COMMAND linuxdeploy.AppImage --appdir appdir --desktop-file ${CMAKE_CURRENT_LIST_DIR}/app.desktop --icon-file ${CMAKE_CURRENT_LIST_DIR}/icon.png --output appimage - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND_ERROR_IS_FATAL ANY)" - ) - # Get rid of hash and cpu arch in AppImage name - install(CODE "execute_process( - COMMAND sh -c \"mv ${CMAKE_PROJECT_NAME}*.AppImage ${CMAKE_PROJECT_NAME}.AppImage\" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND_ERROR_IS_FATAL ANY)" - ) - install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.AppImage DESTINATION . - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - ) -endif() diff --git a/Makefile b/Makefile deleted file mode 100644 index 75db5a3..0000000 --- a/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# This makefile is used to shorten build commands with various toolchains. -# You can build the project without it, just calling the CMake manually. - -BUILD_DIR ?= build -BUILD_TYPE ?= Debug - -.PHONY: gcc msvc install clean - -all: gcc # Default toolchain - -gcc: - $(eval export CC = gcc) - $(eval export CXX = g++) - cmake . -B$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) - cmake --build $(BUILD_DIR) -j - -msvc: - "$(shell ${ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere -prerelease -latest -property installationPath)\VC\Auxiliary\Build\vcvarsall.bat" x64 && \ - cmake . -B$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) && \ - cmake --build $(BUILD_DIR) -j - -install: - cmake --install $(BUILD_DIR) --prefix $(BUILD_DIR)/install - -clean: - @cmake -E rm -rf $(BUILD_DIR) diff --git a/README.md b/README.md index 85c418d..9cf41c5 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # minicom2 -

Modern crossplatform serial terminal emulator

-

-Build badge -License -

+[![Build](https://github.com/yh-sb/minicom2/actions/workflows/build.yml/badge.svg)](https://github.com/yh-sb/minicom2/actions/workflows/build.yml) + +Modern crossplatform serial terminal emulator ## TODO +- [ ] Fix text output on Raspberry Pi when executing `journalctl` - [ ] Add posix implementation for [terminal window interface](https://github.com/yhsb2k/minicom2/blob/master/terminal/terminal_posix.cpp) :penguin: - [ ] Re-architect the application. Maybe approach with coordinator thread is not good? - [ ] Integrate cli pseudographic interface (to be minicom-like) @@ -15,10 +14,8 @@ ## How to build and launch ```powershell -git clone --recursive https://github.com/yhsb2k/minicom2.git -cd minicom2 -make -# or make msvc +xmake -y +xmake run ``` Since pseudo-graphical UI has not yet been integrated, it is possible to configure the serial port using command line options: @@ -38,15 +35,9 @@ Options: ## Requirements * [MinGW-w64](https://winlibs.com) or [MSVC](https://visualstudio.microsoft.com/free-developer-offers) or Linux GCC -* [CMake](https://cmake.org/download) -* [Ninja](https://ninja-build.org) +* [Xmake](https://xmake.io/#/guide/installation) * For Linux: ```bash sudo apt update - sudo apt install cmake g++ ninja-build libfuse2 - # Install linuxdeploy - mkdir -p ~/bin && cd $_ - wget https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20230713-1/linuxdeploy-x86_64.AppImage -O linuxdeploy.AppImage - chmod +x linuxdeploy.AppImage - export PATH=~/bin:$PATH + sudo apt install libfuse2 ``` diff --git a/icon.rc b/icon.rc new file mode 100644 index 0000000..1bc463a --- /dev/null +++ b/icon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "icon.ico" diff --git a/serial/CMakeLists.txt b/serial/CMakeLists.txt deleted file mode 100644 index 65b0394..0000000 --- a/serial/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ - -add_library(serial - #$<$:serial_posix.cpp> - #$<$:serial_win32.cpp> - serial_boost.cpp -) - -target_include_directories(serial - PUBLIC - . -) - -target_link_libraries(serial - PUBLIC - Boost::asio - PRIVATE - $<$:ws2_32> -) diff --git a/serial/xmake.lua b/serial/xmake.lua new file mode 100644 index 0000000..602a560 --- /dev/null +++ b/serial/xmake.lua @@ -0,0 +1,11 @@ +target("serial") + set_kind("object") + add_packages("boost") + add_includedirs(".", {public = true}) + add_files("serial_boost.cpp") + + if is_plat("windows") or is_plat("mingw") then + add_files("serial_win32.cpp") + else + add_files("serial_posix.cpp") + end diff --git a/terminal/CMakeLists.txt b/terminal/CMakeLists.txt deleted file mode 100644 index b638d95..0000000 --- a/terminal/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ - -add_library(terminal - $<$:terminal_posix.cpp> - $<$:terminal_win32.cpp> -) - -target_include_directories(terminal - PUBLIC - . -) diff --git a/terminal/xmake.lua b/terminal/xmake.lua new file mode 100644 index 0000000..e8e2bfa --- /dev/null +++ b/terminal/xmake.lua @@ -0,0 +1,8 @@ +target("terminal") + set_kind("object") + add_includedirs(".", {public = true}) + if is_plat("windows") or is_plat("mingw") then + add_files("terminal_win32.cpp") + else + add_files("terminal_posix.cpp") + end diff --git a/third_party/boost b/third_party/boost deleted file mode 160000 index 564e2ac..0000000 --- a/third_party/boost +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 564e2ac16907019696cdaba8a93e3588ec596062 diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..18045fa --- /dev/null +++ b/xmake.lua @@ -0,0 +1,24 @@ +add_rules("mode.debug", "mode.release", "plugin.compile_commands.autoupdate", {outputdir = "build"}) +set_defaultmode("debug") +set_targetdir("$(buildir)") +set_languages("c++20") + +if is_plat("windows") or is_plat("mingw") then + add_syslinks("ws2_32", "wsock32") + add_ldflags("-static") +end + +add_requires("boost", {configs = {asio = true, program_options = true}}) + +target("minicom2") + add_packages("boost") + includes("serial", "terminal") + add_deps("serial", "terminal") + add_files( + "main.cpp", + "cli_options.cpp" + ) + + if is_plat("mingw") or is_plat("windows") then + add_files("icon.rc") + end