From 29273ff86f6ac5406e09d0238e8b17288028ed0b Mon Sep 17 00:00:00 2001 From: overwriter <49340226+s12mmm3@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:26:53 +0800 Subject: [PATCH] feat: add MSVC CI; remove Makefile (#9) Co-authored-by: TaurusXin --- .github/workflows/autobuild.yml | 47 ++++++++++++++++++++++++--------- CMakeLists.txt | 12 +-------- Makefile | 24 ----------------- main.cpp | 38 +++++++++++++------------- 4 files changed, 55 insertions(+), 66 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index fc68027..a4ce0a0 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -1,11 +1,13 @@ name: CI - +env: + BUILD_TYPE: Release + BUILD_PATH: build on: push: branches: [ main ] jobs: - build_on_windows: + build_on_windows_msys2: runs-on: windows-latest steps: @@ -22,16 +24,37 @@ jobs: install: git mingw-w64-ucrt-x86_64-toolchain - name: Configure build - run: cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -B build + run: cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} - name: Build - run: cmake --build build -j 4 + run: cmake --build ${{ env.BUILD_PATH }} -j 4 - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: Windows amd64 Build - path: build/ncmdump.exe + name: Windows amd64 Build - MinGW + path: ${{ env.BUILD_PATH }}/ncmdump.exe + + build_on_windows_msvc: + runs-on: windows-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Configure build + run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} + + - name: Build + run: cmake --build ${{ env.BUILD_PATH }} -j 4 + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: Windows amd64 Build - MSVC + path: ${{ env.BUILD_PATH }}/ncmdump.exe build_on_linux: runs-on: ubuntu-latest @@ -48,16 +71,16 @@ jobs: sudo apt-get install -y build-essential cmake - name: Configure build - run: cmake -DCMAKE_BUILD_TYPE=Release -B build + run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} - name: Build - run: cmake --build build -j 4 + run: cmake --build ${{ env.BUILD_PATH }} -j 4 - name: Upload artifact uses: actions/upload-artifact@v4 with: name: Linux amd64 Build - path: build/ncmdump + path: ${{ env.BUILD_PATH }}/ncmdump build_on_macos: runs-on: macos-latest @@ -74,13 +97,13 @@ jobs: brew install git cmake - name: Configure build - run: cmake -DCMAKE_BUILD_TYPE=Release -B build + run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B ${{ env.BUILD_PATH }} - name: Build - run: cmake --build build -j 4 + run: cmake --build ${{ env.BUILD_PATH }} -j 4 - name: Upload artifact uses: actions/upload-artifact@v4 with: name: macOS amd64 Build - path: build/ncmdump \ No newline at end of file + path: ${{ env.BUILD_PATH }}/ncmdump \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c54db5..c22acda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(ncmdump LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -option(BUILD_WIN32_STATIC "Build the program statically on Windows" ON) +add_subdirectory(taglib) FILE(GLOB HEADERS ./*.h) FILE(GLOB SOURCES ./*.cpp) @@ -13,22 +13,12 @@ add_executable(ncmdump ${HEADERS} ${SOURCES} ) -add_subdirectory(taglib) target_link_libraries(ncmdump tag) target_include_directories(ncmdump PRIVATE taglib) target_include_directories(ncmdump PRIVATE taglib/taglib) target_include_directories(ncmdump PRIVATE taglib/taglib/toolkit) target_include_directories(ncmdump PRIVATE taglib/taglib/mpeg/id3v2) -if(WIN32) - if(CMAKE_COMPILER_IS_GNUCXX) - target_link_options(ncmdump PRIVATE -O2 -municode) - if(BUILD_WIN32_STATIC) - target_link_options(ncmdump PRIVATE -static) - endif() - endif() -endif() - include(GNUInstallDirs) install(TARGETS ncmdump BUNDLE DESTINATION . diff --git a/Makefile b/Makefile deleted file mode 100644 index ca3ec1a..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -default: - @echo "Please choose a platform: linux, macos-intel, macos-arm64, win32" - @echo "Or use 'make clean' to clean up the build files" - -linux: - g++ main.cpp cJSON.cpp aes.cpp ncmcrypt.cpp -o ncmdump -ltag -std=c++17 - strip ncmdump - -macos-intel: - clang++ main.cpp cJSON.cpp aes.cpp ncmcrypt.cpp -o ncmdump -ltag -std=c++17 - strip ncmdump - -macos-arm64:export CPATH=/opt/homebrew/include -macos-arm64:export LIBRARY_PATH=/opt/homebrew/lib -macos-arm64: - clang++ main.cpp cJSON.cpp aes.cpp ncmcrypt.cpp -o ncmdump -ltag -std=c++17 - strip ncmdump - -win32: - g++ main.cpp cJSON.cpp aes.cpp ncmcrypt.cpp -o ncmdump -ltag -Ltaglib/lib -Itaglib/include -static -O -municode -std=c++17 - strip ncmdump.exe - -clean: - rm -f ncmdump ncmdump.exe \ No newline at end of file diff --git a/main.cpp b/main.cpp index 8cb2c75..ab82e3f 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) && defined(_MSC_VER) #include #endif @@ -47,15 +47,15 @@ void processFilesInFolder(const fs::path& folderPath) { } } -#ifdef _WIN32 +#if defined(_WIN32) && defined(_MSC_VER) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char **argv) #endif { - #ifdef _WIN32 - SetConsoleOutputCP(CP_UTF8); - #endif +#if defined(_WIN32) && defined(_MSC_VER) + SetConsoleOutputCP(CP_UTF8); +#endif if (argc <= 1) { displayHelp(); @@ -67,17 +67,17 @@ int main(int argc, char **argv) bool folderProvided = false; - #ifdef _WIN32 - #define COMPARE_STR(s1, s2) (wcscmp(s1, s2) == 0) - #define HELP_SHORT L"-h" - #define HELP_LONG L"--help" - #define FOLDER L"-d" - #else - #define COMPARE_STR(s1, s2) (strcmp(s1, s2) == 0) - #define HELP_SHORT "-h" - #define HELP_LONG "--help" - #define FOLDER "-d" - #endif +#if defined(_WIN32) && defined(_MSC_VER) +#define COMPARE_STR(s1, s2) (wcscmp(s1, s2) == 0) +#define HELP_SHORT L"-h" +#define HELP_LONG L"--help" +#define FOLDER L"-d" +#else +#define COMPARE_STR(s1, s2) (strcmp(s1, s2) == 0) +#define HELP_SHORT "-h" +#define HELP_LONG "--help" +#define FOLDER "-d" +#endif for (int i = 1; i < argc; ++i) { if (COMPARE_STR(argv[i], HELP_SHORT) || COMPARE_STR(argv[i], HELP_LONG)) { @@ -95,14 +95,14 @@ int main(int argc, char **argv) return 1; } } else { - #ifdef _WIN32 +#if defined(_WIN32) && defined(_MSC_VER) int multiByteStrSize = WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, NULL, 0, NULL, NULL); char *multiByteStr = new char[multiByteStrSize]; WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, multiByteStr, multiByteStrSize, NULL, NULL); fs::path path(multiByteStr); - #else +#else fs::path path(argv[i]); - #endif +#endif files.push_back(path); } }