每个源cflags

时间:2015-08-28 09:47:17

标签: node-gyp gyp cflags

gyp中是否有办法仅为某些源文件启用某些cflags?

this bug的上下文中,我想找到一种方法来编译一些启用了某些SSE功能的代码,而其他代码(用于在运行时检测所述功能的可用性并提供回退) )在优化过程中不应使用这些功能。

通常,我发现node-gyp文档完全不够。

1 个答案:

答案 0 :(得分:2)

作为解决方法,您可以在.GYP文件中使用特定的cflags创建静态库目标,然后根据某些条件将此静态库链接到主目标。

{
   'variables: {
       'use_sse4%': 0, # may be redefined in command line on configuration stage
   },
   'targets: [
       # SSE4 specific target
       {
           'target_name': 'sse4_arch',
           'type': 'static_library',
           'sources': ['sse4_code.cpp'],
           'cflags': ['-msse4.2'],
       },
       # Non SSE4 code
       {
           'target_name': 'generic_arch',
           'type': 'static_library',
           'sources': ['generic_code.cpp'],
       },
       # Your main target
       {
           'target_name': 'main_target',               
           'conditions': [
               ['use_sse4==1', # conditional dependency on the `use_ss4` variable
                   { 'dependencies': ['sse4_arch'] },   # true branch
                   { 'dependencies': ['generic_arch'] } # false branch
               ],
           ],
       },  
   ],
}

有关依赖关系,变量和条件的更多详细信息,请参见GYP documentation

相关问题