The pattern that we have used here is:
- Define a function or macro and place it in a module
- Include the module
- Call the function or macro
From the output, we can see that the code checks each flag in the list and as soon as the check is successful, it prints the successful compile flag. Let us look inside the set_compiler_flag.cmake module. This module, in turn, includes three modules:
include(CheckCCompilerFlag)include(CheckCXXCompilerFlag)include(CheckFortranCompilerFlag)
These are standard CMake modules and CMake will locate them in ${CMAKE_MODULE_PATH}. These modules provide the check_c_compiler_flag, check_cxx_compiler_flag, and check_fortran_compiler_flag macros, respectively. Then comes the function definition:
function(set_compiler_flag ...