Skip to content

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

Description

@LesleyLai

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions