Alexey Samsonov | 163ab9d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 1 | # Because compiler-rt spends a lot of time setting up custom compile flags, |
| 2 | # define a handy helper function for it. The compile flags setting in CMake |
| 3 | # has serious issues that make its syntax challenging at best. |
| 4 | function(set_target_compile_flags target) |
| 5 | foreach(arg ${ARGN}) |
| 6 | set(argstring "${argstring} ${arg}") |
| 7 | endforeach() |
| 8 | set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}") |
| 9 | endfunction() |
| 10 | |
| 11 | function(set_target_link_flags target) |
| 12 | foreach(arg ${ARGN}) |
| 13 | set(argstring "${argstring} ${arg}") |
| 14 | endforeach() |
| 15 | set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}") |
| 16 | endfunction() |
| 17 | |
Alexey Samsonov | 5cb7860 | 2013-02-08 07:39:25 +0000 | [diff] [blame] | 18 | # Check if a given flag is present in a space-separated flag_string. |
| 19 | # Store the result in out_var. |
| 20 | function(find_flag_in_string flag_string flag out_var) |
Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 21 | string(REPLACE " " ";" flag_list "${flag_string}") |
Alexey Samsonov | 5cb7860 | 2013-02-08 07:39:25 +0000 | [diff] [blame] | 22 | list(FIND flag_list ${flag} flag_pos) |
| 23 | if(NOT flag_pos EQUAL -1) |
| 24 | set(${out_var} TRUE PARENT_SCOPE) |
| 25 | else() |
| 26 | set(${out_var} FALSE PARENT_SCOPE) |
| 27 | endif() |
| 28 | endfunction() |
Peter Collingbourne | cbdea32 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 29 | |
| 30 | # Set the variable var_PYBOOL to True if var holds a true-ish string, |
| 31 | # otherwise set it to False. |
| 32 | macro(pythonize_bool var) |
| 33 | if (${var}) |
| 34 | set(${var}_PYBOOL True) |
| 35 | else() |
| 36 | set(${var}_PYBOOL False) |
| 37 | endif() |
| 38 | endmacro() |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 39 | |
Alexey Samsonov | 32956d6 | 2014-03-13 09:31:36 +0000 | [diff] [blame] | 40 | # Appends value to all lists in ARGN, if the condition is true. |
| 41 | macro(append_if condition value) |
| 42 | if(${condition}) |
| 43 | foreach(list ${ARGN}) |
| 44 | list(APPEND ${list} ${value}) |
| 45 | endforeach() |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 46 | endif() |
| 47 | endmacro() |
| 48 | |
Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame^] | 49 | # Appends value to all strings in ARGN, if the condition is true. |
| 50 | macro(append_string_if condition value) |
| 51 | if(${condition}) |
| 52 | foreach(str ${ARGN}) |
| 53 | set(${str} "${${str}} ${value}") |
| 54 | endforeach() |
| 55 | endif() |
| 56 | endmacro() |
| 57 | |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 58 | macro(append_no_rtti_flag list) |
Alexey Samsonov | 32956d6 | 2014-03-13 09:31:36 +0000 | [diff] [blame] | 59 | append_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list}) |
| 60 | append_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list}) |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 61 | endmacro() |