From 957ffb96d28d7f7d55ae8b592610fe10e8ba7226 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 10:36:47 +0800 Subject: [PATCH 1/8] Fix MySQL header include path --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0e618bf..f170897 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #ifdef _WIN32 #ifndef NOMINMAX @@ -32,7 +31,7 @@ using Socket = int; #define SOCKET_ERROR (-1) #endif -#include +#include namespace { constexpr int kPort = 8081; From e562b2e57bac9bf340ae95ac566e78133a770191 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 10:40:16 +0800 Subject: [PATCH 2/8] Enhance CMake configuration for cross-platform support Refactor CMakeLists.txt to support both Windows and Linux builds with MySQL. --- CMakeLists.txt | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99e89c6..cc7b346 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,47 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Threads REQUIRED) -set(MYSQL_DIR "D:/Program Files/MySQL/MySQL Server 8.0") +cmake_minimum_required(VERSION 3.16) + +project(warehouse_storage_system LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Threads REQUIRED) add_executable(warehouse_server src/main.cpp ) -target_include_directories(warehouse_server PRIVATE "${MYSQL_DIR}/include") -target_link_libraries(warehouse_server PRIVATE Threads::Threads "${MYSQL_DIR}/lib/libmysql.lib") - if (WIN32) - target_link_libraries(warehouse_server PRIVATE ws2_32) + + # Windows + set(MYSQL_DIR "D:/Program Files/MySQL/MySQL Server 8.0") + + target_include_directories(warehouse_server PRIVATE + "${MYSQL_DIR}/include" + ) + + target_link_libraries(warehouse_server PRIVATE + Threads::Threads + "${MYSQL_DIR}/lib/libmysql.lib" + ws2_32 + ) + +else() + + # Linux(GitHub Actions) + find_package(PkgConfig REQUIRED) + pkg_check_modules(MYSQL REQUIRED mysqlclient) + + target_include_directories(warehouse_server PRIVATE + ${MYSQL_INCLUDE_DIRS} + ) + + target_link_libraries(warehouse_server PRIVATE + Threads::Threads + ${MYSQL_LIBRARIES} + ) + endif() From 17676011d5634cecfdc105715f2e79ddd7dbc287 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 10:45:17 +0800 Subject: [PATCH 3/8] Add conditional MySQL header inclusion for Windows --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f170897..d0ff489 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,11 @@ using Socket = int; #define SOCKET_ERROR (-1) #endif +#ifdef _WIN32 +#include +#else #include +#endif namespace { constexpr int kPort = 8081; From 830455b32fb45724a2bda9b74211cbf7403b9c36 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 10:48:28 +0800 Subject: [PATCH 4/8] Refactor CMakeLists.txt for better platform support --- CMakeLists.txt | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc7b346..7ad4b34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,3 @@ -cmake_minimum_required(VERSION 3.16) -project(warehouse_storage_system LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -find_package(Threads REQUIRED) - cmake_minimum_required(VERSION 3.16) project(warehouse_storage_system LANGUAGES CXX) @@ -19,33 +11,39 @@ add_executable(warehouse_server src/main.cpp ) -if (WIN32) +target_link_libraries(warehouse_server PRIVATE Threads::Threads) - # Windows - set(MYSQL_DIR "D:/Program Files/MySQL/MySQL Server 8.0") +# =============================== +# Windows +# =============================== +if(WIN32) - target_include_directories(warehouse_server PRIVATE - "${MYSQL_DIR}/include" - ) + # 如果使用 vcpkg + find_package(unofficial-libmysql REQUIRED) target_link_libraries(warehouse_server PRIVATE - Threads::Threads - "${MYSQL_DIR}/lib/libmysql.lib" + unofficial::libmysql::libmysql ws2_32 ) +# =============================== +# Linux +# =============================== else() - # Linux(GitHub Actions) find_package(PkgConfig REQUIRED) + pkg_check_modules(MYSQL REQUIRED mysqlclient) target_include_directories(warehouse_server PRIVATE ${MYSQL_INCLUDE_DIRS} ) + target_link_directories(warehouse_server PRIVATE + ${MYSQL_LIBRARY_DIRS} + ) + target_link_libraries(warehouse_server PRIVATE - Threads::Threads ${MYSQL_LIBRARIES} ) From 0d7074ddcf6006be21d315027dfda7f06d6003a0 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 10:49:40 +0800 Subject: [PATCH 5/8] Refactor CMake workflow for multi-platform support Updated CMake workflow to support multiple compilers and platforms, including dependency installation for Linux and Windows. --- .github/workflows/cmake-multi-platform.yml | 114 ++++++++++++--------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index d9e909f..07da123 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -1,75 +1,91 @@ -# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml name: CMake on multiple platforms on: push: - branches: [ "master" ] + branches: [ "main", "master" ] pull_request: - branches: [ "master" ] jobs: + build: - runs-on: ${{ matrix.os }} strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. fail-fast: false - # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest, windows-latest] - build_type: [Release] - c_compiler: [gcc, clang, cl] include: - - os: windows-latest - c_compiler: cl - cpp_compiler: cl + - os: ubuntu-latest - c_compiler: gcc - cpp_compiler: g++ + compiler: gcc + cc: gcc + cxx: g++ + - os: ubuntu-latest - c_compiler: clang - cpp_compiler: clang++ - exclude: - - os: windows-latest - c_compiler: gcc + compiler: clang + cc: clang + cxx: clang++ + - os: windows-latest - c_compiler: clang - - os: ubuntu-latest - c_compiler: cl + compiler: msvc + + runs-on: ${{ matrix.os }} steps: + - uses: actions/checkout@v4 - - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. - id: strings - shell: bash + #################################################### + # Ubuntu + #################################################### + + - name: Install Linux dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y \ + default-libmysqlclient-dev \ + pkg-config + + #################################################### + # Windows + #################################################### + + - name: Install MySQL via vcpkg + if: runner.os == 'Windows' run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} + git clone https://github.com/microsoft/vcpkg.git + ./vcpkg/bootstrap-vcpkg.bat + ./vcpkg/vcpkg install libmysql:x64-windows + + #################################################### + # Configure + #################################################### + + - name: Configure + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} + run: | + if [ "${{ runner.os }}" = "Windows" ]; then + cmake -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake + else + cmake -B build \ + -DCMAKE_BUILD_TYPE=Release + fi + shell: bash + + #################################################### + # Build + #################################################### - name: Build - # 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). - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + run: cmake --build build --config Release + + #################################################### + # Test + #################################################### - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - # 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). - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} \ No newline at end of file + run: ctest --test-dir build --build-config Release From 03bb5afa087b0668855b8ac54fda954029288f2d Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 12:55:37 +0800 Subject: [PATCH 6/8] Modify CMakeLists.txt for libmysql configuration Updated CMake configuration to use CONFIG for libmysql. --- CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ad4b34..d072c7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,14 +18,26 @@ target_link_libraries(warehouse_server PRIVATE Threads::Threads) # =============================== if(WIN32) - # 如果使用 vcpkg - find_package(unofficial-libmysql REQUIRED) + find_package(unofficial-libmysql CONFIG REQUIRED) - target_link_libraries(warehouse_server PRIVATE + get_target_property( + MYSQL_INCLUDE_DIR + unofficial::libmysql::libmysql + INTERFACE_INCLUDE_DIRECTORIES + ) + + target_include_directories( + warehouse_server PRIVATE + ${MYSQL_INCLUDE_DIR} + ) + + target_link_libraries( + warehouse_server PRIVATE unofficial::libmysql::libmysql ws2_32 ) +endif() # =============================== # Linux # =============================== From 68b5dbe8ab29936ff820e3143cce3832e451c1b9 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 12:56:52 +0800 Subject: [PATCH 7/8] Add step to show installed packages on Windows Added a step to show installed packages on Windows after MySQL installation. --- .github/workflows/cmake-multi-platform.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 07da123..a3ddf6d 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -57,6 +57,11 @@ jobs: ./vcpkg/bootstrap-vcpkg.bat ./vcpkg/vcpkg install libmysql:x64-windows + - name: Show installed packages + if: runner.os == 'Windows' + run: | + dir vcpkg\installed\x64-windows\share + #################################################### # Configure #################################################### From 121c199914c9ed621947e767ca2e1b6febc9a4d6 Mon Sep 17 00:00:00 2001 From: An Ziwu <147840857+MuRongMoQing@users.noreply.github.com> Date: Sat, 11 Jul 2026 13:03:03 +0800 Subject: [PATCH 8/8] Remove unnecessary endif statement --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d072c7b..561f86a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ if(WIN32) ws2_32 ) -endif() # =============================== # Linux # ===============================