Warning, /system/qtcurve/cmake/CMakeArrayMacros.cmake is written in an unsupported language. File is not indexed.

0001 # Copyright (C) 2013~2014 by Yichao Yu
0002 # yyc1992@gmail.com
0003 #
0004 # Redistribution and use in source and binary forms, with or without
0005 # modification, are permitted provided that the following conditions
0006 # are met:
0007 #
0008 # 1. Redistributions of source code must retain the above copyright
0009 #    notice, this list of conditions and the following disclaimer.
0010 # 2. Redistributions in binary form must reproduce the above copyright
0011 #    notice, this list of conditions and the following disclaimer in the
0012 #    documentation and/or other materials provided with the distribution.
0013 #
0014 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0015 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0016 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0017 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0018 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0019 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0020 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0021 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0023 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024 
0025 # Public functions and macros provided by this file
0026 # (See comment of each for more detail):
0027 #     cmake_array_foreach
0028 #     cmake_array_copy
0029 #     cmake_array_propagate_name
0030 #     cmake_array_new
0031 #     cmake_array_new_len
0032 #     cmake_array_append
0033 #     cmake_array_clear
0034 #     cmake_array_concat
0035 #     cmake_array_slice
0036 #     cmake_array_set_global_single
0037 #     cmake_array_set_global
0038 #     cmake_array_get_global
0039 
0040 if(COMMAND cmake_array_foreach)
0041   return()
0042 endif()
0043 
0044 include(CMakeBaseMacros)
0045 
0046 macro(cmake_array_defined array res)
0047   if(DEFINED "${array}.length" AND
0048       "x${${array}.length}x" MATCHES "^x(0|[1-9][0-9]*)x\$")
0049     set("${res}" True)
0050   else()
0051     set("${res}" False)
0052   endif()
0053 endmacro()
0054 
0055 function(cmake_array_abort_undefined array)
0056   cmake_array_defined("${array}" defined)
0057   if(NOT defined)
0058     message(FATAL_ERROR "Array ${array} is not defined.")
0059   endif()
0060 endfunction()
0061 
0062 macro(__cmake_array_foreach_real vname fname prefix start stop)
0063   foreach(__cmake_array_foreach_${vname}_${fname}_i RANGE
0064       "${start}" "${stop}")
0065     if("${__cmake_array_foreach_${vname}_${fname}_i}" STREQUAL "${stop}")
0066       break()
0067     endif()
0068     # use foreach instead of set to prevent variable ${vname} leaking to
0069     # caller scope.
0070     foreach("${vname}"
0071         "${${prefix}${__cmake_array_foreach_${vname}_${fname}_i}}")
0072       cmake_utils_call("${fname}")
0073     endforeach()
0074   endforeach()
0075 endmacro()
0076 
0077 # cmake_array_foreach(varname funcname [prefix] [start | stop | start stop])
0078 #     @varname: name of the loop variable.
0079 #     @funcname: name of the function or macro to be run in each loop.
0080 #     @prefix: name of the array. default: ARGV
0081 #     @start: the start index. default: 0
0082 #     @stop: the stop index. Default to the length of the array. For ARGV this
0083 #         is ARGC, otherwise it is @prefix.length
0084 #
0085 #     This macro run @funcname on a variable list with variable @varname
0086 #     set to the value of each variable. A variable list is a set of variables
0087 #     with names prefix+number. The prefix is @prefix and the range of the
0088 #     number is from @start to (@stop - 1). This can work on the arguments
0089 #     of a function but CANNOT work on arguments of a macro because they are
0090 #     not cmake variables.
0091 macro(cmake_array_foreach varname funcname)
0092   if("${ARGC}" STREQUAL "2")
0093     foreach(__cmake_array_foreach_${varname}_${funcname}_argc ARGC)
0094       __cmake_array_foreach_real("${varname}" "${funcname}"
0095         ARGV 0 "${${__cmake_array_foreach_${varname}_${funcname}_argc}}")
0096     endforeach()
0097   elseif("${ARGC}" STREQUAL "3")
0098     if("${ARGV2}" MATCHES "^[0-9]+\$")
0099       foreach(__cmake_array_foreach_${varname}_${funcname}_argc ARGC)
0100         __cmake_array_foreach_real("${varname}" "${funcname}"
0101           ARGV "${ARGV2}"
0102           "${${__cmake_array_foreach_${varname}_${funcname}_argc}}")
0103       endforeach()
0104     else()
0105       if("x${ARGV2}" STREQUAL "xARGV")
0106         foreach(__cmake_array_foreach_${varname}_${funcname}_argc ARGC)
0107           __cmake_array_foreach_real("${varname}" "${funcname}"
0108             ARGV 0 "${${__cmake_array_foreach_${varname}_${funcname}_argc}}")
0109         endforeach()
0110       else()
0111         cmake_array_abort_undefined("${ARGV2}")
0112         __cmake_array_foreach_real("${varname}" "${funcname}"
0113           "${ARGV2}." 0 "${${ARGV2}.length}")
0114       endif()
0115     endif()
0116   elseif("${ARGC}" STREQUAL "4")
0117     if("${ARGV2}" MATCHES "^[0-9]+\$")
0118       __cmake_array_foreach_real("${varname}" "${funcname}"
0119         ARGV "${ARGV2}" "${ARGV3}")
0120     else()
0121       cmake_array_abort_undefined("${ARGV2}")
0122       __cmake_array_foreach_real("${varname}" "${funcname}"
0123         "${ARGV2}." 0 "${ARGV3}")
0124     endif()
0125   elseif("${ARGC}" STREQUAL "5")
0126     cmake_array_abort_undefined("${ARGV2}")
0127     __cmake_array_foreach_real("${varname}" "${funcname}"
0128       "${ARGV2}." "${ARGV3}" "${ARGV4}")
0129   else()
0130     message(FATAL_ERROR "cmake_array_foreach called with wrong number of argument ${ARGC}. Expect at most 5.")
0131   endif()
0132 endmacro()
0133 
0134 macro(_cmake_array_new_name ret)
0135   cmake_utils_get_unique_name(cmake_array_name "${ret}")
0136 endmacro()
0137 
0138 # cmake_array_copy(from to [parent_scope])
0139 #     @from: name of the source array.
0140 #     @to: name of the destination array.
0141 #     @parent_scope: whether copy this array to parent scope.
0142 #
0143 #     This macro copies the @from array to @to. If @parent_scope is #true,
0144 #     the array will also be copied to parent scope.
0145 macro(cmake_array_copy from to)
0146   cmake_array_new("${to}")
0147   if("${ARGC}" GREATER 2 AND "${ARGV2}")
0148     _cmake_array_copy("${from}" "${${to}}" PARENT_SCOPE)
0149   endif()
0150   _cmake_array_copy("${from}" "${${to}}")
0151 endmacro()
0152 
0153 macro(_cmake_array_copy from to)
0154   cmake_array_abort_undefined("${from}")
0155   cmake_array_abort_undefined("${to}")
0156   set("${to}.length" "${${from}.length}" ${ARGN})
0157   # It doesn't matter to propagate one element more.
0158   foreach(__cmake_array_copy_i RANGE "${${from}.length}")
0159     set("${to}.${__cmake_array_copy_i}"
0160       "${${from}.${__cmake_array_copy_i}}" ${ARGN})
0161   endforeach()
0162 endmacro()
0163 
0164 # cmake_array_propagate_name(arrarname)
0165 #     @arrayname: name of the array to be propagate to parent scope.
0166 #
0167 #     This macro propagate the array @arrayname to the parent scope of the
0168 #     caller. Use this to return a array.
0169 macro(cmake_array_propagate name)
0170   _cmake_array_copy("${name}" "${name}" PARENT_SCOPE)
0171 endmacro()
0172 
0173 macro(__cmake_array_new_foreach)
0174   set("${new_array_name}.${i}" "${__cmake_array_new_value}" PARENT_SCOPE)
0175   math(EXPR i "${i} + 1")
0176 endmacro()
0177 
0178 # cmake_array_new(varname [elements...])
0179 #     @varname: the name of the array to be created.
0180 #     @elements: elements of the array.
0181 #
0182 #     This function create a new array of name @varname from the argument of
0183 #     the function (@elements) in the current scope.
0184 function(cmake_array_new varname)
0185   _cmake_array_new_name(new_array_name)
0186   math(EXPR length "${ARGC} - 1")
0187   set("${new_array_name}.length" "${length}" PARENT_SCOPE)
0188   set(i 0)
0189   cmake_array_foreach(__cmake_array_new_value __cmake_array_new_foreach 1)
0190   set("${varname}" "${new_array_name}" PARENT_SCOPE)
0191 endfunction()
0192 
0193 macro(__cmake_array_new_len_foreach)
0194   math(EXPR length "${i} + 1")
0195   if(length GREATER len)
0196     return()
0197   endif()
0198   set("${new_array_name}.${i}" "${__cmake_array_new_len_value}" PARENT_SCOPE)
0199   math(EXPR i "${length}")
0200 endmacro()
0201 
0202 # cmake_array_new_len(varname len [elements...])
0203 #     @varname: the name of the array to be created.
0204 #     @len: the maximum length of the array.
0205 #     @elements: elements of the array.
0206 #
0207 #     This function create a new array of name @varname from the argument of
0208 #     the function (@elements) in the current scope. At most @len elements
0209 #     will be added to the array.
0210 function(cmake_array_new_len varname len)
0211   _cmake_array_new_name(new_array_name)
0212   math(EXPR maxidx "${len} - 1")
0213   set(i 0)
0214   set(length 0)
0215   cmake_array_foreach(__cmake_array_new_len_value
0216     __cmake_array_new_len_foreach 1)
0217   set("${new_array_name}.length" "${length}" PARENT_SCOPE)
0218   set("${varname}" "${new_array_name}" PARENT_SCOPE)
0219 endfunction()
0220 
0221 macro(__cmake_array_append_foreach)
0222   set("${varname}.${${varname}.length}" "${element}")
0223   math(EXPR "${varname}.length" "${${varname}.length} + 1")
0224 endmacro()
0225 
0226 # cmake_array_append(varname [elements...])
0227 #     @varname: name of the array.
0228 #     @elements: elements to be appended to the array.
0229 #
0230 #     This function appends @elements to @varname.
0231 function(cmake_array_append varname)
0232   cmake_array_abort_undefined("${varname}")
0233   cmake_array_foreach(element __cmake_array_append_foreach 1)
0234   cmake_array_propagate("${varname}")
0235 endfunction()
0236 
0237 # cmake_array_clear(varname)
0238 #     @varname: name of the array to be cleared.
0239 #
0240 #     This function clears array @varname.
0241 function(cmake_array_clear varname)
0242   cmake_array_abort_undefined("${varname}")
0243   set("${varname}.length" "0" PARENT_SCOPE)
0244 endfunction()
0245 
0246 # cmake_array_concat(varname [prefix] [start | stop | start stop])
0247 #     @varname: name of the destination array.
0248 #     @prefix: name of the source array. default: ARGV
0249 #     @start: the start index. default: 0
0250 #     @stop: the stop index. Default to length of the array.
0251 #
0252 #     This macro append the array @prefix to array @varname. @prefix can be
0253 #     the argument list of a function. Defaults are treated the same with
0254 #     #cmake_array_foreach. See #cmake_array_foreach for more detail.
0255 macro(cmake_array_concat varname)
0256   # Lexical scope used here.
0257   # Do not move the definition out of the parent macro.
0258   macro(__cmake_array_concat_foreach)
0259     cmake_array_append("${varname}" "${__cmake_array_concat_value}")
0260   endmacro()
0261   cmake_array_foreach(__cmake_array_concat_value
0262     __cmake_array_concat_foreach ${ARGN})
0263 endmacro()
0264 
0265 # cmake_array_slice(varname [prefix] [start | stop | start stop])
0266 #     @varname: name of the destination array.
0267 #     @prefix: name of the source array. default: ARGV
0268 #     @start: the start index. default: 0
0269 #     @stop: the stop index. Default to length of the array.
0270 #
0271 #     This macro create a new array @varname from array @prefix between
0272 #     @start and @stop. See #cmake_array_foreach for more detail.
0273 macro(cmake_array_slice varname)
0274   cmake_array_new("${varname}")
0275   cmake_array_concat("${${varname}}" ${ARGN})
0276 endmacro()
0277 
0278 # cmake_array_set_global_single(global [prefix] [start | stop | start stop])
0279 #     @global: the name of the global to save the array.
0280 #     @prefix: name of the source array. default: ARGV
0281 #     @start: the start index. default: 0
0282 #     @stop: the stop index. Default to length of the array.
0283 #
0284 #     This macro saves the array to @global. For more detail about @prefix,
0285 #     @start and @stop, see #cmake_array_foreach.
0286 #     See also #cmake_array_set_global and #cmake_array_get_global.
0287 macro(cmake_array_set_global_single global)
0288   macro(__cmake_array_set_global_foreach)
0289     cmake_utils_set_global("${global}.${__cmake_array_set_global_i}"
0290       "${__cmake_array_set_global_value}")
0291     math(EXPR __cmake_array_set_global_i "${__cmake_array_set_global_i} + 1")
0292   endmacro()
0293   foreach(__cmake_array_set_global_i 0)
0294     cmake_array_foreach(__cmake_array_set_global_value
0295       __cmake_array_set_global_foreach ${ARGN})
0296     cmake_utils_set_global("${global}.length" "${__cmake_array_set_global_i}")
0297   endforeach()
0298 endmacro()
0299 
0300 function(_cmake_array_get_global_single global array)
0301   cmake_utils_get_global("${global}.length" "${array}.length")
0302   foreach(array_i RANGE 0 "${${array}.length}")
0303     if("x${${array}.length}x" STREQUAL "x${array_i}x")
0304       break()
0305     endif()
0306     cmake_utils_get_global("${global}.${array_i}" "${array}.${array_i}")
0307   endforeach()
0308   cmake_array_propagate("${array}")
0309 endfunction()
0310 
0311 macro(__cmake_array_set_global_rec_foreach)
0312   foreach(global "${global}.${__cmake_array_i}")
0313     foreach(array "${__cmake_array_value}")
0314       _cmake_array_set_global_rec("${global}" "${array}" "${level}")
0315     endforeach()
0316   endforeach()
0317   math(EXPR __cmake_array_i "${__cmake_array_i} + 1")
0318 endmacro()
0319 
0320 function(_cmake_array_set_global_rec global array level)
0321   if("${level}" LESS 2)
0322     cmake_array_set_global_single("${global}" "${array}")
0323     return()
0324   endif()
0325   math(EXPR level "${level} - 1")
0326   cmake_utils_set_global("${global}.length" "${${array}.length}")
0327   foreach(__cmake_array_i 0)
0328     cmake_array_foreach(__cmake_array_value
0329       __cmake_array_set_global_rec_foreach "${array}")
0330   endforeach()
0331 endfunction()
0332 
0333 macro(__cmake_array_get_global_rec global array level)
0334   if("${level}" LESS 2)
0335     _cmake_array_get_global_single("${global}" "${array}")
0336   else()
0337     math(EXPR new_level "${level} - 1")
0338     cmake_utils_get_global("${global}.length" "${array}.length")
0339     foreach(array_i RANGE 0 "${${array}.length}")
0340       if("x${${array}.length}x" STREQUAL "x${array_i}x")
0341         break()
0342       endif()
0343       __cmake_array_get_global_rec("${global}.${array_i}"
0344         "${array}.${array_i}" "${new_level}")
0345       set("${array}.${array_i}" "${array}.${array_i}")
0346     endforeach()
0347   endif()
0348   cmake_array_propagate("${array}")
0349 endmacro()
0350 
0351 function(_cmake_array_get_global_rec global array level)
0352   __cmake_array_get_global_rec("${global}" "${array}" "${level}")
0353 endfunction()
0354 
0355 # cmake_array_get_global(global array [level])
0356 #     @global: the name of the global to save the array.
0357 #     @array: the name of the array.
0358 #     @level: level of recursion. Default to 1.
0359 #
0360 #     This macro retrieves a multi-level array that is previously
0361 #     saved as @global to @array.
0362 #     See also #cmake_array_set_global and #cmake_array_set_global_single.
0363 macro(cmake_array_get_global global array)
0364   _cmake_array_new_name("${array}")
0365   if("${ARGC}" GREATER 2)
0366     _cmake_array_get_global_rec("${global}" "${${array}}" "${ARGV2}")
0367   else()
0368     _cmake_array_get_global_single("${global}" "${${array}}")
0369   endif()
0370 endmacro()
0371 
0372 # cmake_array_set_global(global array [level])
0373 #     @global: the name of the global to save the array.
0374 #     @array: the name of the array.
0375 #     @level: level of recursion. Default to 1.
0376 #
0377 #     This macro saves the multi-level @array as @global.
0378 #     See also #cmake_array_get_global and #cmake_array_set_global_single.
0379 macro(cmake_array_set_global global array)
0380   if("${ARGC}" GREATER 2)
0381     _cmake_array_set_global_rec("${global}" "${array}" "${ARGV2}")
0382   else()
0383     cmake_array_set_global_single("${global}" "${array}")
0384   endif()
0385 endmacro()
0386 
0387 function(cmake_array_insert array index)
0388   cmake_array_slice(array_insert_after "${array}" "${index}"
0389     "${${array}.length}")
0390   cmake_array_slice(array_insert_before "${array}" 0 "${index}")
0391   cmake_array_concat("${array_insert_before}" 2)
0392   cmake_array_concat("${array_insert_before}" "${array_insert_after}")
0393   _cmake_array_copy("${array_insert_before}" "${array}" PARENT_SCOPE)
0394 endfunction()
0395 
0396 function(cmake_array_pop)
0397 endfunction()
0398 
0399 function(cmake_array_remove)
0400 endfunction()
0401 
0402 function(cmake_array_reverse)
0403 endfunction()