在scons中检测CPU架构(32位/ 64位)?

时间:2022-09-01 10:01:57

Are there any 'standard' plugins for detecting the CPU architecture in scons?

是否有用于检测scons中CPU架构的“标准”插件?

BTW, this question was asked already here in a more general form... just wondering if anyone has already taken the time to incorporate this information into scons.

顺便说一句,这个问题已经在这里以更一般的形式提出了......只是想知道是否有人已经花时间将这些信息合并到scons中。

2 个解决方案

#1


6  

Using i386 is rather compiler dependant, and won't detect non x86 32 bits archs. Assuming the python interpreter used by scons runs on the CPU you are interested in (not always the case - think cross compilation), you can just use python itself.

使用i386依赖于编译器,并且不会检测非x86 32位arch。假设scons使用的python解释器运行在你感兴趣的CPU上(并非总是如此 - 想想交叉编译),你可以只使用python本身。

import platform
print platform.machine()
print platform.architecture()

If you need something more sophisticated, then maybe you will have to write your own configure function - but it may be better to deal with it in your code directly.

如果你需要更复杂的东西,那么也许你必须编写自己的配置函数 - 但最好直接在你的代码中处理它。

#2


2  

Something like this?

像这样的东西?

env = Environment()
conf = Configure(env)
if conf.CheckDeclaration("__i386__"):
    conf.Define("MY_ARCH", "blahblablah")
env = conf.Finish()

#1


6  

Using i386 is rather compiler dependant, and won't detect non x86 32 bits archs. Assuming the python interpreter used by scons runs on the CPU you are interested in (not always the case - think cross compilation), you can just use python itself.

使用i386依赖于编译器,并且不会检测非x86 32位arch。假设scons使用的python解释器运行在你感兴趣的CPU上(并非总是如此 - 想想交叉编译),你可以只使用python本身。

import platform
print platform.machine()
print platform.architecture()

If you need something more sophisticated, then maybe you will have to write your own configure function - but it may be better to deal with it in your code directly.

如果你需要更复杂的东西,那么也许你必须编写自己的配置函数 - 但最好直接在你的代码中处理它。

#2


2  

Something like this?

像这样的东西?

env = Environment()
conf = Configure(env)
if conf.CheckDeclaration("__i386__"):
    conf.Define("MY_ARCH", "blahblablah")
env = conf.Finish()