blob: cf690f4a33c523f04aa37ba753d6569cbdf1314b [file] [log] [blame]
Alexey Samsonov392c50d2013-01-18 16:05:21 +00001# 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.
4function(set_target_compile_flags target)
Stephen Hines6d186232014-11-26 17:56:19 -08005 set(argstring "")
Alexey Samsonov392c50d2013-01-18 16:05:21 +00006 foreach(arg ${ARGN})
7 set(argstring "${argstring} ${arg}")
8 endforeach()
9 set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
10endfunction()
11
12function(set_target_link_flags target)
Stephen Hines6d186232014-11-26 17:56:19 -080013 set(argstring "")
Alexey Samsonov392c50d2013-01-18 16:05:21 +000014 foreach(arg ${ARGN})
15 set(argstring "${argstring} ${arg}")
16 endforeach()
17 set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
18endfunction()
19
Peter Collingbourne7e8db742013-10-25 23:03:34 +000020# Set the variable var_PYBOOL to True if var holds a true-ish string,
21# otherwise set it to False.
22macro(pythonize_bool var)
23 if (${var})
24 set(${var}_PYBOOL True)
25 else()
26 set(${var}_PYBOOL False)
27 endif()
28endmacro()
Stephen Hines2d1fdb22014-05-28 23:58:16 -070029
30# Appends value to all lists in ARGN, if the condition is true.
Stephen Hines6d186232014-11-26 17:56:19 -080031macro(append_list_if condition value)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070032 if(${condition})
33 foreach(list ${ARGN})
34 list(APPEND ${list} ${value})
35 endforeach()
36 endif()
37endmacro()
38
39# Appends value to all strings in ARGN, if the condition is true.
40macro(append_string_if condition value)
41 if(${condition})
42 foreach(str ${ARGN})
43 set(${str} "${${str}} ${value}")
44 endforeach()
45 endif()
46endmacro()
47
48macro(append_no_rtti_flag list)
Stephen Hines6d186232014-11-26 17:56:19 -080049 append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
50 append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
Stephen Hines2d1fdb22014-05-28 23:58:16 -070051endmacro()
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070052
53macro(append_have_file_definition filename varname list)
54 check_include_file("${filename}" "${varname}")
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070055 if (NOT ${varname})
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070056 set("${varname}" 0)
57 endif()
58 list(APPEND ${list} "${varname}=${${varname}}")
59endmacro()
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080060
61macro(list_union output input1 input2)
62 set(${output})
63 foreach(it ${${input1}})
64 list(FIND ${input2} ${it} index)
65 if( NOT (index EQUAL -1))
66 list(APPEND ${output} ${it})
67 endif()
68 endforeach()
69endmacro()