secp256k1-zkp/cmake/TryAppendCFlags.cmake
Hennadii Stepanov 6ece1507cb
cmake, refactor: Rename try_add_compile_option to try_append_cflags
Actually, `try_append_cflags()` can handle a list of flags, and the new
name is similar to the one used in `configure.ac`.
2023-04-27 14:41:13 +01:00

25 lines
685 B
CMake

include(CheckCCompilerFlag)
function(secp256k1_check_c_flags_internal flags output)
string(MAKE_C_IDENTIFIER "${flags}" result)
string(TOUPPER "${result}" result)
set(result "C_SUPPORTS_${result}")
if(NOT MSVC)
set(CMAKE_REQUIRED_FLAGS "-Werror")
endif()
# This avoids running a linker.
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
check_c_compiler_flag("${flags}" ${result})
set(${output} ${${result}} PARENT_SCOPE)
endfunction()
# Append flags to the COMPILE_OPTIONS directory property if CC accepts them.
macro(try_append_c_flags)
secp256k1_check_c_flags_internal("${ARGV}" result)
if(result)
add_compile_options(${ARGV})
endif()
endmacro()