- directory discovery originally designed for a sub-dir location (eg, etc/openfoam) but failed if called from within the sub-dir itself. Now simply assume it is located in the project directory or the etc/ sub-dir, so that it can also be relocated into the project directory in the future (pending changes to RPM and debian packaging)
153 lines
3.5 KiB
Bash
Executable File
153 lines
3.5 KiB
Bash
Executable File
#!/bin/sh
|
|
#------------------------------------------------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | www.openfoam.com
|
|
# \\/ M anipulation |
|
|
#------------------------------------------------------------------------------
|
|
# Copyright (C) 2020-2023 OpenCFD Ltd.
|
|
#------------------------------------------------------------------------------
|
|
# License
|
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
|
#
|
|
# Script
|
|
# bin/tools/vscode-settings
|
|
#
|
|
# Description
|
|
# Emit some settings for Visual Studio Code + OpenFOAM
|
|
#
|
|
# Example
|
|
# bin/tools/vscode-settings > .vscode/settings.json
|
|
# openfoam -spdp -int64 bin/tools/vscode-settings
|
|
#
|
|
# Environment
|
|
# WM_PROJECT_DIR, WM_PROJECT_USER_DIR, WM_OPTIONS
|
|
#
|
|
# More information:
|
|
# https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code
|
|
#
|
|
#------------------------------------------------------------------------------
|
|
# Values consistent with wmake-with-bear
|
|
cacheDirName="build/$WM_OPTIONS"
|
|
|
|
printHelp() {
|
|
cat<<USAGE
|
|
|
|
Usage: ${0##*/} [OPTIONS]
|
|
|
|
options:
|
|
-help Print the usage
|
|
|
|
Emit some settings for Visual Studio Code + OpenFOAM
|
|
|
|
For example,
|
|
bin/tools/vscode-settings > .vscode/settings.json
|
|
openfoam -spdp -int64 bin/tools/vscode-settings
|
|
|
|
USAGE
|
|
exit 0 # clean exit
|
|
}
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
unset outputDir
|
|
|
|
# Parse options
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
case "$1" in
|
|
-h | -help*)
|
|
printHelp
|
|
;;
|
|
*)
|
|
echo "Unknown option/argument: '$1'" 1>&2
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Report settings and flag errors
|
|
projectDir="$WM_PROJECT_DIR"
|
|
session="$projectDir"/etc/openfoam
|
|
|
|
echo "project: ${WM_PROJECT_DIR:?OpenFOAM environment not set?}" 1>&2
|
|
echo "options: ${WM_OPTIONS:?not set}" 1>&2
|
|
if [ -x "$session" ]
|
|
then
|
|
echo "session: $session" 1>&2
|
|
elif [ -x "$projectDir"/openfoam ]
|
|
then
|
|
session="$projectDir"/openfoam
|
|
echo "session: $session" 1>&2
|
|
else
|
|
echo "No session: $session" 1>&2
|
|
fi
|
|
|
|
if [ -z "$outputDir" ]
|
|
then
|
|
prefixDir="$projectDir"
|
|
if ! [ -w "$prefixDir" ]
|
|
then
|
|
echo "Non-writable directory: $prefixDir" 1>&2
|
|
echo "Try with user location" 1>&2
|
|
prefixDir="$WM_PROJECT_USER_DIR"
|
|
|
|
if ! [ -w "$prefixDir" ]
|
|
then
|
|
echo "Non-writable directory: $prefixDir" 1>&2
|
|
echo "Using home directory" 1>&2
|
|
prefixDir="$HOME"
|
|
fi
|
|
fi
|
|
outputDir="$prefixDir/$cacheDirName"
|
|
fi
|
|
|
|
|
|
## echo "Output = $outputDir" 1>&2
|
|
|
|
# JSON output. Long entries are outdented.
|
|
cat << INFO 1>&2
|
|
# -------------------------
|
|
# Some settings for Visual Studio Code + OpenFOAM
|
|
# -------------------------
|
|
INFO
|
|
|
|
echo '{' # BEGIN_LIST
|
|
|
|
# ccls integration
|
|
cat << JSON_CONTENT
|
|
"ccls.cache.directory":
|
|
"$outputDir/ccls-cache",
|
|
|
|
"ccls.misc.compilationDatabaseDirectory":
|
|
"$outputDir",
|
|
|
|
JSON_CONTENT
|
|
|
|
|
|
# Compilation via openfoam session
|
|
if [ -x "$session" ]
|
|
then
|
|
cat << JSON_CONTENT
|
|
"C_Cpp.default.compileCommands":
|
|
"$session wmake -with-bear -s -j",
|
|
JSON_CONTENT
|
|
fi
|
|
|
|
cat << JSON_CONTENT
|
|
|
|
"C_Cpp.autocomplete": "Disabled",
|
|
"C_Cpp.errorSquiggles": "Disabled",
|
|
"C_Cpp.formatting": "Disabled",
|
|
"C_Cpp.intelliSenseEngine": "Disabled"
|
|
JSON_CONTENT
|
|
|
|
echo '}' # END_LIST
|
|
|
|
#------------------------------------------------------------------------------
|