Warning, /system/qtcurve/cmake/CMakeBaseMacros.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_utils_call 0028 # cmake_utils_call_with_var 0029 # cmake_utils_call_once 0030 # cmake_utils_set_and_make_dir 0031 0032 # Public globals registered by this file: 0033 # (See ##cmake_utils_get_global and the comment 0034 # for each of them for more detail) 0035 # CMAKE_GENERAL_BASE 0036 0037 if(COMMAND cmake_utils_call) 0038 return() 0039 endif() 0040 0041 include(CMakeVarMacros) 0042 0043 function(__cmake_utils_call_helper func_name var_name) 0044 cmake_utils_get_unique_name( 0045 "___cmake_utils_call_helper_${func_name}" unique_name) 0046 set("${unique_name}" 0 PARENT_SCOPE) 0047 variable_watch("${unique_name}" "${func_name}") 0048 set("${var_name}" "${unique_name}" PARENT_SCOPE) 0049 endfunction() 0050 0051 # cmake_utils_call(function_name) 0052 # @function_name: the name of function or macro to be called. 0053 # 0054 # This macro will call the function or macro by name. The scope of the 0055 # function call is the same with the scope to call this macro therefore 0056 # setting variables in a macro or setting PARENT_SCOPE variables in a 0057 # function WILL work. This version of the function does not support 0058 # passing arbitrary arguments, use #cmake_utils_wrap_call, 0059 # #cmake_utils_call_args or #cmake_utils_call_args_with_var if you 0060 # need to do that. 0061 macro(cmake_utils_call ___func_name) 0062 __cmake_utils_call_helper("${___func_name}" 0063 __cmake_utils_call_watch_var_name_${___func_name}) 0064 set("${__cmake_utils_call_watch_var_name_${___func_name}}") 0065 endmacro() 0066 0067 # cmake_utils_call_with_var(var_names function_name) 0068 # @var_names: the variable names to be propagate to parent scope. 0069 # @function_name: the name of function or macro to be called. 0070 # 0071 # This functionis just like #cmake_utils_call except the macro or function 0072 # will be executed in a separate scope. You can control the allowed 0073 # variables to be passed to the caller scope using @var_names. This function 0074 # doesn't support calling functions or macros with arbitrary number of 0075 # arguments, use #cmake_utils_call_args_with_var if you need to do that. 0076 function(cmake_utils_call_with_var varnames func_name) 0077 cmake_utils_call("${func_name}") 0078 foreach(varname ${varnames}) 0079 set("${varname}" "${${varname}}" PARENT_SCOPE) 0080 endforeach() 0081 endfunction() 0082 0083 # cmake_utils_call_once(function_name) 0084 # @function_name: the name of function or macro to be called. 0085 # 0086 # This macro is just like #cmake_utils_call except it will not 0087 # call the function if it has already be called by this function before. 0088 # This is useful for a one-time global init function of a cmake module 0089 # that might be included more once. 0090 # 0091 # NOTE: This macro does NOT interfere with #cmake_utils_call 0092 # and you will still be able to call the function before or after 0093 # calling this macro using #cmake_utils_call or directly. 0094 macro(cmake_utils_call_once ___func_name) 0095 cmake_utils_check_and_set_bool( 0096 "__cmake_utils_call_once_${___func_name}__" 0097 ___cmake_utils_call_once_already_called_${___func_name}) 0098 if("${___cmake_utils_call_once_already_called_${___func_name}}" STREQUAL 1) 0099 return() 0100 endif() 0101 cmake_utils_call("${___func_name}") 0102 endmacro() 0103 0104 # cmake_utils_set_and_make_dir(dir global_name var_name) 0105 # @dir: directory name 0106 # @global_name: name of global to save "${dir}", 0107 # see #cmake_utils_get_global for more detail. 0108 # @var_name: name of variable to save "${dir}" 0109 # 0110 # This is a helper function for cmake modules that needs working 0111 # directory (typically under #CMAKE_GENERAL_BASE global). This function 0112 # will save "${dir}" into the variable and the global as well as creating 0113 # the directory if it doesn't exist yet. 0114 function(cmake_utils_set_and_make_dir dir global var) 0115 file(MAKE_DIRECTORY "${dir}") 0116 cmake_utils_set_global("${global}" "${dir}") 0117 set("${var}" "${dir}" PARENT_SCOPE) 0118 endfunction() 0119 0120 macro(__cmake_utils_run_hook name isolate reverse) 0121 macro(__cmake_utils_run_hook_single) 0122 foreach(__cmake_utils_hook_${name} ${__cmake_utils_hooks_${name}}) 0123 if("${isolate}") 0124 cmake_utils_call_with_var("" "${__cmake_utils_hook_${name}}") 0125 else() 0126 cmake_utils_call("${__cmake_utils_hook_${name}}") 0127 endif() 0128 endforeach() 0129 endmacro() 0130 foreach("__cmake_utils_hooks_${name}" "") 0131 if(NOT "${reverse}") 0132 cmake_utils_get_global("__cmake_utils_hooks_${name}" 0133 "__cmake_utils_hooks_${name}") 0134 __cmake_utils_run_hook_single() 0135 cmake_utils_get_global("__cmake_utils_hooks_reverse_${name}" 0136 "__cmake_utils_hooks_${name}") 0137 __cmake_utils_run_hook_single() 0138 else() 0139 macro(__cmake_utils_run_hook_single_reverse) 0140 if(NOT "x${__cmake_utils_hooks_${name}}x" STREQUAL xx) 0141 list(REVERSE "__cmake_utils_hooks_${name}") 0142 __cmake_utils_run_hook_single() 0143 endif() 0144 endmacro() 0145 cmake_utils_get_global("__cmake_utils_hooks_reverse_${name}" 0146 "__cmake_utils_hooks_${name}") 0147 __cmake_utils_run_hook_single_reverse() 0148 cmake_utils_get_global("__cmake_utils_hooks_${name}" 0149 "__cmake_utils_hooks_${name}") 0150 __cmake_utils_run_hook_single_reverse() 0151 endif() 0152 endforeach() 0153 endmacro() 0154 0155 function(_cmake_utils_run_hook_isolated name reverse) 0156 __cmake_utils_run_hook("${name}" True "${reverse}") 0157 endfunction() 0158 0159 macro(cmake_utils_run_hook name reverse) 0160 if("${ARGC}" LESS 3 OR NOT "${ARGV2}") 0161 __cmake_utils_run_hook("${name}" False "${reverse}") 0162 elseif("${ARGV2}" STREQUAL 2) 0163 _cmake_utils_run_hook_isolated("${name}" "${reverse}") 0164 else() 0165 __cmake_utils_run_hook("${name}" True "${reverse}") 0166 endif() 0167 endmacro() 0168 0169 function(cmake_utils_reg_hook name func) 0170 if("${ARGC}" LESS "3" OR NOT "${ARGV2}") 0171 cmake_utils_get_global("__cmake_utils_hooks_${name}" hooks) 0172 cmake_utils_set_global("__cmake_utils_hooks_${name}" "${hooks};${func}") 0173 else() 0174 cmake_utils_get_global("__cmake_utils_hooks_reverse_${name}" hooks) 0175 cmake_utils_set_global("__cmake_utils_hooks_reverse_${name}" 0176 "${func};${hooks}") 0177 endif() 0178 endfunction() 0179 0180 function(cmake_utils_config_end_hook func) 0181 cmake_utils_reg_hook("__cmake_utils_end_of_configure_hook" 0182 "${func}" ${ARGN}) 0183 endfunction() 0184 0185 function(___cmake_utils_parent_file_hook var acc value cur_lst stack) 0186 if(NOT "x${value}x" STREQUAL xx) 0187 return() 0188 endif() 0189 cmake_utils_run_hook("__cmake_utils_end_of_configure_hook" False 2) 0190 endfunction() 0191 0192 # CMAKE_GENERAL_BASE 0193 # This global contains the path to a hidden directory the binary directory 0194 # that can be used as a base directory for saving building files. 0195 function(__cmake_base_utils_init) 0196 cmake_utils_set_and_make_dir("${CMAKE_BINARY_DIR}/.cmake_utils_base" 0197 CMAKE_GENERAL_BASE base_dir) 0198 variable_watch(CMAKE_PARENT_LIST_FILE ___cmake_utils_parent_file_hook) 0199 endfunction() 0200 cmake_utils_call_once(__cmake_base_utils_init)