我试图用gyp创建一个简单的跨平台C++项目.目前我只是在Mac上尝试这个 - 但是想最终为windows,Linux,ios和android构建它.HEre是我正在使用的简单gyp文件.我希望能够使用忍者以及来自此gyp的xcode/msvc项目.我知道我需要能够将
-std = c ++ 11和-libstdc ++添加到clang的命令行中,但是现在我只能使用g ++而不是clang看到生成的构建文件.
这是我的gyp文件.
{
'targets': [
{
'target_name': 'libtest',
'product_name': 'test',
'type': 'static_library',
'sources': [
'./src/lib.cpp',
],
'include_dirs': [
'include',
],
},
{
'target_name': 'testapp',
'type': 'executable',
'sources': [
'./test/test.cpp',
],
'include_dirs': [
'src',
],
'dependencies': [
'libtest'
],
},
],
}
Run Code Online (Sandbox Code Playgroud)
我在某种程度上想出了这一点.至少我得到它在mac上工作makefile(不是忍者,这是我最初的希望).
首先我必须得到gyp来使用clang而不是g ++,为此我必须将make_global_settings添加到gyp文件中.对于跨平台构建而言,这似乎不是一个好的计划.我也能够用环境变量设置这些,我猜我可以用条件来做一些特定的mac.
'make_global_settings': [
['CXX','/usr/bin/clang++'],
['LINK','/usr/bin/clang++'],
],
'targets':
[
......
Run Code Online (Sandbox Code Playgroud)
我要做的另一件事是根据目标类型添加一个带有OTHER_CPLUSPLUSFLAGS和OTHER_LDFLAGS的xcode_settings字典.完整的例子如下.
{
'make_global_settings': [
['CXX','/usr/bin/clang++'],
['LINK','/usr/bin/clang++'],
],
'targets': [
{
'target_name': 'mylib',
'product_name': 'mylib',
'type': 'static_library',
'sources': [
'src/implementation.cc',
],
'include_dirs': [
'include',
],
'conditions': [
[ 'OS=="mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS' : ['-stdlib=libc++'],
},
}],
],
},
{
'target_name': 'myapp',
'type': 'executable',
'sources': [
'./bin/myapp.cc',
],
'conditions': [
[ 'OS=="mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++'],
'OTHER_LDFLAGS': ['-stdlib=libc++'],
},
}],
],
'include_dirs': [
'include',
],
'dependencies': [
'mylib'
],
},
],
}
Run Code Online (Sandbox Code Playgroud)