google构建

GN构建系统

下载depot_tools并设置环境变量

  1. git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git (需要翻墙)

  2. 设置环境变量 将depot_tools的路径添加到环境变量(建议放置第一条,在python环境变量之前)

  3. 禁止工具升级 ==设置环境变量== DEPOT_TOOLS_UPDATE=0 或者 ==删除.git目录==

工具库包含

  • gclient 支持svn和git
  • gcl 预提交脚本for svn python的codeview
  • git-cl 预提交脚本for git python的codeview
  • svn
  • drover 快速还原svn提交
  • cpplint.py 静态检查工具
  • pylint python静态检查工具
  • presubmit_support.py脚本
  • repo: The repo tool.
  • zsh-goodies 补全
  • wtf
  • weekly
  • git-gs

GN exe的生成

GN是一个元构建系统,可为Ninja生成构建文件。

  1. git clone https://gn.googlesource.com/gn

  2. python build/gen.py

  3. ninja -C out(环境要有ninja)

GN使用命令

  1. 生成构建目录 gn gen out/windows_x86_debug

  2. 添加构建参数 gn args out/windows_x86_debug

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// gn args --list out/windows_x86_debug
is_debug = true
is_official_build=false
is_component_build = false
target_cpu="x64"
symbol_level = 0
is_win_fastlink = true //不生成pdb

// 交叉编译 https://gn.googlesource.com/gn/+/master/docs/cross_compiles.md
target_os = "chromeos"
target_os = "android"

target_cpu = "arm"
target_cpu = "x86"
target_cpu = "x64"

编写GN文件

1. 根目录下创建.gn文件

一般build目录下都有一些默认的配置 tool_chain

1
2
# The location of the build configuration file.
buildconfig = "//build/BUILDCONFIG.gn"

2. 创建BUILD.gn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## 可执行程序
executable("hello") {
sources = [ "hello.cc" ]

deps = [
":hello_shared",
":hello_static",
]
}

## dll
shared_library("hello_shared") {
sources = [
"hello_shared.cc",
"hello_shared.h",
]

defines = [ "HELLO_SHARED_IMPLEMENTATION" ]
}

## lib
static_library("hello_static") {
sources = [
"hello_static.cc",
"hello_static.h",
]
}

ninja

  1. git clone git://github.com/ninja-build/ninja.git

  2. cmake 编译或者https://github.com/ninja-build/ninja/releases下载binary

编译问题

warning: A compatible version of re2c (>= 0.11.3) was not found; changes to src/*.in.cc will not affect your build.
wrote build.ninja.

安装re2c http://re2c.org/

build config

win

  1. Microsoft Message Compiler (mc.exe)
打赏
  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2020-2021 一潭清泓
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信