cmake: Use add_compile_options()
in try_add_compile_option()
This change drops tinkering with the `COMPILE_OPTIONS` directory property. Also `try_add_compile_option()` can handle a list of flags now, if they are required to be checked simultaneously. An explanatory comments have been added as well.
This commit is contained in:
parent
4b84f4bf0f
commit
19516ed3e9
@ -1,23 +1,24 @@
|
|||||||
include(CheckCCompilerFlag)
|
include(CheckCCompilerFlag)
|
||||||
|
|
||||||
function(try_add_compile_option option)
|
function(secp256k1_check_c_flags_internal flags output)
|
||||||
string(MAKE_C_IDENTIFIER ${option} result)
|
string(MAKE_C_IDENTIFIER "${flags}" result)
|
||||||
string(TOUPPER ${result} result)
|
string(TOUPPER "${result}" result)
|
||||||
set(result "C_SUPPORTS${result}")
|
set(result "C_SUPPORTS_${result}")
|
||||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set(CMAKE_REQUIRED_FLAGS "-Werror")
|
set(CMAKE_REQUIRED_FLAGS "-Werror")
|
||||||
endif()
|
endif()
|
||||||
check_c_compiler_flag(${option} ${result})
|
|
||||||
if(${result})
|
# This avoids running a linker.
|
||||||
get_property(compile_options
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
check_c_compiler_flag("${flags}" ${result})
|
||||||
PROPERTY COMPILE_OPTIONS
|
|
||||||
)
|
set(${output} ${${result}} PARENT_SCOPE)
|
||||||
list(APPEND compile_options "${option}")
|
|
||||||
set_property(
|
|
||||||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
PROPERTY COMPILE_OPTIONS "${compile_options}"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Append flags to the COMPILE_OPTIONS directory property if CC accepts them.
|
||||||
|
macro(try_add_compile_option)
|
||||||
|
secp256k1_check_c_flags_internal("${ARGV}" result)
|
||||||
|
if(result)
|
||||||
|
add_compile_options(${ARGV})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user