Skip to content

Fix GNU-style flag passing to MSVC frontend#2391

Merged
stephenberry merged 2 commits intostephenberry:mainfrom
annihilatorq:fix-cmake-for-clang-cl
Mar 23, 2026
Merged

Fix GNU-style flag passing to MSVC frontend#2391
stephenberry merged 2 commits intostephenberry:mainfrom
annihilatorq:fix-cmake-for-clang-cl

Conversation

@annihilatorq
Copy link
Copy Markdown
Contributor

@annihilatorq annihilatorq commented Mar 21, 2026

Issue

When building glaze with clang-cl, the build fails because some branches in tests/CMakeLists.txt and fuzzing/CMakeLists.txt select GNU-style flags based only on CMAKE_<LANG>_COMPILER_ID=Clang

This is incorrect for clang-cl: although the compiler ID is Clang, its frontend is MSVC-compatible and therefore expects MSVC-style command-line options. To solve this issue, CMake introduced CMAKE_LANG_COMPILER_FRONTEND_VARIANT flag in v3.14

Fix

This PR updates the compiler checks in tests/CMakeLists.txt and fuzzing/CMakeLists.txt to account for the frontend variant, so clang-cl no longer enters the GNU-style flag branch. As a result, the affected targets configure and build correctly with clang-cl

gotta see what CI will say, and if there are any issues (which shouldn't be the case, but who knows 😁), I'll take care of them

P.S. I also removed target_link_options(glz_test_common INTERFACE -ftime-trace) since target_link_options() applies to the linker, while afaik the flag is intended for compile-time tracing

@annihilatorq
Copy link
Copy Markdown
Contributor Author

I also wanted to ask if there's a reason why glaze hasn't added a basic workflow for building and testing with clang-cl?
If it's because of a lack of time or because this task isn't a high priority, I'd be more than happy to help

@annihilatorq
Copy link
Copy Markdown
Contributor Author

annihilatorq commented Mar 23, 2026

hmm, I guess we can also simplify these checks, so instead of

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
  # Something for compiler with MSVC command line style
endif()

we can use

if(MSVC)
  # Something for compiler with MSVC command line style
endif()

since, as stated in CMake MSVC variable documentation, it is Set to true when the compiler is some version of Microsoft Visual C++ or another compiler simulating the Visual C++ cl command-line syntax.

should we change our current approach (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" to MSVC), or would glaze prefer to stick to a single style for all compilers?

@annihilatorq
Copy link
Copy Markdown
Contributor Author

seems like glaze already uses if(MSVC)

if (MSVC)

so I replaced the long if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") with if(MSVC)

@stephenberry
Copy link
Copy Markdown
Owner

Thanks for this contribution for clang-cl. I'll look it over in a bit more detail ASAP. But, I'm also open for a PR that tests clang-cl if you'd like to add it.

@stephenberry stephenberry merged commit b803ae8 into stephenberry:main Mar 23, 2026
47 of 48 checks passed
@stephenberry
Copy link
Copy Markdown
Owner

stephenberry commented Mar 23, 2026

Looks good!

@annihilatorq annihilatorq deleted the fix-cmake-for-clang-cl branch March 23, 2026 15:34
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