/ src / secp256k1 / cmake / TryAppendCFlags.cmake
TryAppendCFlags.cmake
 1  include(CheckCCompilerFlag)
 2  
 3  function(secp256k1_check_c_flags_internal flags output)
 4    string(MAKE_C_IDENTIFIER "${flags}" result)
 5    string(TOUPPER "${result}" result)
 6    set(result "C_SUPPORTS_${result}")
 7    if(NOT MSVC)
 8      set(CMAKE_REQUIRED_FLAGS "-Werror")
 9    endif()
10  
11    # This avoids running a linker.
12    set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
13    check_c_compiler_flag("${flags}" ${result})
14  
15    set(${output} ${${result}} PARENT_SCOPE)
16  endfunction()
17  
18  # Append flags to the COMPILE_OPTIONS directory property if CC accepts them.
19  macro(try_append_c_flags)
20    secp256k1_check_c_flags_internal("${ARGV}" result)
21    if(result)
22      add_compile_options(${ARGV})
23    endif()
24  endmacro()