blob: cf690f4a33c523f04aa37ba753d6569cbdf1314b [file] [log] [blame]
Alexey Samsonov163ab9d2013-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)
Aaron Ballmane927a172014-10-23 22:13:52 +00005 set(argstring "")
Alexey Samsonov163ab9d2013-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)
Aaron Ballmane927a172014-10-23 22:13:52 +000013 set(argstring "")
Alexey Samsonov163ab9d2013-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 Collingbournecbdea322013-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()
Alexey Samsonovb73db722014-02-18 07:52:40 +000029
Alexey Samsonov32956d62014-03-13 09:31:36 +000030# Appends value to all lists in ARGN, if the condition is true.
Kuba Brecka14c0c592014-10-15 22:47:54 +000031macro(append_list_if condition value)
Alexey Samsonov32956d62014-03-13 09:31:36 +000032 if(${condition})
33 foreach(list ${ARGN})
34 list(APPEND ${list} ${value})
35 endforeach()
Alexey Samsonovb73db722014-02-18 07:52:40 +000036 endif()
37endmacro()
38
Alexey Samsonovfe7e28c2014-03-13 11:31:10 +000039# 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
Alexey Samsonovb73db722014-02-18 07:52:40 +000048macro(append_no_rtti_flag list)
Kuba Brecka14c0c592014-10-15 22:47:54 +000049 append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
50 append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
Alexey Samsonovb73db722014-02-18 07:52:40 +000051endmacro()
Yury Gribov8e49b472015-04-09 08:06:49 +000052
53macro(append_have_file_definition filename varname list)
54 check_include_file("${filename}" "${varname}")
Reid Kleckneraa902962015-05-20 16:56:17 +000055 if (NOT ${varname})
Yury Gribov8e49b472015-04-09 08:06:49 +000056 set("${varname}" 0)
57 endif()
58 list(APPEND ${list} "${varname}=${${varname}}")
59endmacro()
Chris Bieneman361231e2015-08-13 20:38:16 +000060
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()