macro(xaml_check_ipo)
    if(NOT XAML_ENABLE_IPO)
        include(CheckIPOSupported)
        check_ipo_supported(RESULT XAML_ENABLE_IPO OUTPUT output)
    endif()

    if(XAML_ENABLE_IPO)
        set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
        message(STATUS "LTO is enabled for Release")
    endif()
endmacro()

macro(xaml_fix_rtti_flags)
    if(${XAML_NO_RTTI})
        if(MSVC)
            string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
        else()
            string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
        endif()
    endif()
endmacro()

macro(xaml_fix_warning_flags)
    if(MSVC)
        string(REGEX REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
        string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    endif()
endmacro()

macro(xaml_fix_char8_t_flags)
    # /Zc:char8_t will be overrided by /std:c++latest
    if(MSVC)
        set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "")
        set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "")
        list(APPEND XAML_COMPILE_OPTIONS "/utf-8")
    endif()
endmacro()

macro(xaml_fix_msvc_preprocessor)
    if(MSVC AND (NOT CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang"))
        set(CMAKE_C11_STANDARD_COMPILE_OPTION "/std:c11")
        set(CMAKE_C11_EXTENSION_COMPILE_OPTION "/std:c11")
        list(APPEND XAML_COMPILE_OPTIONS "/Zc:preprocessor" "/wd5104" "/wd5105")
    endif()
endmacro()
