使用gyp

GYP(Generate You Project),生成IDE项目的工具,使用Python脚本写成,配置文件为JSON格式。

使用gyp需要两个环境,python和gyp。gyp可以直接在这里下载

git clone https://chromium.googlesource.com/external/gyp

一般下载到build/gyp

使用python将我们的gyp文件加载并运行起来

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)

args中可以添加工程的配置文件,大概格式如下:

{
    '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额外设置

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注