2020-09-06 16:17:16 +08:00
|
|
|
|
# 利用 app_helper 编写 SConstruct
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
编写 SConstruct 是一件繁琐的事情。我们把一些公共的功能,提取到 app\_helper 中,让 SConstruct 稍微简化一点:
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
## 一、示例
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import os
|
|
|
|
|
import scripts.app_helper as app
|
|
|
|
|
|
|
|
|
|
helper = app.Helper(ARGUMENTS);
|
|
|
|
|
helper.add_libs(['sqlite3']).add_cpppath([os.path.join(helper.APP_ROOT, '3rd')]).call(DefaultEnvironment)
|
|
|
|
|
|
|
|
|
|
SConscript(['src/SConscript', '3rd/sqlite3/SConscript'])
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 二、helper API 介绍
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* use\_std\_cxx 指定 C++ 编译器的版本。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.use_std_cxx(17)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* add\_deps 增加依赖的第三方库
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
DEPENDS_LIBS = [
|
|
|
|
|
{
|
|
|
|
|
"root" : '../awtk-restful-httpd',
|
|
|
|
|
'shared_libs': ['httpd'],
|
|
|
|
|
'static_libs': []
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
helper.add_deps(DEPENDS_LIBS)
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_libs 增加依赖的库。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.add_libs(['sqlite3'])
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* set\_dll\_def 设置动态库的 def 文件名。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.set_dll_def('src/table_view.def')
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_cpppath 增加头文件搜索路径。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.add_cpppath([os.path.join(helper.APP_ROOT, '3rd')])
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_libpath 增加库的搜索路径。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_cxxflags 增加 C++预处理参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_ccflags 增加 C 预处理参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_linkflags 增加链接参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_libs 增加特定平台的需要的库。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.add_platform_libs('Windows', ['ws2_32'])
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_cpppath 增加特定平台的需要的头文件搜索路径。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_libpath 增加特定平台的需要的库搜索路径。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_ccflags 增加特定平台的需要的 C 预处理参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_cxxflags 增加特定平台的需要的 C++预处理参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* add\_platform\_linkflags 增加特定平台的需要的链接参数。
|
2020-09-06 16:17:16 +08:00
|
|
|
|
|
|
|
|
|
## 三、注意事项
|
|
|
|
|
|
|
|
|
|
* 平台相关的函数,plat 的取值:
|
|
|
|
|
|
|
|
|
|
* Windows 表示 Windows
|
|
|
|
|
* Linux 表示 Linux
|
|
|
|
|
* Darwin 表示 MacOS
|
|
|
|
|
|
|
|
|
|
* helper 支持链式调用,call 函数需要放到最后。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
helper.add_libs(['sqlite3']).add_cpppath([os.path.join(helper.APP_ROOT, '3rd')]).call(DefaultEnvironment)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 四、参考
|
|
|
|
|
|
2021-02-24 17:43:01 +08:00
|
|
|
|
* [如何引用第三方库](how_to_use_3rd_libs.md)
|
|
|
|
|
* [编写跨平台的代码](cross_platform_programming.md)
|
|
|
|
|
|
2020-09-06 16:17:16 +08:00
|
|
|
|
* https://github.com/zlgopen/awtk-hello/blob/master/SConstruct
|
|
|
|
|
|
|
|
|
|
* https://github.com/zlgopen/awtk-mvvm-c-hello/blob/master/SConstruct
|
|
|
|
|
|
|
|
|
|
* https://github.com/zlgopen/awtk-widget-table-view/blob/master/SConstruct
|