From cbdc6670a1b20d28cde1455ece1ef5002cc60f7c Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 20 Nov 2025 02:15:00 -0500 Subject: [PATCH] fix(windows): properly detect clang-cl and add /std:c++latest for std::filesystem Root cause analysis: - clang-cl on GitHub Actions Windows Server 2022 cannot find std::filesystem - The compiler defaults to pre-C++17 compatibility, exposing only std::experimental::filesystem - Build logs show: -std=c++23 (Unix-style flag) instead of /std:c++latest (MSVC-style flag) Key insight: CMAKE_CXX_COMPILER_FRONTEND_VARIANT is needed to distinguish: - "MSVC": clang-cl (Clang with MSVC command-line interface) - "GNU": regular Clang on Windows Solution: 1. Use CMAKE_CXX_COMPILER_FRONTEND_VARIANT to properly detect clang-cl 2. Add /std:c++latest flag specifically to yaze_util target (where filesystem is used) 3. Apply as PUBLIC compile option so it propagates to dependent targets This targets the exact source of the problem - clang-cl needs MSVC-style /std:c++latest flag to access modern MSVC STL features including std::filesystem. Tested approach based on CMake 3.16+ feature CMAKE_CXX_COMPILER_FRONTEND_VARIANT. Related commits: 19196ca87c, c2bb90a3f1, b556b155a5 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cmake/utils.cmake | 28 ++++++---------------------- src/util/util.cmake | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index ff320346..f50baa44 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -40,28 +40,12 @@ function(yaze_add_compiler_flags) # Compiler-specific settings if(MSVC) - # Check if we're using clang-cl (Clang with MSVC-compatible command line) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # clang-cl requires explicit /std:c++latest to access C++23 features including - # Without this, clang-cl only sees std::experimental::filesystem from older MSVC STL - target_compile_options(yaze_common INTERFACE - /EHsc - /W4 /permissive- - /bigobj - /utf-8 - /std:c++latest - ) - message(STATUS "Windows clang-cl: Added /std:c++latest for C++23 and std::filesystem support") - else() - # Regular MSVC compiler - target_compile_options(yaze_common INTERFACE - /EHsc - /W4 /permissive- - /bigobj - /utf-8 - ) - endif() - + target_compile_options(yaze_common INTERFACE + /EHsc + /W4 /permissive- + /bigobj + /utf-8 + ) target_compile_definitions(yaze_common INTERFACE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS diff --git a/src/util/util.cmake b/src/util/util.cmake index 3fe0b416..f4ba062e 100644 --- a/src/util/util.cmake +++ b/src/util/util.cmake @@ -105,15 +105,21 @@ elseif(APPLE) target_compile_definitions(yaze_util PRIVATE MACOS) elseif(WIN32) target_compile_definitions(yaze_util PRIVATE WINDOWS) - # Windows-specific: Some clang-cl versions need help finding filesystem - # Ensure we're using the right C++ standard library headers - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Verify clang-cl can find MSVC STL headers with filesystem support - include(CheckIncludeFileCXX) - check_include_file_cxx("filesystem" HAVE_FILESYSTEM) - if(NOT HAVE_FILESYSTEM) - message(WARNING "std::filesystem not found - this may cause build failures on Windows") - endif() + + # CRITICAL FIX: clang-cl on Windows needs explicit /std:c++latest for std::filesystem + # clang-cl uses Clang's compiler but must interface with MSVC STL. Without this flag, + # it only finds std::experimental::filesystem (pre-C++17 version). + # + # The CMAKE_CXX_COMPILER_FRONTEND_VARIANT check distinguishes: + # - "MSVC": clang-cl (Clang with MSVC-compatible command line) + # - "GNU": regular Clang on Windows + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + # Use MSVC-style flag for clang-cl + target_compile_options(yaze_util PUBLIC /std:c++latest) + message(STATUS "Windows clang-cl detected: Added /std:c++latest for std::filesystem support") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Regular Clang on Windows - already has proper flags from parent + message(STATUS "Windows Clang (non-cl) detected: Using inherited C++23 flags") endif() endif()