未验证 提交 f539434c 编写于 作者: A Austin 提交者: Gitee

update zh-cn/device-dev/porting/porting-thirdparty-cmake.md.

Signed-off-by: NAustin23 <liaozhiqi7@huawei.com>
上级 882d64ac
...@@ -123,52 +123,52 @@ CMake方式可通过指定工具链进行交叉编译,修改并编译该库, ...@@ -123,52 +123,52 @@ CMake方式可通过指定工具链进行交叉编译,修改并编译该库,
- 挂载成功后执行下列命令可列出用例所有条目: - 挂载成功后执行下列命令可列出用例所有条目:
``` ```
cd nfs cd nfs
./cctest --list ./cctest --list
``` ```
上述命令执行结果部分展示:
上述命令执行结果部分展示:
``` ```
test-bignum/Assign< test-bignum/Assign<
test-bignum/ShiftLeft< test-bignum/ShiftLeft<
test-bignum/AddUInt64< test-bignum/AddUInt64<
test-bignum/AddBignum< test-bignum/AddBignum<
test-bignum/SubtractBignum< test-bignum/SubtractBignum<
test-bignum/MultiplyUInt32< test-bignum/MultiplyUInt32<
test-bignum/MultiplyUInt64< test-bignum/MultiplyUInt64<
test-bignum/MultiplyPowerOfTen< test-bignum/MultiplyPowerOfTen<
test-bignum/DivideModuloIntBignum< test-bignum/DivideModuloIntBignum<
test-bignum/Compare< test-bignum/Compare<
test-bignum/PlusCompare< test-bignum/PlusCompare<
test-bignum/Square< test-bignum/Square<
test-bignum/AssignPowerUInt16< test-bignum/AssignPowerUInt16<
test-bignum-dtoa/BignumDtoaVariousDoubles< test-bignum-dtoa/BignumDtoaVariousDoubles<
test-bignum-dtoa/BignumDtoaShortestVariousFloats< test-bignum-dtoa/BignumDtoaShortestVariousFloats<
test-bignum-dtoa/BignumDtoaGayShortest< test-bignum-dtoa/BignumDtoaGayShortest<
test-bignum-dtoa/BignumDtoaGayShortestSingle< test-bignum-dtoa/BignumDtoaGayShortestSingle<
test-bignum-dtoa/BignumDtoaGayFixed< test-bignum-dtoa/BignumDtoaGayFixed<
test-bignum-dtoa/BignumDtoaGayPrecision< test-bignum-dtoa/BignumDtoaGayPrecision<
test-conversions/DoubleToShortest< test-conversions/DoubleToShortest<
test-conversions/DoubleToShortestSingle< test-conversions/DoubleToShortestSingle<
... ...
``` ```
- 以test-bignum条目为例,执行下列命令开始测试: - 以test-bignum条目为例,执行下列命令开始测试:
``` ```
./cctest test-bignum ./cctest test-bignum
``` ```
测试结果如下则表示通过: 测试结果如下则表示通过:
``` ```
Ran 13 tests. Ran 13 tests.
``` ```
## 将该库编译添加到OpenHarmony工程中 ## 将该库编译添加到OpenHarmony工程中
...@@ -189,103 +189,103 @@ CMake方式可通过指定工具链进行交叉编译,修改并编译该库, ...@@ -189,103 +189,103 @@ CMake方式可通过指定工具链进行交叉编译,修改并编译该库,
- **新增的BUILD.gn文件实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony平台时只需修改路径即可** - **新增的BUILD.gn文件实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony平台时只需修改路径即可**
``` ```
import("config.gni") import("config.gni")
group("double-conversion") { group("double-conversion") {
if (ohos_build_thirdparty_migrated_from_fuchisa == true) { if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
deps = [":make"] deps = [":make"]
} }
} }
if (ohos_build_thirdparty_migrated_from_fuchisa == true) { if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
action("make") { action("make") {
script = "//third_party/double-conversion/build_thirdparty.py" script = "//third_party/double-conversion/build_thirdparty.py"
outputs = ["$root_out_dir/log_dc.txt"] outputs = ["$root_out_dir/log_dc.txt"]
exec_path = rebase_path(rebase_path("./build", ohos_third_party_dir)) exec_path = rebase_path(rebase_path("./build", ohos_third_party_dir))
command = "rm * .* -rf && $CMAKE_TOOLS_PATH/cmake .. $CMAKE_FLAG $CMAKE_TOOLCHAIN_FLAG && make -j" command = "rm * .* -rf && $CMAKE_TOOLS_PATH/cmake .. $CMAKE_FLAG $CMAKE_TOOLCHAIN_FLAG && make -j"
args = [ args = [
"--path=$exec_path", "--path=$exec_path",
"--command=${command}" "--command=${command}"
] ]
} }
} }
``` ```
- **新增的config.gni用于配置该库,实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时只需修改CMAKE_FLAG的配置即可。** - **新增的config.gni用于配置该库,实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时只需修改CMAKE_FLAG的配置即可。**
``` ```
#CMAKE_FLAG: config compile feature #CMAKE_FLAG: config compile feature
CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11" CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11"
#toolchain:follow up-layer,depend on $ohos_build_compiler #toolchain:follow up-layer,depend on $ohos_build_compiler
if (ohos_build_compiler == "clang") { if (ohos_build_compiler == "clang") {
CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/" CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/"
} else { } else {
CMAKE_TOOLCHAIN_FLAG = "" CMAKE_TOOLCHAIN_FLAG = ""
} }
#CMake tools path,no need setting if this path already joined to $PATH. #CMake tools path,no need setting if this path already joined to $PATH.
CMAKE_TOOLS_PATH = "setting CMake tools path..." CMAKE_TOOLS_PATH = "setting CMake tools path..."
``` ```
- **新增的build_thirdparty.py实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时无需修改即可使用。** - **新增的build_thirdparty.py实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时无需修改即可使用。**
``` ```
import os import os
import sys import sys
from subprocess import Popen from subprocess import Popen
import argparse import argparse
import shlex import shlex
def cmd_exec(command): def cmd_exec(command):
cmd = shlex.split(command) cmd = shlex.split(command)
proc = Popen(cmd) proc = Popen(cmd)
proc.wait() proc.wait()
ret_code = proc.returncode ret_code = proc.returncode
if ret_code != 0: if ret_code != 0:
raise Exception("{} failed, return code is {}".format(cmd, ret_code)) raise Exception("{} failed, return code is {}".format(cmd, ret_code))
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--path', help='Build path.') parser.add_argument('--path', help='Build path.')
parser.add_argument('--command', help='Build command.') parser.add_argument('--command', help='Build command.')
parser.add_argument('--enable', help='enable python.', nargs='*') parser.add_argument('--enable', help='enable python.', nargs='*')
args = parser.parse_args() args = parser.parse_args()
if args.enable: if args.enable:
if args.enable[0] == 'false': if args.enable[0] == 'false':
return return
if args.path: if args.path:
curr_dir = os.getcwd() curr_dir = os.getcwd()
os.chdir(args.path) os.chdir(args.path)
if args.command: if args.command:
if '&&' in args.command: if '&&' in args.command:
command = args.command.split('&&') command = args.command.split('&&')
for data in command: for data in command:
cmd_exec(data) cmd_exec(data)
else: else:
cmd_exec(args.command) cmd_exec(args.command)
os.chdir(curr_dir) os.chdir(curr_dir)
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
``` ```
- 在配置文件中添加开关控制该库编译,默认设为关闭 - 在配置文件中添加开关控制该库编译,默认设为关闭
在//build/lite/ohos_var.gni文件中添加下列配置: 在//build/lite/ohos_var.gni文件中添加下列配置:
``` ```
declare_args() { declare_args() {
ohos_build_thirdparty_migrated_from_fuchisa = true ohos_build_thirdparty_migrated_from_fuchisa = true
} }
``` ```
3. 编译构建 3. 编译构建
- 手动单独构建: 手动单独构建:
执行下列命令 执行下列命令
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册