2016-08-01 23:21:34 +00:00
|
|
|
#!/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
|
|
|
|
|
2016-08-02 00:11:05 +00:00
|
|
|
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
|
|
|
|
|
2016-08-01 23:21:34 +00:00
|
|
|
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
|
|
|
|
|
2016-08-02 00:11:05 +00:00
|
|
|
eval $compiler_option cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "$config_option" $@ "$project_path"
|
2016-08-01 23:21:34 +00:00
|
|
|
|
2016-08-02 00:11:05 +00:00
|
|
|
if [ -h "$project_path/$json_file" ]; then
|
2016-08-01 23:21:34 +00:00
|
|
|
unlink "$project_path/$json_file"
|
|
|
|
fi
|
|
|
|
work_dir="$PWD"
|
|
|
|
(cd "$project_path" && ln -s "$work_dir/$json_file")
|