diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e10371 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +testSolver \ No newline at end of file diff --git a/README.en.md b/README.en.md index 9336c9b..206895f 100644 --- a/README.en.md +++ b/README.en.md @@ -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` diff --git a/README.md b/README.md index ec79233..31cb8a0 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/install b/install new file mode 100755 index 0000000..0521094 --- /dev/null +++ b/install @@ -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 \ No newline at end of file diff --git a/ofCmakeConfig b/ofCmakeConfig new file mode 100755 index 0000000..e34f9d3 --- /dev/null +++ b/ofCmakeConfig @@ -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 < .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 <