From 9882b1124cf55291f34f170e8a9502bfa35c92db Mon Sep 17 00:00:00 2001 From: Hubert Liberacki Date: Wed, 15 Oct 2025 01:25:31 +0200 Subject: [PATCH] - Fix CI to run WIndows jobs Fix CI jobs to execute compilation on Windows. --- .github/workflows/ci_pipeline.yml | 93 ++++++++++++++++++++++--------- CMakeLists.txt | 18 +++--- 2 files changed, 79 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci_pipeline.yml b/.github/workflows/ci_pipeline.yml index c5a7308..f284381 100644 --- a/.github/workflows/ci_pipeline.yml +++ b/.github/workflows/ci_pipeline.yml @@ -13,12 +13,18 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] std: [14, 20, 23] - compiler: [gcc, clang] + compiler: [gcc, clang, msvc] exclude: - # macOS: Apple Clang only + # Linux: [gcc, clang] + - os: ubuntu-latest + compiler: msvc + # MacOS: [clang] - os: macos-latest compiler: gcc - # Windows: use MSVC only + - os: macos-latest + compiler: msvc + + # Windows: [msvc] - os: windows-latest compiler: gcc - os: windows-latest @@ -30,10 +36,12 @@ jobs: - uses: actions/checkout@v4 - uses: seanmiddleditch/gha-setup-ninja@v5 - - name: Setup compiler + - name: Setup compiler (Linux/macOS) + if: runner.os != 'Windows' + shell: bash run: | - if [[ "${{ runner.os }}" == "Linux" ]]; then - if [[ "${{ matrix.compiler }}" == "gcc" ]]; then + if [ "${{ runner.os }}" = "Linux" ]; then + if [ "${{ matrix.compiler }}" = "gcc" ]; then sudo apt update -y sudo apt install -y g++-11 echo "CXX=g++-11" >> $GITHUB_ENV @@ -42,50 +50,85 @@ jobs: sudo apt install -y clang-15 echo "CXX=clang++-15" >> $GITHUB_ENV fi - elif [[ "${{ runner.os }}" == "macOS" ]]; then - # Apple Clang is preinstalled and modern (LLVM-based) - echo "CXX=clang++" >> $GITHUB_ENV else - # Windows automatically uses MSVC via CMake - echo "Using MSVC on Windows" + echo "CXX=clang++" >> $GITHUB_ENV fi - name: Print compiler info + if: runner.os != 'Windows' + shell: bash run: | cmake --version - if [[ "${{ runner.os }}" == "Windows" ]]; then - cl - else - $CXX --version - fi + $CXX --version - name: Configure + if: runner.os != 'Windows' + shell: bash run: | - if [[ "${{ matrix.compiler }}" == "gcc" ]]; then + if [ "${{ matrix.compiler }}" = "gcc" ]; then CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-array-bounds" else CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror" fi cmake -S . -B build -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_CXX_STANDARD=${{ matrix.std }} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DBUILD_TESTING=ON \ - -DEXAMPLES=ON \ - -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_STANDARD=${{ matrix.std }} \ + -DCMAKE_CXX_STANDARD_REQUIRED=ON \ + -DBUILD_TESTING=ON \ + -DEXAMPLES=ON \ + -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" - name: Build + if: runner.os != 'Windows' + shell: bash run: cmake --build build --parallel - name: Run tests + if: runner.os != 'Windows' + shell: bash run: ctest --test-dir build --output-on-failure - - name: Run examples + - name: Run examples (Linux only) if: runner.os == 'Linux' + shell: bash run: | if [ -d build/examples ]; then echo "Running examples..." find build/examples -maxdepth 1 -type f -executable -print -exec {} \; else echo "No examples directory found." - fi \ No newline at end of file + fi + + - name: Setup MSVC + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + + - name: Print compiler info (MSVC) + if: runner.os == 'Windows' + shell: cmd + run: | + cmake --version + cl + + - name: Configure (MSVC) + if: runner.os == 'Windows' + shell: cmd + run: | + cmake -S . -B build -G "Ninja" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_CXX_STANDARD=${{ matrix.std }} ^ + -DCMAKE_CXX_STANDARD_REQUIRED=ON ^ + -DBUILD_TESTING=ON ^ + -DEXAMPLES=ON ^ + -DCMAKE_CXX_FLAGS="/W4 /WX /EHsc" + + - name: Build (MSVC) + if: runner.os == 'Windows' + shell: cmd + run: cmake --build build --parallel + + - name: Run tests (MSVC) + if: runner.os == 'Windows' + shell: cmd + run: ctest --test-dir build --output-on-failure + diff --git a/CMakeLists.txt b/CMakeLists.txt index b675eab..c6b8e7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,17 +6,17 @@ include(GNUInstallDirs) set(library_name accessor) add_library(${library_name} INTERFACE) target_include_directories(${library_name} INTERFACE - $ - $) + $ + $) install(TARGETS accessor EXPORT ${library_name}Config - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # For Windows + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # For Windows install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING PATTERN "*.hpp*") + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.hpp*") install(EXPORT ${library_name}Config DESTINATION share/${library_name}/cmake) @@ -28,15 +28,19 @@ if(${EXAMPLES}) add_executable(accessFunctions examples/access_function.cpp) target_link_libraries(accessFunctions accessor) + set_target_properties(accessFunctions PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) add_executable(accessMembers examples/access_member.cpp) target_link_libraries(accessMembers accessor) + set_target_properties(accessMembers PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) add_executable(accessColletion examples/multiple_instances.cpp) target_link_libraries(accessColletion accessor) + set_target_properties(accessColletion PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) add_executable(accessNoMacro examples/no_macro.cpp) target_link_libraries(accessNoMacro accessor) + set_target_properties(accessNoMacro PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) endif() #TESTS