|
1 | 1 | include(CheckCCompilerFlag)
|
2 | 2 |
|
3 |
| -function(try_add_compile_option option) |
4 |
| - string(MAKE_C_IDENTIFIER ${option} result) |
5 |
| - string(TOUPPER ${result} result) |
6 |
| - set(result "C_SUPPORTS${result}") |
7 |
| - set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 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}") |
8 | 7 | if(NOT MSVC)
|
9 | 8 | set(CMAKE_REQUIRED_FLAGS "-Werror")
|
10 | 9 | endif()
|
11 |
| - check_c_compiler_flag(${option} ${result}) |
12 |
| - if(${result}) |
13 |
| - get_property(compile_options |
14 |
| - DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
15 |
| - PROPERTY COMPILE_OPTIONS |
16 |
| - ) |
17 |
| - list(APPEND compile_options "${option}") |
18 |
| - set_property( |
19 |
| - DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
20 |
| - PROPERTY COMPILE_OPTIONS "${compile_options}" |
21 |
| - ) |
22 |
| - 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) |
23 | 16 | endfunction()
|
| 17 | + |
| 18 | +# Append flags to the COMPILE_OPTIONS directory property if CC accepts them. |
| 19 | +macro(try_add_compile_option) |
| 20 | + secp256k1_check_c_flags_internal("${ARGV}" result) |
| 21 | + if(result) |
| 22 | + add_compile_options(${ARGV}) |
| 23 | + endif() |
| 24 | +endmacro() |
0 commit comments