Simplify cmake targets

- Don't use for loop
- Use reduce filtering commands
This commit is contained in:
Shohei YOSHIDA 2026-03-14 20:27:54 +09:00
parent 9240b691d0
commit 309d615eb5
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 7 additions and 16 deletions

View File

@ -165,25 +165,16 @@ _cmake_presets() {
# -------------- # --------------
(( $+functions[_cmake_targets] )) || (( $+functions[_cmake_targets] )) ||
_cmake_targets() { _cmake_targets() {
local -a targets local dir="$1"
local i local -a targets=()
if [ -f $1/Makefile ] if [[ -f "${dir}/Makefile" ]]; then
then
# `make help` doesn't work for Makefiles in general, but for CMake generated Makefiles it does. # `make help` doesn't work for Makefiles in general, but for CMake generated Makefiles it does.
i=1 targets=(${(f)"$(make -f $dir/Makefile help | awk '/^\.\.\./ { print $2 }')"})
for target in $(make -f $1/Makefile help | \grep -e "\.\.\." | sed "s/\.\.\. //" | sed "s/ (the default.*//") ; do elif [[ -f "${dir}/build.ninja" ]]; then
targets[$i]=$target
(( i = $i + 1 ))
done
elif [ -f $1/build.ninja ]
then
# `ninja help` doesn't seem to be the list of targets we're interested in # `ninja help` doesn't seem to be the list of targets we're interested in
i=1 targets=(${(f)"$(ninja -C $dir -t targets all 2>/dev/null | awk -F: '{print $1}' )"})
for target in $(ninja -C $1 -t targets all 2&>/dev/null | awk -F: '{print $1}') ; do
targets[$i]="$target"
(( i++ ))
done
fi fi
_describe 'build targets' targets _describe 'build targets' targets
} }