在 scons 中设置编译器特定标志 [英] Setting compiler specific flags in scons

查看:94
本文介绍了在 scons 中设置编译器特定标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写将在不同平台和编译器上使用的 scons 脚本时,有时需要添加编译器特定标志.伪代码中的 Fx

When writing a scons script that will be used on different platform and compiler it's sometimes desired to add compiler specific flags. Fx in pseudo code

if using_gcc:
    env.Append( CCFLAGS=["-g"] )
elif using_msvc:
    env.Append( CCFLAGS=["/Zi"] )

在较早的时候,我只是复制了 Tools 下的适当 (?) .py 文件并修改了这些文件并将其放置在 site_tools 下,但是这似乎是一个骇人听闻的解决方案.

At an earlier occation I just copied the appropriate(?) .py files under Tools and modified these and placed under site_tools, but that seems like a hackish solution.

有没有更好的方法来达到这个结果?如果可以将其添加到 site_scons 下以在全局范围内生效(而不必求助于黑客工具文件本身),那当然会很好.

Is there a better way to achieve this result? It would of course be nice if it could be added under site_scons to take global effect (without having to resort to hacking the tools files themselves).

注意:我发现在 site_scons 下这样做是可取的原因是它可以作为在多个项目之间共享的公共构建系统的一部分来完成.当然,这意味着必须在项目的所有参与者之间共享这个构建系统.

Note: The reason I find it desirable to do this under site_scons is that it could be done a part of a common build system that is shared among multiple projects. Naturally this means that one have to share this build system among all participants in the project too.

推荐答案

我利用 SCons 在 OSX、Winders 和 Linux 上构建,使用相同的脚本,并且通常处理像这样的平台相关标志.

I utilize SCons to build on OSX, Winders, and Linux, with the same scripts, and usually handle platform dependent flags like this.

import platform
env = Environment()
env['SYSTEM'] = platform.system().lower()

if env['SYSTEM'] in ['linux', 'darwin']:
    env.Append( CCFLAGS=["-g"] )
if env['SYSTEM'] == 'windows':
    env.Append( CCFLAGS=["/Zi"] )

我将系统添加为环境变量,因为它通常会出现多次,而且随处可用很方便.

I add the system as an environment variable because it usually comes up several times, and it's handy to just have it available everywhere.

请注意,当您混合使用工具链、构建模式和其他有趣的选项时,此逻辑通常会变得更加复杂.

Note that this logic usually gets much more complicated when you mix in toolchains, build modes, and other fun options.

我尽量不使用 site_scons、用户环境变量或任何点文件来修改构建环境.我发现在一个地方定义整个环境规范更有用,并保证(尽可能)对所有平台上的所有用户都相同.

I try not to use site_scons, user environment variables, or any dot-files to modify the build environment. I find it much more useful to have the entire environment specification defined in one place, and guaranteed (as best as possible) to be the same for all users on all platforms.

这篇关于在 scons 中设置编译器特定标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆