Prevent SCons from looking for standard tools

后端 未结 3 573
北海茫月
北海茫月 2020-12-07 02:11

I am currently setting up SCons for cross-compilation with Windows as the host OS. I am building a custom Environment for the cross-compiler, but SCons insists

相关标签:
3条回答
  • 2020-12-07 02:37

    Consider redefining the DefaultEnvironment instead of defining an Environment.

    All of the Builder functions that we've introduced so far, like Program and Library, actually use a default construction environment that contains settings for the various compilers and other tools that SCons configures by default, or otherwise knows about and has discovered on your system. The goal of the default construction environment is to make many configurations to "just work" to build software using readily available tools with a minimum of configuration changes.

    This way, SCons won't try to make predictions based on common usage and apply them to your project. For example:

    PATH = {'PATH' : ['C:/cygwin/bin']}
    env = Environment(ENV=PATH)
    env.Program('helloworld.c++')
    

    will make assumptions based on what it thinks is the most likely case & try to find Visual Studio before resorting to whatever it finds in PATH, whereas:

    PATH = {'PATH' : ['C:/cygwin/bin']}
    env = DefaultEnvironment(ENV=PATH)
    env.Program('helloworld.c++')
    

    will make no such a assumption, and go directly to whatever it finds in PATH without looking for Visual Studio.

    0 讨论(0)
  • 2020-12-07 02:39

    You may suppress warnings like this

    env.SetOption('warn', 'no-visual-c-missing')
    

    For example, to cross-compile for ARM Cortex-M microcontrollers I'm doing this

    cross = 'arm-none-eabi-'
    toolchain = {
        'CC': cross + 'gcc',
        'CXX': cross + 'g++',
        'AR': cross + 'ar',
        'AS': cross + 'gcc',
        'OBJCOPY': cross + 'objcopy',
        'SIZE': cross + 'size',
        'PROGSUFFIX': '.elf',
    }
    
    env = Environment(tools=('gcc', 'g++', 'gnulink', 'ar', 'as'), ENV=os.environ)
    env.SetOption('warn', 'no-visual-c-missing')
    env.Replace(**toolchain)
    
    0 讨论(0)
  • 2020-12-07 02:42

    There are at least 2 ways to do this, the first way is the easiest, try creating the environment specifying the compiler, as follows:

    env = Environment(CC = '/path/to/the/compiler')
    

    You'll probably need to add paths for the linker and other tools as well. Then SCons shouldnt search for them.

    Another way to do it would be to create a tool definition for the cross-compiler using the tools argument on the Environment() function as mentioned in the CONFIGURATION FILE REFERENCE section of the SCons man page, where the following is mentioned:

    Additionally, a specific set of tools with which to initialize the environment may be specified as an optional keyword argument:

    env = Environment(tools = ['msvc', 'lex'])

    Non-built-in tools may be specified using the toolpath argument:

    env = Environment(tools = ['default', 'foo'], toolpath = ['tools'])

    ...

    The individual elements of the tools list may also themselves be two-element lists of the form (toolname, kw_dict). SCons searches for the toolname specification file as described above, and passes kw_dict, which must be a dictionary, as keyword arguments to the tool's generate function. The generate function can use the arguments to modify the tool's behavior by setting up the environment in different ways or otherwise changing its initialization.

    tools/my_tool.py:

    def generate(env, **kw):
      # Sets MY_TOOL to the value of keyword argument 'arg1' or 1.
      env['MY_TOOL'] = kw.get('arg1', '1')
    def exists(env):
      return 1
    

    SConstruct:

    env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})],
                      toolpath=['tools'])
    
    0 讨论(0)
提交回复
热议问题