- Modified the yaze_add_compiler_flags function to set C++ and C standards in the parent scope, ensuring they are applied correctly across the project. - Added a new compiler flag for MSVC to support C++20/23 features, enhancing compatibility with modern C++ standards. Benefits: - Improved consistency in compiler settings across different CMake targets. - Enhanced support for newer C++ features, facilitating modern development practices.
73 lines
2.5 KiB
CMake
73 lines
2.5 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
|
|
/std:c++latest # Required for C++20/23 features like std::span
|
|
)
|
|
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()
|