Skip to content

Add GitHub Actions CI workflow for CMake project#1

Merged
phoenixofhp merged 5 commits intomainfrom
copilot/add-github-workflow
Oct 11, 2025
Merged

Add GitHub Actions CI workflow for CMake project#1
phoenixofhp merged 5 commits intomainfrom
copilot/add-github-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 11, 2025

  • Create .github/workflows directory structure
  • Create a CI workflow file that:
    • Runs on push and pull requests to main branch
    • Tests on multiple OS (Ubuntu, macOS, Windows)
    • Uses CMake to configure and build the project
    • Verifies the build succeeds with both Release and Debug configurations
    • Tests the executable on all platforms
  • Validate YAML syntax
  • Fix Windows build failures
    • Fixed compiler flag incompatibility: Use /W4 for MSVC, -Wall -Wextra -Wpedantic for GCC/Clang
    • Skip compile_commands.json copy on MSVC since Visual Studio generators don't generate this file (only Makefile/Ninja do)
Original prompt

Add github workflow for my project (it uses cmake)


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: phoenixofhp <64036649+phoenixofhp@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub workflow for CMake project Add GitHub Actions CI workflow for CMake project Oct 11, 2025
Copilot AI requested a review from phoenixofhp October 11, 2025 19:40
@phoenixofhp
Copy link
Copy Markdown
Owner

@copilot Windows builds failed

Co-authored-by: phoenixofhp <64036649+phoenixofhp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot Windows builds failed

Fixed in commit c58ac35. The issue was in CMakeLists.txt where the copy_compile_commands target was depending on a file that doesn't exist yet on Windows. Changed it to depend on the executable target instead, which ensures proper build order across all platforms.

@phoenixofhp
Copy link
Copy Markdown
Owner

@copilot
Still don't work, but now it fails with Wextra:

cl : command line  error D8021: invalid numeric argument '/Wextra' [D:\a\cpp_calc\cpp_calc\build\cpp_calc.vcxproj]
Error: Process completed with exit code 1.

Co-authored-by: phoenixofhp <64036649+phoenixofhp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot
Still don't work, but now it fails with Wextra:

...

Fixed in commit 9cd1bbc. The issue was that -Wextra (and other GCC/Clang flags) are not compatible with MSVC. Updated CMakeLists.txt to use /W4 for MSVC and -Wall -Wextra -Wpedantic for GCC/Clang compilers.

@phoenixofhp
Copy link
Copy Markdown
Owner

@copilot
Still fails:

  cpp_calc.vcxproj -> D:\a\cpp_calc\cpp_calc\build\Release\cpp_calc.exe
  Copying compile_commands.json to project root
  Error copying file (if different) from "D:/a/cpp_calc/cpp_calc/build/compile_commands.json" to "D:/a/cpp_calc/cpp_calc/compile_commands.json".
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: Custom build for 'D:\a\cpp_calc\cpp_calc\build\CMakeFiles\51c2c35a463082391a2519301bdfd464\copy_compile_commands.rule;D:\a\cpp_calc\cpp_calc\CMakeLists.txt' exited with code 1. [D:\a\cpp_calc\cpp_calc\build\copy_compile_commands.vcxproj]

Co-authored-by: phoenixofhp <64036649+phoenixofhp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot
Still fails:

...

Fixed in commit 8458c3d. The issue is that Visual Studio generators don't generate compile_commands.json (only Makefile/Ninja generators do). Updated CMakeLists.txt to skip the copy command on MSVC, preventing the error while still copying the file on Linux/macOS.

Copy link
Copy Markdown
Owner

@phoenixofhp phoenixofhp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@phoenixofhp phoenixofhp marked this pull request as ready for review October 11, 2025 20:03
@phoenixofhp phoenixofhp merged commit e7b09e3 into main Oct 11, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants