def get_opts(platform): from SCons.Variables import BoolVariable, PathVariable default_mono_static = platform in ["ios", "javascript"] default_mono_bundles_zlib = platform in ["javascript"] return [ PathVariable( "mono_prefix", "Path to the Mono installation directory for the target platform and architecture", "", PathVariable.PathAccept, ), PathVariable( "mono_bcl", "Path to a custom Mono BCL (Base Class Library) directory for the target platform", "", PathVariable.PathAccept, ), BoolVariable("mono_static", "Statically link Mono", default_mono_static), BoolVariable("mono_glue", "Build with the Mono glue sources", True), BoolVariable("build_cil", "Build C# solutions", True), BoolVariable( "copy_mono_root", "Make a copy of the Mono installation directory to bundle with the editor", True), BoolVariable( "mono_bundles_zlib", "Specify if the Mono runtime was built with bundled zlib", default_mono_bundles_zlib), ]
def create_variables(): """ Create a default scons var setup. This adds default parameters to the environment such as the options.py file, PATH and LD_LIBRARY_PATH are used for setting the respective environment variables, CPATH and LPATH are used for setting additional paths for C include files and library files respectively. Returns: (SCons.Script.Variables): The scons Variables pre-setup with common parameters """ # First create a dummy env to parse just the 'options' parameter. # This allows the user to specify a file containing build options options_var = SCons.Script.Variables() options_var.Add("options", "Options for SConstruct e.g. debug=0", "options.py") env = SCons.Script.Environment(variables=options_var) # Use this parameter to create the real variables, pre-populating the values from the user provided # options file, and also the dev_options.py file, which may be pe present if this is a developer checkout. # Note we include the 'options' var again, so it appears in the help command var = SCons.Script.Variables( [os.path.join("..", "internal", "dev_options.py"), env["options"]]) var.AddVariables( ("options", "Options for SConstruct e.g. debug=0", "options.py"), ("PATH", "Prepend to the PATH environment variable"), ("LD_LIBRARY_PATH", "Prepend to the LD_LIBRARY_PATH environment variable"), ("CPATH", "Append to the C include path list the compiler uses"), ("LPATH", "Append to the library path list the compiler uses"), ("scons_extra", "Extra scons files to be loaded, separated by comma.", ""), PathVariable( "install_prefix", "Installation prefix", os.path.join(os.path.sep, "usr", "local"), PathVariable.PathAccept, ), PathVariable( "install_bin_dir", "Executables installation directory", os.path.join("$install_prefix", "bin"), PathVariable.PathAccept, ), PathVariable( "install_include_dir", "Header files installation directory", os.path.join("$install_prefix", "include"), PathVariable.PathAccept, ), PathVariable( "install_lib_dir", "Libraries installation directory", os.path.join("$install_prefix", "lib"), PathVariable.PathAccept, ), ) return var
def _parse_default_command_line_options(): """Parses the command line options controlling various build settings @remarks This contains variables that work across all builds. Build-specific variables are discouraged, but would be irgnored by SCons' Variables class.""" command_line_variables = Variables(None, ARGUMENTS) # Build configuration (also called build type in many SCons examples) command_line_variables.Add( BoolVariable( 'DEBUG', 'Whether to do an unoptimized debug build', False ) ) # Default architecture for the binaries. We follow the Debian practices, # which, while clueless and chaotic, are at least widely used. default_arch = 'amd64' if 'armv7' in platform.uname()[4]: default_arch = 'armhf' if 'aarch64' in platform.uname()[4]: default_arch = 'arm64' # CPU architecture to target command_line_variables.Add( EnumVariable( 'TARGET_ARCH', 'CPU architecture the binary will run on', default_arch, allowed_values=('armhf', 'arm64', 'x86', 'amd64', 'any') ) ) # Directory for intermediate files command_line_variables.Add( PathVariable( 'INTERMEDIATE_DIRECTORY', 'Directory in which intermediate build files will be stored', 'obj', PathVariable.PathIsDirCreate ) ) # Directory for intermediate files command_line_variables.Add( PathVariable( 'ARTIFACT_DIRECTORY', 'Directory in which build artifacts (outputs) will be stored', 'bin', PathVariable.PathIsDirCreate ) ) return command_line_variables
def to_scons( self, env: "Optional[SCEnvironment]" = None ) -> "Union[SCVariables, Tuple[str, str, Union[str, Dict[str, str]]]]": """Convert option to SCons variable""" default = self.default if isinstance(default, str) and "$" in default and env is not None: default = env.subst(default) elif not isinstance(default, (str, bool)): raise TypeError( f"Invalid defaults option with type '{type(default)}'") if self.choices is None: out = self.name, self.description, default else: out = self.name, self.description, default, self.choices try: if isinstance(self, BoolOption): return BoolVariable(*out) elif isinstance(self, PathOption): return PathVariable(*out) elif isinstance(self, EnumOption): return EnumVariable(*out) else: return out except Exception as err: logger.error( f"Error converting '{self.name}' to SCons variable:\n{out}") raise err
def create_variables(): ''' Create a default scons var setup. This adds default parameters to the environment such as the options.py file, PATH and LD_LIBRARY_PATH are used for setting the respective environment variables, CPATH and LPATH are used for setting additional paths for C include files and library files respectively. Returns: (SCons.Script.Variables): The scons Variables pre-setup with common parameters ''' # First create a dummy env to parse just the 'options' parameter. # This allows the user to specify a file containing build options options_var = SCons.Script.Variables() options_var.Add('options', 'Options for SConstruct e.g. debug=0', 'options.py') env = SCons.Script.Environment(variables=options_var) # Use this parameter to create the real variables, pre-populating the values from the user provided # options file, and also the dev_options.py file, which may be pe present if this is a developer checkout. # Note we include the 'options' var again, so it appears in the help command var = SCons.Script.Variables( [os.path.join('..', 'internal', 'dev_options.py'), env['options']]) var.AddVariables( ('options', 'Options for SConstruct e.g. debug=0', 'options.py'), ('PATH', 'Prepend to the PATH environment variable'), ('LD_LIBRARY_PATH', 'Prepend to the LD_LIBRARY_PATH environment variable'), ('CPATH', 'Append to the C include path list the compiler uses'), ('LPATH', 'Append to the library path list the compiler uses'), ('scons_extra', 'Extra scons files to be loaded, separated by comma.', ''), PathVariable('install_prefix', 'Installation prefix', os.path.join(os.path.sep, 'usr', 'local'), PathVariable.PathAccept), PathVariable('install_bin_dir', 'Executables installation directory', os.path.join('$install_prefix', 'bin'), PathVariable.PathAccept), PathVariable('install_include_dir', 'Header files installation directory', os.path.join('$install_prefix', 'include'), PathVariable.PathAccept), PathVariable('install_lib_dir', 'Libraries installation directory', os.path.join('$install_prefix', 'lib'), PathVariable.PathAccept), ) return var
def create_variables(): ''' Create a default scons var setup. This adds default parameters to the environment such as the options.py file, PATH and LD_LIBRARY_PATH are used for setting the respective environment variables, CPATH and LPATH are used for setting additional paths for C include files and library files respectively. Returns: (SCons.Script.Variables): The scons Variables pre-setup with common parameters ''' options_var = SCons.Script.Variables() options_var.Add('options', 'Options for Sconstruct e.g. debug=0', 'options.py') env = SCons.Script.Environment(variables=options_var) # Create another Variables so we can have options appear in the help command var = SCons.Script.Variables(['dev_options.py', env['options']]) var.AddVariables( ('options', 'Options for Sconstruct e.g. debug=0', 'options.py'), ('PATH', 'Prepend to the PATH environment variable'), ('LD_LIBRARY_PATH', 'Prepend to the LD_LIBRARY_PATH environment variable'), ('CPATH', 'Append to the C include path list the compiler uses'), ('LPATH', 'Append to the library path list the compiler uses'), ('scons_extra', 'Extra scons files to be loaded, separated by comma.', None), PathVariable('install_prefix', 'Installation prefix', os.path.join(os.path.sep, 'usr', 'local'), PathVariable.PathAccept), PathVariable('install_bin_dir', 'Executables installation directory', os.path.join('$install_prefix', 'bin'), PathVariable.PathAccept), PathVariable('install_include_dir', 'Header files installation directory', os.path.join('$install_prefix', 'include'), PathVariable.PathAccept), PathVariable('install_lib_dir', 'Libraries installation directory', os.path.join('$install_prefix', 'lib'), PathVariable.PathAccept), ) return var
def get_opts(platform): from SCons.Variables import BoolVariable, PathVariable default_mono_static = platform in ["ios", "web"] default_mono_bundles_zlib = platform in ["web"] return [ PathVariable( "dotnet_root", "Path to the .NET Sdk installation directory for the target platform and architecture", "", PathVariable.PathAccept, ), ]
def generate(env, configGroup): # add parameters to configurate toolchain params = Variables(env['PARAMETER_SOURCE'], ARGUMENTS) params.Add(('gcc_compiler', 'GCC cross compiler prefix', '')) params.Add(('gcc_cppflags', 'GCC cross compiler cpp flags', '')) params.Add(('gcc_linkflags', 'GCC cross compiler link flags', '')) params.Add( PathVariable('gcc_sysroot', 'GCC cross compiler system root', '', PathVariable.Accept)) params.Update(env) try: configReport = env.configReport configReport.add('GCC cross compiler prefix', 'gcc_compiler', configGroup) configReport.add('GCC cross compiler cpp flags', 'gcc_cppflags', configGroup) configReport.add('GCC cross compiler link flags', 'gcc_linkflags', configGroup) configReport.add('GCC cross compiler system root', 'gcc_sysroot', configGroup) except: pass # get configuration parameters compiler = env.subst(env['gcc_compiler']) sysroot = env.subst(env['gcc_sysroot']) cppflags = env['gcc_cppflags'] env['CC'] = compiler + 'gcc' env['CXX'] = compiler + 'g++' env['LD'] = compiler + 'ld' env['STRIP'] = compiler + 'strip' env['OBJCOPY'] = compiler + 'objcopy' env['AS'] = compiler + 'as' env['AR'] = compiler + 'ar' env['RANLIB'] = compiler + 'ranlib' env.Append(CROSSCOMPILE_CPPFLAGS=cppflags) env.Append(CROSSCOMPILE_LINKFLAGS=linkflags) env.Append(CROSSCOMPILE_CPPFLAGS=['--sysroot={}'.format(sysroot)]) env.Append(CROSSCOMPILE_LINKFLAGS=['--sysroot={}'.format(sysroot)]) # apply cross compile flags to build environment env.Append(CFLAGS=env['CROSSCOMPILE_CFLAGS']) env.Append(CPPFLAGS=env['CROSSCOMPILE_CPPFLAGS']) env.Append(CXXFLAGS=env['CROSSCOMPILE_CXXFLAGS']) env.Append(LINKFLAGS=env['CROSSCOMPILE_LINKFLAGS'])
def generate(env, **kw): # Do we need to set the scons variables? if 'vars' in kw: kw['vars'].AddVariables( PathVariable('mpicc', 'MPI C compiler wrapper (default: mpicc)', None, PathVariable.PathAccept), PathVariable('mpicxx', 'MPI C++ compiler wrapper (default: mpiCC)', None, PathVariable.PathAccept), PathVariable('mpif90', 'MPI Fortran compiler wrapper (default: mpif90)', None, PathVariable.PathAccept)) return conf = env.Configure(custom_tests={'CheckCompiler': CheckCompiler}) # Set default compilers # Use I_MPI_ROOT to detect special Intel MPI wrappers if not 'mpicc' in env: if env['compiler'].startswith('cray_'): env['mpicc'] = 'cc' elif 'I_MPI_ROOT' in env['ENV']: if env['compiler'] == 'intel': env['mpicc'] = 'mpiicc' else: env['mpicc'] = 'mpicc' else: env['mpicc'] = 'mpicc' if not 'mpicxx' in env: if env['compiler'].startswith('cray_'): env['mpicxx'] = 'CC' elif 'I_MPI_ROOT' in env['ENV']: if env['compiler'] == 'intel': env['mpicxx'] = 'mpiicpc' else: env['mpicxx'] = 'mpicxx' else: if conf.CheckCompiler('mpicxx'): env['mpicxx'] = 'mpicxx' else: env['mpicxx'] = 'mpiCC' if not 'mpif90' in env: if env['compiler'].startswith('cray_'): env['mpif90'] = 'ftn' elif 'I_MPI_ROOT' in env['ENV']: if env['compiler'] == 'intel': env['mpif90'] = 'mpiifort' else: env['mpif90'] = 'mpif90' else: env['mpif90'] = 'mpif90' # Check all MPI wrappers ret = [conf.CheckCompiler(env[cc]) for cc in ['mpicc', 'mpicxx', 'mpif90']] if not all(ret): print 'Could not find all MPI wrappers!' env.Exit(1) # Update the environment and build environment for (compiler, wrapper) in [('CC', 'mpicc'), ('CXX', 'mpicxx'), ('F90', 'mpif90')]: # Set all known env variables for envVar in MPI_ENV_VARIABLES[compiler]: env['ENV'][envVar] = env[compiler] # Update the build environment env[compiler] = env[wrapper] conf.Finish()
def addDeprecatedOptions(opt): from SCons.Variables import PathVariable opt.Add( PathVariable('LAPACK', 'Path to LAPACK', '', PathVariable.PathAccept)) opt.Add(PathVariable('ATLAS', 'Path to ATLAS', '', PathVariable.PathAccept)) opt.Add( PathVariable('ATLASINC', 'Path to ATLAS includes', '', PathVariable.PathAccept)) opt.Add( PathVariable('BOOSTLIB', 'Path to BOOST libraries', '', PathVariable.PathAccept)) opt.Add( PathVariable('BOOSTINC', 'Path to BOOST includes', '', PathVariable.PathAccept)) opt.Add('BOOSTREGEX', 'Boost regex library name', '') opt.Add('BOOSTPO', 'Boost program options library name', '') opt.Add( PathVariable('LIBXTRA', 'Path to additional libraries', '', PathVariable.PathAccept)) opt.Add( PathVariable('NETCDFINC', 'Path to netcdf include files', '', PathVariable.PathAccept)) opt.Add( PathVariable('NETCDFLIB', 'Path to netcdf library files', '', PathVariable.PathAccept)) opt.Add( PathVariable('ALTPATH', 'Additional path to commands', '', PathVariable.PathAccept)) opt.Add( PathVariable('LIBS_OVERRIDE', 'Override linked libs', '', PathVariable.PathAccept)) opt.Add( PathVariable('LIBS_PATHS_OVERRIDE', 'Override paths to libs', '', PathVariable.PathAccept))
def generate(env, configGroup): # add parameters to configurate toolchain params = Variables(env['PARAMETER_SOURCE'], ARGUMENTS) params.Add( PathVariable( 'android_ndkroot', 'Path to Android NDK toolchain (NDK_ROOT env-param by default)', os.path.expanduser(os.environ['NDK_ROOT']), PathVariable.PathAccept)) params.Add( EnumVariable('android_arch', 'Android architecture to build for', 'armv7a', ['armv7', 'armv7a', 'armv8', 'x86', 'x86_64'])) params.Add(('android_apilevel', 'Android API level', '18')) params.Add(('android_gccversion', 'Android NDK GCC version', '4.9')) params.Update(env) try: configReport = env.configReport configReport.add('Path to Android NDK toolchain', 'android_ndkroot', configGroup) configReport.add('Android architecture to build for', 'android_arch', configGroup) configReport.add('Android API level', 'android_apilevel', configGroup) configReport.add('Android NDK GCC version', 'android_gccversion', configGroup) except: pass # get configuration parameters ndkroot = env.subst(env['android_ndkroot']) arch = env['android_arch'] apilevel = env['android_apilevel'] gccVersion = env['android_gccversion'] # set construction variables stlsupport = 'gnu-libstdc++' if env['android_arch'] == 'armv7': abi = 'androideabi' fullarch = 'armeabi-v7' hardfp = False elif env['android_arch'] == 'armv7a': abi = 'androideabi' fullarch = 'armeabi-v7a' hardfp = True elif env['android_arch'] == 'armv8': abi = 'androideabi' fullarch = 'armeabi-v8' hardfp = True elif env['android_arch'] == 'x86': abi = 'android' fullarch = 'x86' hardfp = False elif env['android_arch'] == 'x86_64': abi = 'android' fullarch = 'x86_64' hardfp = False else: raise Exception('Invalid architecture {}'.format(env['android_arch'])) compilerPrefix = '{}-{}-{}{}-'.format(arch, platform.system().lower(), abi, apilevel) compilerPrefix2 = '{}-{}-{}-'.format(arch, platform.system().lower(), abi) pathToolchain = os.path.join( ndkroot, 'toolchains', 'llvm', 'prebuilt', '-'.join([platform.system().lower(), platform.machine()])) env['ANDROID_TOOLCHAIN'] = pathToolchain pathBin = os.path.join(pathToolchain, 'bin') env['ANDROID_BIN'] = pathBin compiler = os.path.join(pathBin, compilerPrefix) compiler2 = os.path.join(pathBin, compilerPrefix2) env['ANDROID_COMPILER'] = compiler env['ANDROID_FULLARCH'] = fullarch env['ANDROID_HARDFP'] = hardfp env['CC'] = compiler + 'clang' env['CXX'] = compiler + 'clang++' env['LD'] = compiler2 + 'ld' env['STRIP'] = compiler2 + 'strip' env['OBJCOPY'] = compiler2 + 'objcopy' env['AS'] = compiler2 + 'as' env['AR'] = compiler2 + 'ar' env['RANLIB'] = compiler2 + 'ranlib' env['NASM'] = compiler2 + 'yasm' # libraries to link against required for libraries and binaries to load on android. # additional libraries can be required. android is in general quite picky about # these libraries and the loading order env.Append(CROSSCOMPILE_IBS=['m', 'z', 'log', 'c', 'android']) # libs.append( 'gnustl_static' ) # stl support using static gnustl env.Append(CROSSCOMPILE_CPPFLAGS=[ '-O3' ]) # default is -O2 so try to squeeze out a bit more speed if possible # hardware floating point support if hardfp: env.Append(CROSSCOMPILE_CPPFLAGS=['-D_NDK_MATH_NO_SOFTFP=1']) # apply cross compile flags to build environment env.Append(LIBS=env['CROSSCOMPILE_LIBS']) env.Append(CFLAGS=env['CROSSCOMPILE_CFLAGS']) env.Append(CPPFLAGS=env['CROSSCOMPILE_CPPFLAGS']) env.Append(CXXFLAGS=env['CROSSCOMPILE_CXXFLAGS']) env.Append(LINKFLAGS=env['CROSSCOMPILE_LINKFLAGS'])
def addDeprecatedOptions(opt): from SCons.Variables import PathVariable opt.Add(PathVariable("LAPACK", "Path to LAPACK", "", PathVariable.PathAccept)) opt.Add(PathVariable("ATLAS", "Path to ATLAS", "", PathVariable.PathAccept)) opt.Add( PathVariable("ATLASINC", "Path to ATLAS includes", "", PathVariable.PathAccept) ) opt.Add( PathVariable("BOOSTLIB", "Path to BOOST libraries", "", PathVariable.PathAccept) ) opt.Add( PathVariable("BOOSTINC", "Path to BOOST includes", "", PathVariable.PathAccept) ) opt.Add("BOOSTREGEX", "Boost regex library name", "") opt.Add("BOOSTPO", "Boost program options library name", "") opt.Add( PathVariable( "LIBXTRA", "Path to additional libraries", "", PathVariable.PathAccept ) ) opt.Add( PathVariable( "NETCDFINC", "Path to netcdf include files", "", PathVariable.PathAccept ) ) opt.Add( PathVariable( "NETCDFLIB", "Path to netcdf library files", "", PathVariable.PathAccept ) ) opt.Add( PathVariable( "ALTPATH", "Additional path to commands", "", PathVariable.PathAccept ) ) opt.Add( PathVariable( "LIBS_OVERRIDE", "Override linked libs", "", PathVariable.PathAccept ) ) opt.Add( PathVariable( "LIBS_PATHS_OVERRIDE", "Override paths to libs", "", PathVariable.PathAccept ) )
def init(env, vars): # Add parallelism to the build system if not env.GetOption('num_jobs'): env.SetOption('num_jobs', cpu_count() + 1) # Some environment tunnings so this runs faster env.Decider('MD5-timestamp') env.SConsignFile() # Let the default to do nothing env.Default() # Get the scons root path, this can be tricky because # scons can be ran with the -v option INSTALL_DIR = os.path.join(env.Dir('#').abspath, "install") if env.GetOption('buildtests'): PROJECTS_DIR = env.Dir('#/buildtests').abspath else: PROJECTS_DIR = env.Dir('#/projects').abspath vars.AddVariables( PathVariable('WS_DIR', 'workspace directory', PROJECTS_DIR, PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('BUILD_DIR', 'build directory', os.path.join(env.Dir('#').abspath, "build"), PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('INSTALL_BIN_DIR', 'install bin directory', os.path.join(INSTALL_DIR, "bin"), PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('INSTALL_HEADERS_DIR', 'install headers directory', os.path.join(INSTALL_DIR, "includes"), PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('INSTALL_LIB_DIR', 'install libs directory', os.path.join(INSTALL_DIR, "libs"), PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('INSTALL_DOC_DIR', 'install docs directory', os.path.join(INSTALL_DIR, "docs"), PathVariable.PathIsDirCreate)) vars.AddVariables( PathVariable('INSTALL_REPORTS_DIR', 'software reports directory', os.path.join(INSTALL_DIR, "reports"), PathVariable.PathIsDirCreate)) vars.Update(env) REPORT_DIR = env.Dir(env['INSTALL_REPORTS_DIR']).abspath vars.AddVariables( PathVariable('INSTALL_METRICS_DIR', 'software metrics directory', os.path.join(REPORT_DIR, "metrics"), PathVariable.PathIsDirCreate)) env.SetDefault(CPPCHECK_SUPPRESSION='') env.SetDefault(SPLINT_FLAGS='') vars.Update(env) if env.GetOption('exclude_headers'): env['exclude_headers'] = True if env.GetOption('verbose'): env.cdebug('Install information:') env.cdebug(' bin dir : ' + env['INSTALL_BIN_DIR']) env.cdebug(' lib dir : ' + env['INSTALL_LIB_DIR']) env.cdebug(' headers dir: ' + env['INSTALL_HEADERS_DIR']) env.cdebug(' doc dir : ' + env['INSTALL_DOC_DIR']) ## Replace the scons _concat function for mine. replace_scons_concat_function(env)