diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c716e28 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + build_type: [Release, Debug] + + steps: + - uses: actions/checkout@v4 + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + + - name: Build + run: cmake --build build --config ${{ matrix.build_type }} + + - name: Test Run + run: ./build/cpp_calc --test + if: runner.os != 'Windows' + + - name: Test Run (Windows) + run: .\build\${{ matrix.build_type }}\cpp_calc.exe --test + if: runner.os == 'Windows' diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f766df..5ede894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,18 +9,12 @@ set(CMAKE_CXX_EXTENSIONS OFF) # Всегда экспортировать compile_commands.json set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# --- Копировать compile_commands.json в корень проекта --- -add_custom_target(copy_compile_commands ALL - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_BINARY_DIR}/compile_commands.json - ${CMAKE_SOURCE_DIR}/compile_commands.json - DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json - COMMENT "Copying compile_commands.json to project root" -) -# ---------------------------------------------------------- - # Добавляем флаги компиляции -add_compile_options(-Wall -Wextra -Wpedantic) +if(MSVC) + add_compile_options(/W4) +else() + add_compile_options(-Wall -Wextra -Wpedantic) +endif() # Добавляем include-директории include_directories(${CMAKE_SOURCE_DIR}/libs) @@ -31,3 +25,17 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/src/*.cpp) # Создаём исполняемый файл add_executable(cpp_calc ${SRC_FILES}) +# --- Копировать compile_commands.json в корень проекта --- +# Note: Visual Studio generators don't generate compile_commands.json +# Only copy if the file exists (for Makefile/Ninja generators) +if(NOT MSVC) + add_custom_command(TARGET cpp_calc POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + COMMENT "Copying compile_commands.json to project root" + VERBATIM + ) +endif() +# ---------------------------------------------------------- +