forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
18 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
include(CheckCCompilerFlag) | ||
|
||
function(try_add_compile_option option) | ||
string(MAKE_C_IDENTIFIER ${option} result) | ||
string(TOUPPER ${result} result) | ||
set(result "C_SUPPORTS${result}") | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
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() | ||
check_c_compiler_flag(${option} ${result}) | ||
if(${result}) | ||
get_property(compile_options | ||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
PROPERTY COMPILE_OPTIONS | ||
) | ||
list(APPEND compile_options "${option}") | ||
set_property( | ||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
PROPERTY COMPILE_OPTIONS "${compile_options}" | ||
) | ||
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_add_compile_option) | ||
secp256k1_check_c_flags_internal("${ARGV}" result) | ||
if(result) | ||
add_compile_options(${ARGV}) | ||
endif() | ||
endmacro() |