[Scons-users] Detecting flag availability with SConf for a compiler that doesn't error out on bad flags

Andrew C. Morrow andrew.c.morrow at gmail.com
Sun Mar 10 13:12:21 EDT 2013


For GCC and clang, I've been using the following approach with some
success to build a facility to detect whether a given compiler flag is
available or not given the currently configured tool set:

1) Clone the current Env.
2) Add the relevant flag to the env, along with -Werror, to CCFLAGS or
CXXFLAGS as appropriate.
3) Construct a Configure context, and invoke TryCompile
4) If the TryCompile succeeds, then the flag is supported, otherwise no.

However, this approach falls over with the Microsoft toolchain,
because 'cl' always treats invalid command line flags as warnings, no
matter whether you ask it to treat all warnings as errors with /WX, or
even if you attempt to escalate the "invalid command line flag"
warning directly with /we<CODE>.

Please see the following links for more details:

http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
http://stackoverflow.com/questions/15274521/using-scons-trycompile-to-examine-compiler-flag-support-on-windows
https://connect.microsoft.com/VisualStudio/feedback/details/781052/cl-compiler-should-honor-wx-and-or-wecode-for-command-line-argument-warnings

I'm really pleased with how this technique is working with clang and
gcc, but if I can't bring the microsoft tools into the game I'm going
to need to abandon it.

Does anyone have any suggestions as to how to get the SConf facility
to recognize when 'cl' has rejected a candidate command line flag as
unsupported? Solutions that involve modifying the SCons code aren't
really viable in my case. Interposing on the implementation of SConf
may be, as long as the modifications are small and targeted.

Thanks,
Andrew


More information about the Scons-users mailing list