【笔记】GYP Usage
2014-03-14 13:40
288 查看
GYP Usage
GYPCMake
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 StartedGypUserDocumentation
GypLanguageSpecification
InputFormatReference
4) 使用GYP
可以学习别人写的样例gypdemo,构建一个使用了JNI的APK。另外补充下node-gyp,其用于写Node.js的C++扩展。
4.1) 参考
gypdemoNode.js C++ addon编写实战
相关文章推荐
- Yourkit 学习笔记-CPU Usage telemetry
- Yourkit 学习笔记-CPU Usage telemetry
- Spring笔记之五(Hierarchical Bean Factory Usage)
- libhaur笔记1:Usage
- SQL Server 2000 (SP4)笔记整理(三):触发器
- tomcat 附带例子笔记2
- C++ Primer 笔记
- CEGUI学习笔记六-- 使用CEGUI解决具体问题
- git使用笔记
- IIS 7.5学习笔记(二)IIS简史:从IIS 1.0到IIS 7.5
- 微软企业库4.1学习笔记(十一)企业库的核心类
- GCC-3.4.6源代码学习笔记(148)
- 工作笔记 2011-06-14 二
- API Demos 2.3 学习笔记 (8)-- Views->ImageButton
- 12月27日笔记
- Windows 8学习笔记(二)——XML文件的操作
- Design Pattern学习笔记 --- State模式
- Oracle笔记(七) 数据更新、事务处理、数据伪列
- python学习笔记二