myx/MyxCMake/lib/macro/CheckEnableCxxCompilerFlag.cmake

38 lines
935 B
CMake
Raw Normal View History

2022-10-06 23:49:02 +00:00
include_guard(GLOBAL)
# based on 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})
2022-10-07 05:03:03 +00:00
set(CMAKE_REQUIRED_QUIET TRUE)
2022-10-06 23:49:02 +00:00
check_cxx_compiler_flag("${flag}" check_cxx_flag)
2022-10-07 05:03:03 +00:00
unset(CMAKE_REQUIRED_QUIET)
2022-10-06 23:49:02 +00:00
if(check_cxx_flag)
2022-10-07 05:03:03 +00:00
myx_message_notice("'${flag}': flag is supported.")
2022-10-06 23:49:02 +00:00
if(ARG_TARGET)
target_compile_options(${ARG_TARGET} PUBLIC ${flag})
else()
add_compile_options(${flag})
endif()
2022-10-07 05:03:03 +00:00
else()
myx_message_status("'${flag}': flag is NOT supported.")
2022-10-06 23:49:02 +00:00
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()