myx/MyxCMake/lib/macro/CheckEnableCxxCompilerFlag.cmake

39 lines
1.1 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

include_guard(GLOBAL)
# Добавление флага к списку используемых после проверки
# возможности его использования текущим компилятором
# Основано на https://github.com/bluescarni/yacma
include(CheckCXXCompilerFlag)
macro(check_enable_cxx_compiler_flag FLAG)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${FLAG}" check_cxx_flag)
unset(CMAKE_REQUIRED_QUIET)
if(check_cxx_flag)
myx_message_notice("'${FLAG}': flag is supported.")
if(ARG_TARGET)
target_compile_options(${ARG_TARGET} PUBLIC ${FLAG})
else()
add_compile_options(${FLAG})
endif()
else()
myx_message_status("'${FLAG}': flag is NOT supported.")
endif()
unset(check_cxx_flag CACHE)
foreach(iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()