如何根据编译器类型在SConstruct for C编译器中设置选项?

bia*_*lix 5 c compiler-construction scons compiler-options

我需要为C编译器设置其他选项,例如添加标志以打开所有警告,具体取决于编译器的类型.例如,我应该使用MSVC

env.Append(CPPFLAGS = "/Wall")
Run Code Online (Sandbox Code Playgroud)

但对于mingw(gcc)我需要使用:

env.Append(CCFLAGS = "-Wall") 
Run Code Online (Sandbox Code Playgroud)

我怎样才能以scons的方式做到这一点?

ric*_*chq 6

您可以检查编译器的名称:

cc = env['CC']
if cc == 'cl':
  env.Append(CPPFLAGS = '/Wall')
elif cc == 'gcc':
  env.Append(CCFLAGS = '-Wall')
Run Code Online (Sandbox Code Playgroud)