您的位置:首页 > 其它

GYP(Generate Your Project)一个很有价值的构建系统

2012-09-19 09:34 465 查看
转载自:http://blog.csdn.net/bertzhang/article/details/7387954

因为阅读chromium的需要,也熟悉了一下chromium使用的GYP构建系统,其实这个系统和我原来所在的一个公司的构建系统非常相似,因此学习起来也比较容易。

首先看一下gyp的安装,如果你使用ubuntu系统那么安装可以通过下面的命令完成:

[cpp] view
plaincopy

sudo apt-get install gyp  

下面我们就通过一个例子来看看gyp的使用,假设我们编写三个文件hello_world.cc, my_class.h, my_class.cc这三个文件内容如下:

hello_world.cc

[cpp] view
plaincopy

#include <stdio.h>  

#include "my_class.h"  

int main(int argc, char** argv) {  

  printf("hello world\n");  

  MyClass my_class(100);  

  my_class.Fun1();    

}  

my_class.h

[cpp] view
plaincopy

class MyClass {  

public:  

  MyClass(int value) : value_(value) {}  

  void Fun1();  

private:  

  int value_;  

};  

my_class.cc

[cpp] view
plaincopy

#include "my_class.h"  

#include <stdio.h>  

void MyClass::Fun1() {  

  printf("the value is %d\n", value_);  

}  

下面我们编写构建文件foo.gyp

foo.gyp

[cpp] view
plaincopy

{  

   'targets': [  

     {  

       'target_name': 'foo',  

       'type': 'executable',  

       'sources': [  

         'hello_world.cc',  

  'my_class.h',  

  'my_class.cc',  

       ],  

     },  

   ],  

 }  

然后运行命令:

[cpp] view
plaincopy

gyp --depth=. foo.gyp  

其中--depth=.虽然没什么用,但必须要加上,参考文献[1]说是chromium遗留问题

命令运行后会生成Makefile文件,这样就可以使用make进行编译了。

注意:最后}后面没有“,”, 开始这个地方写错了,总是出错,耽误了不少时间。

如果涉及到库、编译依赖、跨平台等问题可以详细参考文献[2],这里不一一说明,本文主要演示一个简单的使用过程,更多功能可以参考文献[2]来实现。

文献1比较了gyp和cmake等,也有一定的参考价值。

参考文献:

[1]http://blog.xiaogaozi.org/2011/10/29/introduction-to-gyp

[2]http://code.google.com/p/gyp/wiki/GypUserDocumentation
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐