summaryrefslogtreecommitdiff
path: root/cmake/helpers/EflMacros.cmake
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-20 09:39:46 -0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-01-23 18:23:40 +0100
commitc4e78153b16f89a14245db97316158006a732cde (patch)
treeb7fba6c1cf369608c0ae2103dac6dadd173f0a07 /cmake/helpers/EflMacros.cmake
parent76212a91625cd72142d0fe27cb85ccc5b29fedf5 (diff)
EflMacros: replace macros with functions.
Macros do not start a new scope and can leave leftovers, then use functions. However to set and append to global scope is cumbersome, add functions to aid that.
Diffstat (limited to 'cmake/helpers/EflMacros.cmake')
-rw-r--r--cmake/helpers/EflMacros.cmake108
1 files changed, 60 insertions, 48 deletions
diff --git a/cmake/helpers/EflMacros.cmake b/cmake/helpers/EflMacros.cmake
index 9ae80aaa3c..9f8db24a4c 100644
--- a/cmake/helpers/EflMacros.cmake
+++ b/cmake/helpers/EflMacros.cmake
@@ -1,3 +1,28 @@
1# NOTE:
2#
3# - Use function() whenever possible, macro() doesn't start a new
4# variable scope and needs careful handling to avoid left overs.
5#
6# - To 'export' values or lists, use the macros SET_GLOBAL() and
7# LIST_APPEND_GLOBAL().
8#
9
10# LIST_APPEND_GLOBAL(Var Element)
11#
12# Append to a list in the global variable scope (cache internal)
13function(LIST_APPEND_GLOBAL _var _element)
14 set(_local ${${_var}})
15 list(APPEND _local ${_element})
16 set(${_var} ${_local} CACHE INTERNAL "")
17endfunction()
18
19# SET_GLOBAL(Var Value [Help])
20#
21# Set a variable in the global variable scope (cache internal)
22function(SET_GLOBAL _var _value)
23 set(${_var} "${_value}" CACHE INTERNAL "${ARGN}")
24endfunction()
25
1# EFL_OPTION(Name Help Default) 26# EFL_OPTION(Name Help Default)
2# 27#
3# Declare an option() that will be automatically printed by 28# Declare an option() that will be automatically printed by
@@ -5,48 +30,47 @@
5# 30#
6# To extend the EFL_OPTIONS_SUMMARY() message, use 31# To extend the EFL_OPTIONS_SUMMARY() message, use
7# EFL_OPTION_SET_MESSAGE(Name Message) 32# EFL_OPTION_SET_MESSAGE(Name Message)
8macro(EFL_OPTION _name _help _defval) 33function(EFL_OPTION _name _help _defval)
9 set(_extra_args ${ARGN})
10 set(_type) 34 set(_type)
35 set(_vartype)
11 set(_choices) 36 set(_choices)
12 list(LENGTH _extra_args _argc) 37 list(LENGTH ARGN _argc)
13 if(_argc LESS 1) 38 if(_argc LESS 1)
14 set(_type BOOL) 39 set(_type BOOL)
40 set(_vartype BOOL)
15 else() 41 else()
16 list(GET _extra_args 0 _type) 42 list(GET ARGN 0 _type)
17 list(REMOVE_AT _extra_args 0) 43 set(_vartype ${_type})
44 list(REMOVE_AT ARGN 0)
18 endif() 45 endif()
19 if(${_type} STREQUAL "CHOICE") 46 if(${_vartype} STREQUAL "CHOICE")
20 set(_type STRING) 47 set(_type STRING)
21 set(EFL_OPTION_CHOICES_${_name} ${_extra_args}) 48 SET_GLOBAL(EFL_OPTION_CHOICES_${_name} "${ARGN}" "Possible values for ${_name}")
22 set(_choices " (Choices: ${_extra_args})") 49 set(_choices " (Choices: ${ARGN})")
23 endif() 50 endif()
24 list(APPEND EFL_ALL_OPTIONS ${_name}) 51
25 set(EFL_OPTION_DEFAULT_${_name} "${_defval}") 52 LIST_APPEND_GLOBAL(EFL_ALL_OPTIONS ${_name})
26 set(EFL_OPTION_TYPE_${_name} "${_type}") 53
54 SET_GLOBAL(EFL_OPTION_DEFAULT_${_name} "${_defval}" "Default value for ${_name}")
55 SET_GLOBAL(EFL_OPTION_TYPE_${_name} "${_vartype}" "Type of ${_name}")
27 set(${_name} ${_defval} CACHE ${_type} "${_help}${_choices}") 56 set(${_name} ${_defval} CACHE ${_type} "${_help}${_choices}")
28 option(${_name} "${_help}${_choices}" ${_defval}) 57 option(${_name} "${_help}${_choices}" ${_defval})
29 58
30 if(_extra_args) 59 if(_choices)
31 list(FIND _extra_args ${${_name}} RET) 60 list(FIND ARGN "${${_name}}" _ret)
32 if(${RET} EQUAL -1) 61 if(${_ret} EQUAL -1)
33 message(FATAL_ERROR "Invalid choice ${_name}=${${_name}}${_choices}") 62 message(FATAL_ERROR "Invalid choice ${_name}=${${_name}}${_choices}")
34 endif() 63 endif()
35 endif() 64 endif()
36 65endfunction()
37 unset(_type)
38 unset(_choices)
39 unset(_extra_args)
40 unset(_argc)
41endmacro()
42 66
43# EFL_OPTION_SET_MESSAGE(Name Message) 67# EFL_OPTION_SET_MESSAGE(Name Message)
44# 68#
45# Extends the summary line output by EFL_OPTIONS_SUMMARY() 69# Extends the summary line output by EFL_OPTIONS_SUMMARY()
46# with more details. 70# with more details.
47macro(EFL_OPTION_SET_MESSAGE _name _message) 71function(EFL_OPTION_SET_MESSAGE _name _message)
48 set(EFL_OPTION_MESSAGE_${_name} "${_message}") 72 SET_GLOBAL(EFL_OPTION_MESSAGE_${_name} "${_message}")
49endmacro() 73endfunction()
50 74
51# EFL_OPTIONS_SUMMARY() 75# EFL_OPTIONS_SUMMARY()
52# Shows the summary of options, their values and related messages. 76# Shows the summary of options, their values and related messages.
@@ -64,6 +88,8 @@ function(EFL_OPTIONS_SUMMARY)
64 endif() 88 endif()
65 if(EFL_OPTION_MESSAGE_${_o}) 89 if(EFL_OPTION_MESSAGE_${_o})
66 set(_m " [${EFL_OPTION_MESSAGE_${_o}}]") 90 set(_m " [${EFL_OPTION_MESSAGE_${_o}}]")
91 else()
92 set(_m)
67 endif() 93 endif()
68 message(STATUS " ${_o}=${_v} (${_i})${_m}") 94 message(STATUS " ${_o}=${_v} (${_i})${_m}")
69 endforeach() 95 endforeach()
@@ -85,10 +111,13 @@ endfunction()
85set(EFL_ALL_LIBS) 111set(EFL_ALL_LIBS)
86set(EFL_ALL_TESTS) 112set(EFL_ALL_TESTS)
87 113
88macro(EFL_FINALIZE) 114# EFL_FINALIZE()
115#
116# Finalize EFL processing, adding extra targets.
117function(EFL_FINALIZE)
89 add_custom_target(all-libs DEPENDS ${EFL_ALL_LIBS}) 118 add_custom_target(all-libs DEPENDS ${EFL_ALL_LIBS})
90 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS}) 119 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS})
91endmacro() 120endfunction()
92 121
93# EFL_LIB(Name) 122# EFL_LIB(Name)
94# 123#
@@ -105,7 +134,7 @@ endmacro()
105# - target_compile_definitions() to ${Name}_DEFINITIONS 134# - target_compile_definitions() to ${Name}_DEFINITIONS
106# - compile tests in ${Name}_TESTS using EFL_TEST() 135# - compile tests in ${Name}_TESTS using EFL_TEST()
107# 136#
108macro(EFL_LIB _target) 137function(EFL_LIB _target)
109 string(TOLOWER ${_target} _target_lc) 138 string(TOLOWER ${_target} _target_lc)
110 set(EFL_LIB_CURRENT ${_target}) 139 set(EFL_LIB_CURRENT ${_target})
111 set(EFL_LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/${_target_lc}) 140 set(EFL_LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/${_target_lc})
@@ -222,22 +251,9 @@ macro(EFL_LIB _target)
222 unset(t) 251 unset(t)
223 add_custom_target(${_target}-tests DEPENDS ${${_target}_TESTS}) 252 add_custom_target(${_target}-tests DEPENDS ${${_target}_TESTS})
224 add_custom_target(${_target}-modules DEPENDS ${${_target}_MODULES}) 253 add_custom_target(${_target}-modules DEPENDS ${${_target}_MODULES})
225 list(APPEND EFL_ALL_LIBS ${_target}) 254 LIST_APPEND_GLOBAL(EFL_ALL_LIBS ${_target})
226 list(APPEND EFL_ALL_TESTS ${_target}-tests) 255 LIST_APPEND_GLOBAL(EFL_ALL_TESTS ${_target}-tests)
227 256endfunction()
228 unset(_sources)
229 unset(_headers)
230 unset(_deps)
231 unset(EFL_LIB_CURRENT)
232 unset(EFL_LIB_SOURCE_DIR)
233 unset(EFL_LIB_BINARY_DIR)
234 unset(EFL_BIN_SOURCE_DIR)
235 unset(EFL_BIN_BINARY_DIR)
236 unset(EFL_MODULES_SOURCE_DIR)
237 unset(EFL_MODULES_BINARY_DIR)
238 unset(EFL_TESTS_SOURCE_DIR)
239 unset(EFL_TESTS_BINARY_DIR)
240endmacro()
241 257
242 258
243# EFL_TEST(Name) 259# EFL_TEST(Name)
@@ -417,13 +433,9 @@ function(EFL_MODULE _modname)
417 set_target_properties(${_modtarget} PROPERTIES 433 set_target_properties(${_modtarget} PROPERTIES
418 POSITION_INDEPENDENT_CODE TRUE) 434 POSITION_INDEPENDENT_CODE TRUE)
419 435
420 set(_all_mods ${${EFL_LIB_CURRENT}_STATIC_MODULES}) 436 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_STATIC_MODULES ${_modtarget})
421 list(APPEND _all_mods ${_modtarget})
422 set(${EFL_LIB_CURRENT}_STATIC_MODULES ${_all_mods} PARENT_SCOPE)
423 else() 437 else()
424 set(_all_mods ${${EFL_LIB_CURRENT}_MODULES})
425 list(APPEND _all_mods ${_modtarget})
426 set(${EFL_LIB_CURRENT}_MODULES ${_all_mods} PARENT_SCOPE)
427 target_link_libraries(${_modtarget} ${EFL_LIB_CURRENT}) 438 target_link_libraries(${_modtarget} ${EFL_LIB_CURRENT})
439 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_MODULES ${_modtarget})
428 endif() 440 endif()
429endfunction() 441endfunction()