Failed to build on Clang/Windows: `W4` and `WX` flags passed to Clang

Open Beginner friendly
#247 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cmake, cpp
Domain
build-system

Research direction

Start in CMake/WarningsAsErrors.cmake and inspect how /W4 and /WX are added to ApprovalTests. Reproduce the Clang-on-Windows configuration with CMake and Ninja, then verify that Clang no longer receives these flags as file paths while the intended warning behavior remains for supported compilers.

Written by the indexing model from the issue text.

Description

Hi, thanks for this amazing library! I've used it a long throughout the years.

I am trying to build approval tests with Clang on Windows, and I got the following error:

clang++: error: no such file or directory: '/W4'
clang++: error: no such file or directory: '/WX'

It appears that those warning flags are being added by CMake/WarningsAsErrors.cmake.

My current escape hatch:

get_target_property(approval_tests_opts ApprovalTests COMPILE_OPTIONS)

if (approval_tests_opts)
    string(REPLACE "/W4" "" approval_tests_opts "${approval_tests_opts}")
    string(REPLACE "/WX" "" approval_tests_opts "${approval_tests_opts}")
    set_target_properties(ApprovalTests PROPERTIES COMPILE_OPTIONS "${approval_tests_opts}")
endif ()

Extra information of my build

Project: Charlie3D
target to build: charlie3d_test

The Approval Test libary are pulled via CPM:

CPMAddPackage(
        NAME approvaltests
        GITHUB_REPOSITORY approvals/ApprovalTests.cpp
        GIT_TAG v.10.13.0
        SYSTEM TRUE
)

CMake generated command:

C:\Users\Lenovo\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/Lenovo/AppData/Local/Programs/CLion/bin/ninja/win/x64/ninja.exe -DBEYOND_CORE_BUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=C:\Users\Lenovo\.clion-vcpkg\vcpkg\scripts\buildsystems\vcpkg.cmake -DCHARLIE3D_BUILD_TESTS=OFF -G Ninja -S E:\Dev\Charlie3D -B E:\Dev\Charlie3D\cmake-build-debug-clang

Other Information:

clang version 21.1.8
Target: x86_64-pc-windows-msvc
cmake version 3.31.6 (CMake; JetBrains IDE bundle; build 29)
OS: Windows 11

Dominant language
C++
Stars
339
Forks
55
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from approvals/ApprovalTests.cpp

All issues in approvals/ApprovalTests.cpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.