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,b556b155a5Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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 <filesystem>
|
||||
# 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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user