Search code examples
sconsclang++

Scons to use Clang -MJ option


Hi I am trying to build a compile_commands.json on windows with Scons build system and all other possibilities have failed.

I decided to use the Clang -MJ option to do this as this seems the easiest solution available.

The issue is that it isnt clear how I would go about doing this with the Scons build system; Basically I have to add -MJ myfilename.o.json to every build command. I am currently building a Library with multiple sources files like this : library = env.StaticLibrary(target=result_path + '/' + result_name, source=sources)

Essentially at the end I should have : clang++ -target x86_64-pc-windows-gnu -MJ AABB.o.json -o src/core/AABB.o -c -m64 -g -O3 -std=c++14 -Wwrite-strings -I. -I/c/GodotLibraries/godot_headers -Iinclude -Iinclude/core src/core/AABB.cpp

Thanks in advance,

`


Solution

  • You are trying to set special compiler flags for your current build environment. This is done by appending the new flags to the correct environment variable. Depending on what build process (=Builder) you want to use, the corresponding single build actions (=Actions) might use different variables. The User Guide contains an Appendix A "Construction Variables", listing the default variables and their synopsis.

    In your case the CCFLAGS is relevant and can be used like this:

    env = Environment()
    env.Append(CCFLAGS=['-MJ','AAB.o.json','-m64','-g','-O3'])
    
    env.Program(...)
    

    In the same way you can make SCons use the clang compiler, by setting the CXX variable accordingly:

    env = Environment()
    env['CXX']='clang'
    env.Append(CCFLAGS=['-MJ','AAB.o.json','-m64','-g','-O3'])
    
    env.Program(...)
    

    I hope this lets you get the general idea behind the Builder/Action setup in SCons: The basic structure of the executed command is always the same for each Builder, but you can influence the final output by setting and overwriting those environment variables that get expanded.