您的位置:首页 > 其它

【笔记】GYP Usage

2014-03-14 13:40 288 查看

GYP Usage

GYP

CMake

GypVsCMake

1) 安装GYP

svn: http://gyp.googlecode.com/svn/trunk/

# 设置Python环境变量
PY_HOME = C:\Python27  # 注意是2.7
Path += %PY_HOME%;%PY_HOME%\Scripts

cd C:\gyp  # 到GYP目录
python setup.py install  # 安装GYP


Python

TortoiseSVN

2) 编译V8

svn: http://v8.googlecode.com/svn/trunk/

编译参考BuildingWithGYP

2.1) Visual Studio编译

前提

需要checkout以下三样到相应位置。

http://src.chromium.org/svn/trunk/tools/third_party/python_26  >  [path]\v8\third_party\python_26 http://src.chromium.org/svn/trunk/deps/third_party/cygwin  >  [path]\v8\third_party\cygwin http://src.chromium.org/svn/trunk/deps/third_party/icu46  >  [path]\v8\third_party\icu

Windows下总是麻烦一点。

编译

python.exe build\gyp_v8  # 动态库加"-Dcomponent=shared_library", 64位加"-Dtarget_arch=x64"
"c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com" /build Release build\All.sln

更多编译选项参考Custom build settings

2.2) 参考

BuildingWithGYP

编译v8引擎

3) 开始GYP

3.1) Hello World

hello.cc

#include <iostream>

int main() {
std::cout << "Hello World!" << std::endl;
}

hello.gyp

{
'targets': [
{
'target_name': 'hello',
'type': 'executable',
'sources': [
'hello.cc',
],
},
],
}

如果要加上"Debug/Release"目标,可以再添加如下一段:

{
'target_defaults': {
'default_configuration': 'Debug',
'configurations': {
'Debug': {
'defines': [ 'DEBUG', '_DEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 1,  # static debug
},
},
},
'Release': {
'defines': [ 'NDEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 0,  # static release
},
},
}
},
'msvs_settings': {
'VCLinkerTool': {
'GenerateDebugInformation': 'true',
},
},
},

'targets': [
# ...
]
}

生成

gyp --depth=. hello.gyp

Windows下默认生成VS工程文件,生成Makefile加"-f make"或"--format=make"。

3.2) V8 Hello World

把V8编译成动态库,得到v8.lib,v8.dll。(生成时加"-Dcomponent=shared_library")

把V8 Hello World代码保存为"v8hello.cc",代码见V8 Getting Started

v8vars.gypi

{
'variables' : {
'V8_DIR': '../v8',
},
}

设置V8_DIR为对应路径。这里单独把变量放到了gypi (gyp include)内,后续includes包含。

v8hello.gyp

{
'includes': [
'v8vars.gypi',
],
'targets': [
{
'target_name': 'v8hello',
'type': 'executable',
'sources': [
'v8hello.cc',
],
'include_dirs': [
'<(V8_DIR)/include',
],
'conditions': [
['OS=="win"',
{
'libraries': [
'<(V8_DIR)/build/Release/lib/v8.lib',
],
'copies': [
{
'destination': 'Default',  # default target
'files': [
'<(V8_DIR)/build/Release/v8.dll',
'<(V8_DIR)/build/Release/icui18n.dll',
'<(V8_DIR)/build/Release/icuuc.dll',
]
},
],
}
],
],
},
],
}

生成

gyp --depth=. v8hello.gyp

然后打开sln,编译即可。

3.3) 参考

V8 Getting Started

GypUserDocumentation

GypLanguageSpecification

InputFormatReference

4) 使用GYP

可以学习别人写的样例gypdemo,构建一个使用了JNI的APK。

另外补充下node-gyp,其用于写Node.js的C++扩展。

4.1) 参考

gypdemo

Node.js C++ addon编写实战
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  GYP V8