mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-12-02 02:05:41 +00:00
King_DuckZ
08a6c0d73d
For example if you run the script from dindexer/clang_debug you will tell cmake to make a debug build using clang. You can also use gcc_debug but there is no way to specify a particular version.
52 lines
1.3 KiB
Bash
Executable file
52 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
code_dirs[0]="$HOME/dev/code/cpp"
|
|
code_dirs[1]="$HOME/dev/code"
|
|
|
|
build_dir="$HOME/dev/build"
|
|
|
|
json_file="compile_commands.json"
|
|
|
|
project_name=$(pwd | sed -r "s_$build_dir/([^/]+).*\$_\1_")
|
|
project_path=""
|
|
for z in "${code_dirs[@]}"
|
|
do
|
|
if [ -d "$z/$project_name" ]; then
|
|
project_path="$z/$project_name"
|
|
break;
|
|
fi
|
|
done
|
|
|
|
if [ -z "$project_path" ]; then
|
|
>&2 echo "Project \"$project_name\" not found in any of the search paths"
|
|
exit 1
|
|
fi
|
|
|
|
config_name=$(pwd | sed -r "s@$build_dir/$project_name/([^/_]+_)?([^/]+).*\$@\2@")
|
|
compiler_name=$(pwd | sed -r "s@$build_dir/$project_name/([^/_]+_)?([^/]+).*\$@\1@")
|
|
compiler_option=""
|
|
if [ -n "$compiler_name" ]; then
|
|
compiler_name="${compiler_name%?}"
|
|
case "$compiler_name" in
|
|
"clang")
|
|
compiler_option="CXX=clang++ CC=clang"
|
|
;;
|
|
"gcc")
|
|
compiler_option="CXX=g++ CC=gcc"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
config_option=""
|
|
if [ -n "$config_name" ]; then
|
|
config_name="$(tr '[:lower:]' '[:upper:]' <<< ${config_name:0:1})${config_name:1}"
|
|
config_option="-DCMAKE_BUILD_TYPE=$config_name"
|
|
fi
|
|
|
|
eval $compiler_option cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "$config_option" $@ "$project_path"
|
|
|
|
if [ -h "$project_path/$json_file" ]; then
|
|
unlink "$project_path/$json_file"
|
|
fi
|
|
work_dir="$PWD"
|
|
(cd "$project_path" && ln -s "$work_dir/$json_file")
|