Search code examples
scons

In SCons, how to set a C preprocessor define temporarily


My C code contains #ifdef FOO. Can add something to the SCons command line to set the define, without having to modify the SConstruct/SConscript files?

I know there is a construction variable CFLAGS, and if I could get -DFOO into it, that should work. But, I cannot find a way to set construction variables from the command line.


Solution

  • No, unless your SConstructs/SConscripts support some sort of option/variable that you could give on the command-line (see chap. 10 "Controlling a Build From the Command-Line" in the UserGuide http://www.scons.org/doc/production/HTML/scons-user.html ).

    By design, SCons uses "clean" Environments (no shell variables are imported) to protect your builds and make them repeatable. You can't simply override this by suddenly injecting flags and options from the outside. But you can, in the SConstructs, create your build Environment such that you allow it to "import" certain shell settings (or the whole os.environ). See also #1 of the "most frequently asked FAQ" at https://bitbucket.org/scons/scons/wiki/FrequentlyAskedQuestions#markdown-header-why-doesnt-scons-find-my-compilerlinkeretc-i-can-execute-it-just-fine-from-the-command-line .