基础版

This commit is contained in:
Zhuo Yang 2022-04-11 14:44:18 +08:00
parent ac770ebb49
commit 37b29fd98a
5 changed files with 191 additions and 56 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
testSolver

View File

@ -1,36 +1,16 @@
# of_cmake_config
#### Description
本项目用于生成OpenFOAM项目的CMakeLists.txt
#### Software Architecture
Software architecture description
This project is used to generate CMakeLists.txt for OpenFOAM project.
#### Installation
1. xxxx
2. xxxx
3. xxxx
0. Activate OpenFOAM environment:
- Using alias `of2012clang` or `of2012clangdebug`
- source directly: `source $HOME/OpenFOAM/OpenFOAM-v2012/etc/bashrc WM_COMPILER=Clang ...`
1. Get this project: `git clone https://gitee.com/xfygogo/of_cmake_config.git of_cmake_config`
2. Install: `cd of_cmake_config && ./install`
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
1. Activate OpenFOAM environment
2. In project root path, run `ofCmakeConfig`

View File

@ -3,35 +3,14 @@
#### 介绍
本项目用于生成OpenFOAM项目的CMakeLists.txt
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
0. 激活OpenFOAM环境:
- 使用别名 `of2012clang` or `of2012clangdebug`
- 直接source: `source $HOME/OpenFOAM/OpenFOAM-v2012/etc/bashrc WM_COMPILER=Clang ...`
1. 获取该项目源码:`git clone https://gitee.com/xfygogo/of_cmake_config.git of_cmake_config`
2. 安装:`cd of_cmake_config && ./install`
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
0. 激活OpenFOAM环境
1. 在项目根目录下, 运行 `ofCmakeConfig`

13
install Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
objDir=$WM_PROJECT_DIR/wmake
if [ -d $objDir ]
then
cwd=`pwd`
chmod +x ./ofCmakeConfig
rm -f $objDir/ofCmakeConfig
ln -s $cwd/ofCmakeConfig $objDir/
echo "installed ofCmakeConfig"
else
echo "please active OpenFOAM environment"
fi

162
ofCmakeConfig Executable file
View File

@ -0,0 +1,162 @@
#!/bin/bash
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 ]
then
make --no-print-directory -f "$WM_DIR"/makefiles/info "$@"
else
echo "OpenFOAM environment not set?" 1>&2
return 1
fi
}
if [ -z "$objectsDir" ]
then
objectsDir="$MakeDir/$WM_OPTIONS"
fi
mkdir -p "$objectsDir"
make -s -f "$WM_DIR"/makefiles/files MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" "$objectsDir"/options
make -s -f "$WM_DIR"/makefiles/files MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir"
s=`make --dry-run -f "$WM_DIR"/makefiles/general MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" $targetType`
link_flags_extra=`echo $s | grep -oP '(?<=Xlinker).*(?=Make)'`
link_flags_extra="-Xlinker $link_flags_extra"
OF_compile_flags=`printInfo "cxxflags"`
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 -oP '(?<=/).*$'`
# echo OF_testCaseDir: '${CMAKE_SORCE_DIR}/testCase'
OF_sources=`cat Make/files | grep -oP '.*.C'`
# echo OF_sources: $OF_sources
str_inc=`echo $s | sed 's/ /\n/g' | grep -E '^-I' | sort | uniq |grep -oP '(?<=-I).*'`
OF_includeDir=${str_inc/%lnInclude/}
# echo OF_includeDir: $OF_includeDir
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
# 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
cmake_minimum_required(VERSION 3.12)
#=== OF related variables ===
set(project_name $OF_project_name)
set(WM_COMPILE_OPTION $WM_COMPILE_OPTION)
set(OF_compile_flags "$OF_compile_flags")
set(OF_link_flags "$OF_link_flags")
set(OF_testCaseDir \${CMAKE_SOURCE_DIR}/testCase)
set(OF_sources
$OF_sources
)
set(OF_includeDir
$OF_includeDir
)
set(OF_linkLib
$OF_linkLib
)
set(OF_linkDir
$OF_linkDir
)
#=== End ===
project(\${project_name} LANGUAGES CXX C)
set(ENV{LD_LIBRARY_PATH} "\$ENV{LD_LIBRARY_PATH}:\${OF_linkDir}")
if(\${WM_COMPILE_OPTION} STREQUAL "Opt")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release mode" FORCE)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED)
link_directories(
\${OF_linkDir}
)
include_directories(
\${OF_includeDir}
\${CMAKE_SOURCE_DIR}/lnInclude
\${CMAKE_SOURCE_DIR}
)
add_executable(\${project_name}
\${OF_sources}
)
target_link_libraries(
\${project_name}
PRIVATE
\${OF_linkLib}
)
set_target_properties( \${project_name} PROPERTIES
COMPILE_FLAGS \${OF_compile_flags}
LINK_FLAGS \${OF_link_flags}
WORKING_DIRECTORY \${OF_testCaseDir})
EOF