chromium
的编译过程中用到了GYP,GN和Ninja这三个构建工具,GYP
是一个在不同平台构建项目的工具,GN
是GYP
的升级版,Ninja
是一个小型追求速度的构建系统。
GYP
是Generate Your Projects
的缩写,GYP
的目的是为了支持更大的项目编译在不同的平台,比如Mac
,Windows
,Linux
,它可以生成Xcode工程,Visual Studio工程,Ninja编译文件和Makefiles。
GYP
的输入是.gyp
和.gypi
文件,.gypi
文件是用于.gyp
文件include使用的。.gyp
文件就是符合特定格式的json
文件。
先来看一个chromium
中缩减的.gyp
文件:
{
'variables': {
.
.
.
},
'includes': [
'../build/common.gypi',
],
'target_defaults': {
.
.
.
},
'targets': [
{
'target_name': 'target_1',
.
.
.
},
{
'target_name': 'target_2',
.
.
.
},
],
'conditions': [
['OS=="linux"', {
'targets': [
{
'target_name': 'linux_target_3',
.
.
.
},
],
}],
['OS=="win"', {
'targets': [
{
'target_name': 'windows_target_4',
.
.
.
},
],
}, { # OS != "win"
'targets': [
{
'target_name': 'non_windows_target_5',
.
.
.
},
}],
],
}
上面指定下面几个属性的值:
variables
: 定义可能被修改或者用于文件其它地方的变量。
includes
: 需要包含进来的有.gypi
后缀的文件。target_defaults
: 默认设置,应用于文件中的所有target。targets
: 指定该文件生成的target列表。conditions
: 指定不同的条件,修改文件中的变量。
下面来看构建一个简单的可执行文件的target:
{
'targets': [
{
'target_name': 'foo',
'type': 'executable',
'msvs_guid': '5ECEC9E5-8F23-47B6-93E0-C3B328B3BE65',
'dependencies': [
'xyzzy',
'../bar/bar.gyp:bar',
],
'defines': [
'DEFINE_FOO',
'DEFINE_A_VALUE=value',
],
'include_dirs': [
'..',
],
'sources': [
'file1.cc',
'file2.cc',
],
'conditions': [
['OS=="linux"', {
'defines': [
'LINUX_DEFINE',
],
'include_dirs': [
'include/linux',
],
}],
['OS=="win"', {
'defines': [
'WINDOWS_SPECIFIC_DEFINE',
],
}, { # OS != "win",
'defines': [
'NON_WINDOWS_DEFINE',
],
}]
],
},
],
}
target_name
: 唯一的来表示工程名称。
type
: 文件类型,这里是executable
。msvs_guid
: 用于生成Visual Studio solution
文件的GUID
值。dependencies
: 该target所依赖的其它target。defines
: 宏定义,用于-D
or/D
。include_dirs
: 包含头文件的文件夹,用于-I
or/I
。sources
: 该target的源文件列表。conditions
: 一些条件设置。
再来看一个简单的库的target:
{
'targets': [
{
'target_name': 'foo',
'type': '
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?