_cmake (9457B)
1 #compdef cmake 2 3 # Description 4 # ----------- 5 # 6 # Completion script for CMake (http://www.cmake.org). 7 # 8 # ------------------------------------------------------------------------- 9 # Authors 10 # ------- 11 # 12 # * Scott M. Kroll <skroll@gmail.com> 13 # 14 # ------------------------------------------------------------------------- 15 # Notes 16 # ----- 17 # 18 # * By default only C and C++ languages are supported for compiler flag 19 # variables. To define your own list of languages: 20 # 21 # cmake_langs=('C' 'C' 22 # 'CXX' 'C++') 23 # zstyle ':completion:*:cmake:*' languages $cmake_langs 24 # 25 # ------------------------------------------------------------------------- 26 27 _cmake() { 28 local context state line curcontext="$curcontext" cmake_args 29 30 local cmake_help_actions;cmake_help_actions=( 31 '(- 1)--help-command[Print help for a single command and exit]:command-name:_cmake_command_names' 32 '(- 1)--help-command-list[List available listfile commands and exit]' 33 '(- 1)--help-commands[Print help for all commands and exit]' 34 '(- 1)--help-compatcommands[Print help for compatibility commands]' 35 '(- 1)--help-module[Print help for compatibility commands]:module-name:_cmake_module_names' 36 '(- 1)--help-module-list[Print help for a single module and exit]' 37 '(- 1)--help-modules[Print help for all modules and exit]' 38 '(- 1)--help-property[List available properties and exit]:property-name:_cmake_property_names' 39 '(- 1)--help-property-list[List available properties and exit]' 40 '(- 1)--help-properties[Print help for all properties and exit]' 41 '(- 1)--help-variable[Print help for a single variable and exit]:variable-name:_cmake_variable_names' 42 '(- 1)--help-variable-list[List documented variables and exit]' 43 '(- 1)--help-variables[Print help for all variables and exit]' 44 '(- 1)--copyright[Print the CMake copyright and exit]' 45 '(- 1)'{--help,-help,-usage,-h,-H}'[Print usage information and exit]' 46 '(- 1)--help-full[Print full help and exit]' 47 '(- 1)--help-html[Print full help in HTML format]' 48 '(- 1)--help-man[Print full help as a UNIX man page and exit]' 49 '(- 1)'{--version,-version}'[Print full help as a UNIX man page and exit]' 50 ) 51 52 local cmake_build_options;cmake_build_options=( 53 '-C[Pre-load a script to populate the cache]:script:_files' 54 '*-D-[Create a cmake cache entry]:property:_cmake_define_property' 55 '-U[Remove matching entries from CMake cache]:globbing expression' 56 '-G[Specify a makefile generator]:generator:_cmake_generators' 57 '-T[Specify toolset name if supported by generator]:toolset name' 58 '(-Wno-dev -Wdev)-Wno-dev[Suppress developer warnings]' 59 '(-Wno-dev -Wdev)-Wdev[Enable developer warnings]' 60 '-i[Run in wizard mode]' 61 '-L-[List cache variables]::_values "options" "[non-advanced cache variables]" "A[advanced cache variables]" "H[non-advanced cached variables with help]" "AH[advanced cache variables with help]"' 62 '--trace[Put cmake in trace mode]' 63 ':cmake project:_files -/' 64 ) 65 66 local cmake_command_actions;cmake_command_actions=( 67 '-E[CMake command mode]:*:command' 68 ) 69 70 _arguments -C -s \ 71 - help \ 72 "$cmake_help_actions[@]" \ 73 - command \ 74 "$cmake_command_actions[@]" \ 75 - build_opts \ 76 "$cmake_build_options[@]" && return 0 77 } 78 79 # ------------------- 80 # _cmake_command_names 81 # ------------------- 82 (( $+functions[_cmake_command_names] )) || 83 _cmake_command_names() { 84 local command_names; command_names=(${(f)"$($service --help-command-list 2> /dev/null)"}) 85 _values 'command name' ${command_names[@]:1} && return 0 86 } 87 88 # ----------------- 89 # _cmake_list_names 90 # ----------------- 91 (( $+functions[_cmake_list_names] )) || 92 _cmake_list_names() { 93 local command; command="$@[1]" 94 local desc; desc="$@[2]" 95 local list_names; list_names=(${(f)"$($service $command 2> /dev/null | sed -e 's/\[/\\\[/' -e 's/\]/\\\]/')"}) 96 97 _values ${desc} ${list_names[@]:1} && return 0 98 } 99 100 # ------------------ 101 # _cmake_module_names 102 # ------------------ 103 (( $+functions[_cmake_module_names] )) || 104 _cmake_module_names() { 105 _cmake_list_names '--help-module-list' 'module name' && return 0 106 } 107 108 # -------------------- 109 # _cmake_property_names 110 # -------------------- 111 (( $+functions[_cmake_property_names] )) || 112 _cmake_property_names() { 113 _cmake_list_names '--help-property-list' 'property name' && return 0 114 } 115 116 # --------------------- 117 # _cmake_variable_names 118 # --------------------- 119 (( $+functions[_cmake_variable_names] )) || 120 _cmake_variable_names() { 121 _cmake_list_names '--help-variable-list' 'variable name' && return 0 122 } 123 124 # ---------------------- 125 # _cmake_define_property 126 # ---------------------- 127 (( $+functions[_cmake_define_property] )) || 128 _cmake_define_property() { 129 if compset -P '*='; then 130 _wanted property-values expl 'property value' _cmake_define_property_values ${${IPREFIX%=}#-D} && return 0 131 else 132 _wanted property-names expl 'property name' _cmake_define_property_names -qS= && return 0 133 fi 134 } 135 136 # ---------------------------- 137 # _cmake_define_property_names 138 # ---------------------------- 139 (( $+functions[_cmake_define_property_names] )) || 140 _cmake_define_property_names() { 141 local alternatives; alternatives=( 142 'common-property-names:common property name:_cmake_define_common_property_names -qS=' 143 ) 144 local -A cmake_langs 145 zstyle -a ":completion:${curcontext}:" languages cmake_langs 146 [[ $#cmake_langs -eq 0 ]] && cmake_langs=('C' 'C' 'CXX' 'C++') 147 148 for cmake_lang in ${(k)cmake_langs}; do 149 cmake_lang_desc="${cmake_langs[$cmake_lang]}" 150 alternatives+=("${cmake_lang//:/-}-property-names:${cmake_lang_desc} language property name:_cmake_define_lang_property_names -qS= ${cmake_lang} ${cmake_lang_desc}") 151 done 152 153 _alternative "${alternatives[@]}" 154 } 155 156 # --------------------------------- 157 # _cmake_define_lang_property_names 158 # --------------------------------- 159 (( $+functions[_cmake_define_lang_property_names] )) || 160 _cmake_define_lang_property_names() { 161 local cmake_lang="$@[-2]" cmake_lang_desc="$@[-1]" 162 local properties; properties=( 163 "CMAKE_${cmake_lang}_COMPILER:${cmake_lang_desc} compiler" 164 "CMAKE_${cmake_lang}_FLAGS:${cmake_lang_desc} compiler flags for all builds" 165 "CMAKE_${cmake_lang}_FLAGS_DEBUG:${cmake_lang_desc} compiler flags for all Debug build" 166 "CMAKE_${cmake_lang}_FLAGS_RLEASE:${cmake_lang_desc} compiler flags for all Relase build" 167 "CMAKE_${cmake_lang}_FLAGS_MINSIZREL:${cmake_lang_desc} compiler flags for all MinSizRel build" 168 "CMAKE_${cmake_lang}_FLAGS_RELWITHDEBINFO:${cmake_lang_desc} compiler flags for all RelWithDebInfo build" 169 ) 170 171 _describe -t "${cmake_lang//:/-}-property-names" "${cmake_lang_desc} property name" properties $@[0,-3] && return 0 172 } 173 174 # ----------------------------------- 175 # _cmake_define_common_property_names 176 # ----------------------------------- 177 (( $+functions[_cmake_define_common_property_names] )) || 178 _cmake_define_common_property_names() { 179 local properties; properties=( 180 'CMAKE_BUILD_TYPE:Specifies the build type for make based generators' 181 'CMAKE_TOOLCHAIN_FILE:Absolute or relative path to a cmake script which sets up toolchain related variables' 182 'CMAKE_COLOR_MAKEFILE:Enables/disables color output when using the Makefile generator' 183 'CMAKE_INSTALL_PREFIX:Install directory used by install' 184 ) 185 186 _describe -t 'common-property-names' 'common property name' properties $@ 187 } 188 189 # ---------------------------- 190 # _cmake_define_property_values 191 # ---------------------------- 192 (( $+functions[_cmake_define_property_values] )) || 193 _cmake_define_property_values() { 194 local ret=1 195 setopt localoptions extendedglob 196 case $@[-1] in 197 (CMAKE_BUILD_TYPE) _wanted build-types expl 'build type' _cmake_build_types && ret=0;; 198 (CMAKE_TOOLCHAIN_FILE) _wanted toolchain-files expl 'file' _cmake_toolchain_files && ret=0;; 199 (CMAKE_COLOR_MAKEFILE) _wanted booleans expl 'boolean' _cmake_booleans && ret=0;; 200 (CMAKE_INSTALL_PREFIX) _files -/ && ret=0;; 201 (CMAKE_*_COMPILER) _wanted compilers expl 'compiler' _cmake_compilers && ret=0;; 202 (CMAKE_*_FLAGS(|_?*)) _message -e compiler-flags 'compiler flags' && ret=0;; 203 (*) _files && ret=0;; 204 esac 205 206 return ret 207 } 208 209 # ------------------ 210 # _cmake_build_types 211 # ------------------ 212 (( $+functions[_cmake_build_types] )) || 213 _cmake_build_types() { 214 local build_types; build_types=( 215 'Debug' 216 'Release' 217 'RelWithDebInfo' 218 'MinSizeRel' 219 ) 220 _values 'build type' ${build_types[@]} 221 } 222 223 # ----------------- 224 # _cmake_generators 225 # ----------------- 226 (( $+functions[_cmake_generators] )) || 227 _cmake_generators() { 228 local generators; generators=( 229 'Unix Makefiles' 230 'Ninja' 231 'CodeBlocks - Ninja' 232 'CodeBlocks - Unix Makefiles' 233 'Eclipse CDT4 - Ninja' 234 'Eclipse CDT4 - Unix Makefiles' 235 'KDevelop3' 236 'KDevelop3 - Unix Makefiles' 237 'Sublime Text 2 - Ninja' 238 'Sublime Text 2 - Unix Makefiles' 239 ) 240 241 _describe -t generators 'generator' generators 242 } 243 244 # ---------------------- 245 # _cmake_toolchain_files 246 # ---------------------- 247 (( $+functions[_cmake_toolchain_files] )) || 248 _cmake_toolchain_files() { 249 _files -g '*\.cmake*' 250 } 251 252 # --------------- 253 # _cmake_booleans 254 # --------------- 255 (( $+functions[_cmake_booleans] )) || 256 _cmake_booleans() { 257 local booleans; booleans=( 258 'YES' 259 'NO' 260 ) 261 _describe -t booleans 'boolean' booleans 262 } 263 264 # --------------- 265 # _cmake_compilers 266 # --------------- 267 (( $+functions[_cmake_compilers] )) || 268 _cmake_compilers() { 269 _command_names -e 270 } 271 272 273 _cmake "$@" 274