Following the recommended practice of the previous recipe, we will define the function in a module (set_compiler_flag.cmake), include the module, and then call the function. The module contains the following code, which we will discuss later:
include(CheckCCompilerFlag)include(CheckCXXCompilerFlag)include(CheckFortranCompilerFlag)function(set_compiler_flag _result _lang) # build a list of flags from the arguments set(_list_of_flags)
# also figure out whether the function # is required to find a flag set(_flag_is_required FALSE) foreach(_arg IN ITEMS ${ARGN}) string(TOUPPER "${_arg}" _arg_uppercase) if(_arg_uppercase STREQUAL "REQUIRED") set(_flag_is_required TRUE) else() list(APPEND _list_of_flags "${_arg}") endif() endforeach() ...