Files
yaze/cmake/utils.cmake
scawful cbdc6670a1 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 <noreply@anthropic.com>
2025-11-20 02:15:00 -05:00

72 lines
2.4 KiB
CMake

# This file contains utility functions for the yaze build system.
# ============================================================================
# yaze_add_compiler_flags
#
# Sets standard compiler flags for C++ and C.
# Also handles platform-specific and compiler-specific flags.
# ============================================================================
function(yaze_add_compiler_flags)
# Set C++ and C standards in parent scope
set(CMAKE_CXX_STANDARD 23 PARENT_SCOPE)
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
set(CMAKE_CXX_EXTENSIONS OFF PARENT_SCOPE)
set(CMAKE_C_STANDARD 99 PARENT_SCOPE)
set(CMAKE_C_STANDARD_REQUIRED ON PARENT_SCOPE)
if(YAZE_SUPPRESS_WARNINGS)
if(MSVC)
add_compile_options(/w)
else()
add_compile_options(-w)
endif()
message(STATUS "✓ Warnings suppressed (use -v preset suffix for verbose builds)")
else()
message(STATUS "○ Verbose warnings enabled")
endif()
# Common interface target for shared settings
add_library(yaze_common INTERFACE)
target_compile_features(yaze_common INTERFACE cxx_std_23)
# Platform-specific definitions
if(YAZE_PLATFORM_LINUX)
target_compile_definitions(yaze_common INTERFACE linux stricmp=strcasecmp)
elseif(YAZE_PLATFORM_MACOS)
target_compile_definitions(yaze_common INTERFACE MACOS)
elseif(YAZE_PLATFORM_WINDOWS)
target_compile_definitions(yaze_common INTERFACE WINDOWS)
endif()
# Compiler-specific settings
if(MSVC)
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
SILENCE_CXX23_DEPRECATIONS
_SILENCE_CXX23_DEPRECATION_WARNING
_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
NOMINMAX
WIN32_LEAN_AND_MEAN
strncasecmp=_strnicmp
strcasecmp=_stricmp
)
else()
target_compile_options(yaze_common INTERFACE
-Wall -Wextra -Wpedantic
-Wno-deprecated-declarations
-Wno-c++23-compat
)
target_compile_definitions(yaze_common INTERFACE
_SILENCE_CXX23_DEPRECATION_WARNING
_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
)
endif()
endfunction()