删除冗余代码;添加occ脚本

This commit is contained in:
Zhuo Yang 2022-08-29 00:10:53 +08:00
parent b577883841
commit cca0de5e85
6 changed files with 23 additions and 65 deletions

View File

@ -1,4 +1,5 @@
# of_cmake_config
[中文](README.md) | [英文](README.en.md)
#### Description
This project is used to generate CMakeLists.txt for OpenFOAM project.
@ -13,4 +14,8 @@ This project is used to generate CMakeLists.txt for OpenFOAM project.
#### Instructions
1. Activate OpenFOAM environment
2. In project root path, run `ofCmakeConfig`
2. In project root path,
- run `ofCmakeConfig` to generate `CMakeLists.txt`
- or run `occ`, which is a wrapper of `ofCmakeConfig` script, to generate `CMakeLists.txt` and `compile_commands.json`.
[video demo](demo/occ_demo.mp4)

View File

@ -1,4 +1,5 @@
# of_cmake_config
[中文](README.md) | [英文](README.en.md)
#### 介绍
本项目用于生成OpenFOAM项目的CMakeLists.txt
@ -13,4 +14,13 @@
#### 使用说明
0. 激活OpenFOAM环境
1. 在项目根目录下, 运行 `ofCmakeConfig`
1. 在项目根目录下,
- 运行 `ofCmakeConfig`,生成`CMakeLists.txt`
- 或运行`occ`,其包装了`ofCmakeConfig`,除了生成`CMakeLists.txt`还会调用cmake生成`compile_commands.json`。
#### 测试环境
- `vscode` + `clangd`
- `vim` + `coc-clangd`
[视频演示](demo/occ_demo.mp4)

BIN
demo/occ_demo.mp4 Normal file

Binary file not shown.

View File

@ -5,8 +5,9 @@ if [ -d $objDir ]
then
cwd=`pwd`
chmod +x ./ofCmakeConfig
rm -f $objDir/ofCmakeConfig
rm -f $objDir/ofCmakeConfig $objDir/occ
ln -s $cwd/ofCmakeConfig $objDir/
ln -s $cwd/occ $objDir/
echo "installed ofCmakeConfig"
else
echo "please active OpenFOAM environment"

4
occ Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
ofCmakeConfig
rm -r build && mkdir build
cmake -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .

View File

@ -3,12 +3,6 @@ Script="${0##*/}" # Need 'Script' for wmakeFunctions messages
scriptsDir="${0%/*}"/scripts # wmake/scripts directory
. "$scriptsDir"/wmakeFunctions # Source wmake functions
# TODO: 检查当前路径是否是CMAKE_SOURCE_DIR
# 其中包含.vscode, CMakeLists.txt
# ...
# TODO: 根据OF环境变量设置安装目录
printInfo() {
if [ -f "$WM_DIR"/makefiles/info ]
@ -40,8 +34,6 @@ link_flags_extra="-Xlinker $link_flags_extra"
OF_compile_flags=`printInfo "cxxflags"`
OF_compile_flags="$OF_compile_flags -iquote."
OF_link_flags="$OF_compile_flags $link_flags_extra"
# echo OF_compile_flags: $OF_compile_flags
# echo OF_link_flags: $OF_link_flags
OF_project_name=`cat Make/files | grep EXE | grep -oP '(?<=/).*$'`
OF_typestr="add_executable"
@ -51,10 +43,7 @@ then
OF_typestr="add_library"
fi
# echo OF_testCaseDir: '${CMAKE_SORCE_DIR}/testCase'
OF_sources=`cat Make/files | grep -oP '.*\.C'`
# echo OF_sources: $OF_sources
# update OF_typestr
if [ $OF_typestr = "add_executable" ]
then
OF_typestr="$OF_typestr(\${project_name} \${OF_sources})"
@ -79,57 +68,6 @@ OF_includeDir=`echo $OF_includeDir | sed 's/ /\n/g'`
OF_linkLib=`echo $s | sed 's/ /\n/g' | grep -E '^-l' | sort | uniq |grep -oP '(?<=-l).*'`
OF_linkDir=$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib
OF_linkDir=`echo "$OF_linkDir $FOAM_USER_LIBBIN" | sed 's/ /\n/g'`
# echo OF_linkLib: $OF_linkLib
# echo OF_linkDir: $OF_linkDir
# 写入文件 .vscode/of-gdb.sh
mkdir -p .vscode
cat > .vscode/of-gdb.sh <<EOF
#!/bin/bash
source $FOAM_ETC/bashrc WM_MPLIB=$WM_MPLIB WM_COMPILE_OPTION=$WM_COMPILE_OPTION WM_COMPILER=$WM_COMPILER
/usr/bin/gdb "\$@"
EOF
# 写入文件 .vscode/launch.json
cat > .vscode/launch.json << EOF
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "\${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": true,
"cwd": "\${workspaceFolder}/testCase",
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "\${env:PATH}:\${command:cmake.getLaunchTargetDirectory}"
},
{
"name": "OTHER_VALUE",
"value": "Something something"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "\${workspaceFolder}/.vscode/of-gdb.sh",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
EOF
chmod +x .vscode/of-gdb.sh
# 写入文件 CMakeLists.txt
cat > CMakeLists.txt <<EOF