0

I want to check in Scons that my compiler support some option (for example -fcilkplus). The only way I manage to do it is the following sequence of operations:

env.Prepend(CXXFLAGS = ['-fcilkplus'], LIBS = ['cilkrts'])

Then I launch my custom checker:

def CheckCilkPlusCompiler(context):
    test = """
    #include <cilk/cilk.h>
    #include <assert.h>
    int fib(int n) {
      if (n < 2) return n;
      int a = cilk_spawn fib(n-1);
      int b = fib(n-2);
      cilk_sync;
      return a + b;
    }
    int main() {
      int result = fib(30);
      assert(result == 832040);
      return 0;
    }
    """
    context.Message('Checking Cilk++ compiler ... ')
    result = context.TryRun(test, '.cpp')
    context.Result(result[0])
    return result[0]

Now if it fails, I have to remove the two options extra flags -fcilkplus cilkrts from the environment variables. Is there a better way to do that ?

The problem is that I can't manage to access to the env from the context and therefore I can't make a clone of it.

hivert
  • 10,579
  • 3
  • 31
  • 56

1 Answers1

0

You can use check the availability of a library with SCons as follows:

env = Environment()
conf = Configure(env)
if not conf.CheckLib('cilkrts'):
    print 'Did not find libcilkrts.a, exiting!'
    Exit(1)
else:
    env.Prepend(CXXFLAGS = ['-fcilkplus'], LIBS = ['cilkrts'])

env = conf.Finish()

You could also check the availability of a header as follows:

env = Environment()
conf = Configure(env)
if conf.CheckCHeader('cilk/cilk.h'):
    env.Prepend(CXXFLAGS = ['-fcilkplus'], LIBS = ['cilkrts'])
env = conf.Finish()

Update:

I just realized, you can access the environment on the Configure object as follows:

conf.env.Append(...)
Brady
  • 10,207
  • 2
  • 20
  • 59
  • Thanks a lot, but I already know all of this. My question is specifically to *check for a compiler option*. The `-fcilkplus` is just a use case. I edited my question to make it clearer. – hivert Apr 24 '14 at 10:58