GYP(Generate You Project),生成IDE项目的工具,使用Python脚本写成,配置文件为JSON格式。
使用gyp需要两个环境,python和gyp。gyp可以直接在这里下载
git clone https://chromium.googlesource.com/external/gyp
一般下载到build/gyp
使用python将我们的gyp文件加载并运行起来
Shell
import gyp // 载入gyp模块
import sys
import os
args = sys.argv[1:]
args.append(os.path.join(os.path.abspath(uv_root), 'test.gyp'))
def run_gyp(args) :
rc = gyp.main(args) // gyp初始化
if rc != 0 :
print('Error running GYP')
sys.exit(rc)
1
2
3
4
5
6
7
8
9
10
11
12
importgyp//载入gyp模块
importsys
importos
args=sys.argv[1:]
args.append(os.path.join(os.path.abspath(uv_root),'test.gyp'))
defrun_gyp(args):
rc=gyp.main(args)//gyp初始化
ifrc!=0:
print('Error running GYP')
sys.exit(rc)
args中可以添加工程的配置文件,大概格式如下:
Shell
{
'target_defaults': {
'conditions': [
['OS != "win"', {
'defines': [
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64',
],
'conditions': [
['OS=="solaris"', {
'cflags': [ '-pthreads' ],
}],
['OS not in "solaris android"', {
'cflags': [ '-pthread' ],
}],
],
}],
],
'xcode_settings': {
'WARNING_CFLAGS': [ '-Wall', '-Wextra', '-Wno-unused-parameter' ],
'OTHER_CFLAGS': [ '-g', '--std=gnu89', '-pedantic' ],
}
},
target: [
{
'target_name': 'hello',
'type': 'executable',
'dependencies': [ 'libuv' ],
'sources': [
'hello.c',
],
'conditions': [
[ 'OS=="win"', {
'sources': [
],
'libraries': [ '-lws2_32' ]
}, { # POSIX
'defines': [ '_GNU_SOURCE' ],
'sources': [
'test/runner-unix.c',
'test/runner-unix.h',
]
}],
['uv_library=="shared_library"', {
'defines': [ 'USING_UV_SHARED=1' ]
}],
],
'msvs-settings': {
'VCLinkerTool': {
'SubSystem': 1, # /subsystem:console
},
},
},
]
}
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
'target_defaults':{
'conditions':[
['OS != "win"',{
'defines':[
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64',
],
'conditions':[
['OS=="solaris"',{
'cflags':['-pthreads'],
}],
['OS not in "solaris android"',{
'cflags':['-pthread'],
}],
],
}],
],
'xcode_settings':{
'WARNING_CFLAGS':['-Wall','-Wextra','-Wno-unused-parameter'],
'OTHER_CFLAGS':['-g','--std=gnu89','-pedantic'],
}
},
target:[
{
'target_name':'hello',
'type':'executable',
'dependencies':['libuv'],
'sources':[
'hello.c',
],
'conditions':[
['OS=="win"',{
'sources':[
],
'libraries':['-lws2_32']
},{# POSIX
'defines':['_GNU_SOURCE'],
'sources':[
'test/runner-unix.c',
'test/runner-unix.h',
]
}],
['uv_library=="shared_library"',{
'defines':['USING_UV_SHARED=1']
}],
],
'msvs-settings':{
'VCLinkerTool':{
'SubSystem':1,# /subsystem:console
},
},
},
]
}
target_name:工程名
type: 工程类型
dependencies: 依赖文件夹
sources: 源文件
conditions:条件判断
msvs-settings:msvs额外设置