csbuild package

Module contents

Attention

To support CSBuild’s operation, Python’s import lock is DISABLED once CSBuild has started.

This should not be a problem for most makefiles, but if you do any threading within your makefile, take note: anything that’s imported and used by those threads should always be implemented on the main thread before that thread’s execution starts. Otherwise, CSBuild does not guarantee that the import will have completed once that thread tries to use it. Long story short: Don’t import modules within threads.

csbuild.AddCcCompilerFlags(*args)

Specifies a list of literal strings to be passed to the C compiler. As this is toolchain-specific, it should be called on a per-toolchain basis.

Parameters:args (an arbitrary number of strings) – The list of flags to be passed
csbuild.AddCompilerFlags(*args)

Specifies a list of literal strings to be passed to the both the C compiler and the C++ compiler. As this is toolchain-specific, it should be called on a per-toolchain basis.

Parameters:args (an arbitrary number of strings) – The list of flags to be passed
csbuild.AddCxxCompilerFlags(*args)

Specifies a list of literal strings to be passed to the C++ compiler. As this is toolchain-specific, it should be called on a per-toolchain basis.

Parameters:args (an arbitrary number of strings) – The list of flags to be passed
csbuild.AddDefines(*args)

Add additionally defined preprocessor directives, as if each file had a #define directive at the very top.

Parameters:args (an arbitrary number of strings) – The list of preprocessor directives to define
csbuild.AddExcludeDirectories(*args)

Exclude the given directories from the project. This may be called multiple times to add additional excludes. Directories are relative to the location of the script itself, not the specified project working directory.

Parameters:args (an arbitrary number of strings) – The list of directories to be excluded.
csbuild.AddExcludeFiles(*args)

Exclude the given files from the project. This may be called multiple times to add additional excludes. Files are relative to the location of the script itself, not the specified project working directory.

Parameters:args (an arbitrary number of strings) – The list of files to be excluded.
csbuild.AddExtraDirectories(*args)

Adds additional directories to search for files in.

Parameters:args (an arbitrary number of strings) – A list of directories to search.
csbuild.AddExtraFiles(*args)

Adds additional files to be compiled that are not in the project directory.

Parameters:args (an arbitrary number of strings) – A list of files to add.
csbuild.AddExtraObjects(*args)

Adds additional objects to be passed to the linker that are not in the project directory.

Parameters:args (an arbitrary number of strings) – A list of objects to add.
csbuild.AddFrameworkDirectories(*args)

Search the given directories for framworks to link. This may be called multiple times to add additional directories. Directories are relative to the location of the script itself, not the specified project working directory.

Parameters:args (an arbitrary number of strings) – The list of directories to be searched.
csbuild.AddFrameworks(*args)

Add frameworks for Objective-C/C++ compilations.

Parameters:args (an arbitrary number of strings) – The list of libraries to link in.
csbuild.AddIncludeDirectories(*args)

Search the given directories for include headers. This may be called multiple times to add additional directories. Directories are relative to the location of the script itself, not the specified project working directory.

In the gcc toolchain, /usr/include and /usr/local/include (or the platform appropriate equivalents) will always be appended to the end of this list.

Parameters:args (an arbitrary number of strings) – The list of directories to be searched.
csbuild.AddLibraries(*args)

When linking the project, link in the given libraries. This may be called multiple times to add additional libraries.

In the gcc toolchain, these will all be prefixed with “lib” when looking for the file to link. I.e., csbuild.Libraries(“MyLib”) will link libMyLib.so or libMyLib.a.

For compatibility, the msvc toolchain will search for the library exactly as specified, and if it can’t find it, will then search for it with the lib prefix. I.e., csbuild.Libraries(“MyLib”) will first search for MyLib.lib, and if that isn’t found, will then search for libMyLib.lib.

Parameters:args (an arbitrary number of strings) – The list of libraries to link in.
csbuild.AddLibraryDirectories(*args)

Search the given directories for libraries to link. This may be called multiple times to add additional directories. Directories are relative to the location of the script itself, not the specified project working directory.

In the gcc toolchain, /usr/lib and /usr/local/lib (or the platform appropriate equivalents) will always be appended to the end of this list.

Parameters:args (an arbitrary number of strings) – The list of directories to be searched.
csbuild.AddLinkerFlags(*args)

Specifies a list of literal strings to be passed to the linker. As this is toolchain-specific, it should be called on a per-toolchain basis.

Parameters:args (an arbitrary number of strings) – The list of flags to be passed
csbuild.AddOption(*args, **kwargs)

Adds an option to the argument parser. The syntax for this is identical to the ArgParse add_argument syntax; see the :argparse: documentation

csbuild.AddScript(incFile)

Include the given makefile script as part of this build process.

Attention

The included file will be loaded in the current file’s namespace, not a new namespace.

This doesn’t work the same way as importing a module. Any functions or variables defined in the current module will be available to the called script, and anything defined in the called script will be available to the calling module after it’s been called. As a result, this can be used much like #include in C++ to pull in utility scripts in addition to calling makefiles. The result is essentially as if the called script were copied and pasted directly into this one in the location of the AddScript() call.

Parameters:incFile (str) – path to an additional makefile script to call as part of this build
csbuild.AddSharedLibraries(*args)

Similar to csbuild.Libraries, but forces these libraries to be linked dynamically.

Parameters:args (an arbitrary number of strings) – The list of libraries to link in.
csbuild.AddStaticLibraries(*args)

Similar to csbuild.Libraries, but forces these libraries to be linked statically.

Parameters:args (an arbitrary number of strings) – The list of libraries to link in.
csbuild.AddUndefines(*args)

Add explicitly undefined preprocessor directives, as if each file had a #undef directive at the very top.

Parameters:args (an arbitrary number of strings) – The list of preprocessor directives to undefine
csbuild.ClearCcCompilerFlags()

Clears the list of literal C compiler flags.

csbuild.ClearChunks()

Clears the explicitly set list of chunks and returns the behavior to the default.

csbuild.ClearCompilerFlags()

Clears the list of literal compiler flags.

csbuild.ClearCxxCompilerFlags()

Clears the list of literal C++ compiler flags.

csbuild.ClearDefines()

Clear the list of defined preprocessor directives

csbuild.ClearExtraDirectories()

Clear the list of external directories to search.

csbuild.ClearExtraFiles()

Clear the list of external files to compile.

csbuild.ClearExtraObjects()

Clear the list of external objects to link.

csbuild.ClearIncludeDirectories()

Clears the include directories

csbuild.ClearLibraries()

Clears the list of libraries

csbuild.ClearLibraryDirectories()

Clears the library directories

csbuild.ClearLinkerFlags()

Clears the list of literal linker flags.

csbuild.ClearSharedibraries()

Clears the list of dynamically-linked libraries

csbuild.ClearStaticLibraries()

Clears the list of statically-linked libraries

csbuild.ClearUndefines()

Clear the list of undefined preprocessor directives

class csbuild.DebugLevel

Bases: object

Disabled = 0
EmbeddedSymbols = 1
ExternalSymbols = 2
ExternalSymbolsPlus = 3
csbuild.DisableChunkedBuild()

Turn off the chunked/unity build system and build using individual files.

csbuild.DisablePrecompile(*args)

Disables precompilation and handles headers as usual.

Parameters:args (an arbitrary number of strings) – A list of files to disable precompilation for.

If this list is empty, it will disable precompilation entirely.

csbuild.DisableProfiling()

Turns profiling optimizations back off

csbuild.DisableWarnings()

Disables all warnings.

csbuild.DisableWarningsAsErrors()

Disable the promotion of warnings to errors.

csbuild.DoNotChunk(*files)

Prevents the listed files (or files matching the listed patterns) from ever being placed in a chunk, ever.

Parameters:files (arbitrary number of strings) – filenames or patterns to exclude from chunking
csbuild.DoNotChunkTogether(pattern, *additionalPatterns)

Makes files matching the given patterns mutually exclusive for chunking. I.e., if you call this with DoNotChunkTogether(“File1.cpp”, “File2.cpp”), it guarantees File1 and File2 will never appear together in the same chunk. If you specify more than two files, or a pattern that matches more than two files, no two files in the list will ever appear together.

Parameters:
  • pattern (string) – Pattern to search for files with (i.e., Source/*_Unchunkable.cpp)
  • additionalPatterns (arbitrary number of optional strings) – Additional patterns to compile the list of mutually exclusive files with
csbuild.Done(code=0)

Exit the build process early

Parameters:code (int) – Exit code to exit with
csbuild.EnableChunkedBuild()

Turn chunked/unity build on and build using larger compilation units. This is the default.

csbuild.EnableChunkedPrecompile()

When this is enabled, all header files will be precompiled into a single “superheader” and included in all files.

csbuild.EnableHeaderInstall()

Enables installation of the project’s headers. Default target is /usr/local/include, unless the –prefix option is specified. If –prefix is specified, the target will be {prefix}/include

csbuild.EnableOutputInstall()

Enables installation of the compiled output file. The default installation directory is /usr/local/lib.

csbuild.EnableProfiling()

Optimize output for profiling

csbuild.EnableUnityBuild()

Turns on true unity builds, combining all files into only one compilation unit.

csbuild.EnableWarningsAsErrors()

Promote all warnings to errors.

csbuild.Exit(code=0)

Exit the build process early

Parameters:code (int) – Exit code to exit with
csbuild.GetArgDefault(argname)

Gets the default argument for the requested option

Parameters:argname (str) – the name of the option
csbuild.GetArgs()

Gets all of the arguments parsed by the argument parser.

Returns:an argparse.Namespace object
Return type:argparse.Namespace
csbuild.GetOption(option)

Retrieve the given option from the parsed command line arguments.

Parameters:option (str) – The name of the option, without any preceding dashes.

ArgParse replaces dashes with underscores, but csbuild will accept dashes and automatically handle the conversion internally.

Returns:The given argument, if it exists. If the argument has never been specified, returns csbuild.ARG_NOT_SET.

If –help has been specified, this will ALWAYS return csbuild.ARG_NOT_SET for user-specified arguments. Handle csbuild.ARG_NOT_SET to prevent code from being unintentionally run with –help.

csbuild.GetTargetList()

Get the list of targets currently being built.

If no target has been specified (the default is being used), this list is empty.

Returns:The list of targets
Return type:list[str]
csbuild.IgnoreExternalHeaders()

If this option is set, external headers will not be checked or followed when building. Only headers within the base project’s directory and its subdirectories will be checked. This will speed up header checking, but if you modify any external headers, you will need to manually –clean or –rebuild the project.

Bases: object

csbuild.LinkSharedRuntime()

Link against a dynamic C/C++ runtime library.

csbuild.LinkStaticRuntime()

Link against a static C/C++ runtime library.

csbuild.NoBuiltInTargets()

Disable the built-in “debug” and “release” targets.

class csbuild.OptimizationLevel

Bases: object

Disabled = 0
Max = 3
Size = 1
Speed = 2
csbuild.Precompile(*args)

Explicit list of header files to precompile. Disables chunk precompile when called.

Parameters:args (an arbitrary number of strings) – The files to precompile.
csbuild.PrecompileAsC(*args)

Specifies header files that should be compiled as C headers instead of C++ headers.

Parameters:args (an arbitrary number of strings) – The files to specify as C files.
class csbuild.ProjectType

Bases: object

Specifies the type of project to compile

Application = 0
SharedLibrary = 1
StaticLibrary = 2
csbuild.RegisterProjectGenerator(name, generator)

Register a new project generator for use in solution generation.

Parameters:
csbuild.RegisterToolchain(name, compiler, linker)

Register a new toolchain for use in the project.

Parameters:
class csbuild.ScopeDef

Bases: object

All = 7
DependentsOnly = 6
Final = 4
Intermediate = 2
Self = 1
csbuild.SetActiveToolchain(name)

Sets the active toolchain to be used when building the project.

On Windows platforms, this is set to msvc by default. On Linux platforms, this is set to gcc by default.

This will be overridden if the script is executed with the –toolchain option.

Parameters:name (str) – The toolchain to use to build the project
csbuild.SetCcCommand(s)

Specify the compiler executable to be used for compiling C files. Ignored by the msvc toolchain.

Parameters:s (str) – Path to the executable to use for compilation
csbuild.SetChunkTolerance(i)

Please see detailed description.

If building using ChunkSize():

Set the number of modified files below which a chunk will be split into individual files.

For example, if you set this to 3 (the default), then a chunk will be built as a chunk if more than three of its files need to be built; if three or less need to be built, they will be built individually to save build time.

If building using ChunkFilesize():

Sets the total combined filesize of modified files within a chunk below which the chunk will be split into individual files.

For example, if you set this to 150000 (the default), then a chunk will be built as a chunk if the total filesize of the files needing to be built exceeds 150kb. If less than 150kb worth of data needs to be built, they will be built individually to save time.

Parameters:i (int) – Number of files required to trigger chunk building.
csbuild.SetChunks(*chunks)

Explicitly set the chunks used as compilation units.

NOTE that setting this will disable the automatic file gathering, so any files in the project directory that are not specified here will not be built.

Parameters:chunks (an arbitrary number of lists of strings) – Lists containing filenames of files to be built,

relativel to the script’s location, NOT the project working directory. Each list will be built as one chunk.

csbuild.SetCxxCommand(s)

Specify the compiler executable to be used for compiling C++ files. Ignored by the msvc toolchain.

Parameters:s (str) – Path to the executable to use for compilation
csbuild.SetDebugLevel(i)

Sets the debug level. Due to toolchain differences, this should be called per-toolchain, usually.

Parameters:i (DebugLevel) – How (and if) symbols should be generated
csbuild.SetDefaultTarget(s)

Sets the default target if none is specified. The default value for this is release.

Parameters:s (str) – Name of the target to build for this project if none is specified.
csbuild.SetHeaderInstallSubdirectory(s)

Specifies a subdirectory of {prefix}/include in which to install the headers.

Parameters:s (str) – The desired subdirectory; i.e., if you specify this as “myLib”, the headers will be

installed under {prefix}/include/myLib.

csbuild.SetHeaderRecursionDepth(i)

Sets the depth to search for header files. If set to 0, it will search with unlimited recursion to find included headers. Otherwise, it will travel to a depth of i to check headers. If set to 1, this will only check first-level headers and not check headers included in other headers; if set to 2, this will check headers included in headers, but not headers included by those headers; etc.

This is very useful if you’re using a large library (such as boost) or a very large project and are experiencing long waits prior to compilation.

Parameters:i (int) – Recursion depth for header examination
csbuild.SetIntermediateDirectory(s)

Specifies the directory in which to place the intermediate .o or .obj files.

Parameters:s (str) – The object directory, relative to the current script location, NOT to the project working directory.
csbuild.SetMaxChunkFileSize(i)

Sets the maximum combined filesize for a chunk. The default is 500000, and this is the default behavior.

This value is ignored if SetChunks is called.

Mutually exclusive with ChunkNumFiles()

Parameters:i (int) – Maximum size per chunk in bytes.
csbuild.SetNumFilesPerChunk(i)

Set the size of the chunks used in the chunked build. This indicates the number of files per compilation unit. The default is 10.

This value is ignored if SetChunks is called.

Mutually exclusive with ChunkFilesize().

Parameters:i (int) – Number of files per chunk
csbuild.SetOptimizationLevel(i)

Sets the optimization level. Due to toolchain differences, this should be called per-toolchain, usually.

Parameters:i (OptimizationLevel) – The level of optimization to use
csbuild.SetOutput(name, projectType=0)

Sets the output options for this project.

Parameters:name (str) – The output name. Do not include an extension, and do not include the “lib” prefix for libraries on

Linux. These are added automatically.

Parameters:projectType (csbuild.ProjectType) – The type of project to compile. The options are: - ProjectType.Application - on Windows, this will be built with a .exe extension. On Linux, there is no extension. - ProjectType.SharedLibrary - on Windows, this will generate a .lib and a .dll. On Linux, this will generate a .so and prefix “lib” to the output name. - ProjectType.StaticLibrary - on Windows, this will generate a .lib. On Linux, this will generate a .a and prefix “lib” to the output name.
csbuild.SetOutputArchitecture(arch)

Set the output architecture.

Parameters:arch (str) – The desired architecture. Choose from x86, x64, ARM.
csbuild.SetOutputDirectory(s)

Specifies the directory in which to place the output file.

Parameters:s (str) – The output directory, relative to the current script location, NOT to the project working directory.
csbuild.SetOutputExtension(name)

This allows you to override the extension used for the output file.

Parameters:name (str) – The desired extension, including the .; i.e., csbuild.Extension( ”.exe” )
csbuild.SetStaticLinkMode(mode)

Determines how static links are handled. With the msvc toolchain, iterative link times of a project with many libraries can be significantly improved by setting this to :StaticLinkMode.LinkLibs:. This will cause the linker to link the .obj files used to make a library directly into the dependent project. Link times for full builds may be slightly slower, but this will allow incremental linking to function when libraries are being changed. (Usually, changing a .lib results in a full link.)

On most toolchains, this defaults to :StaticLinkMode.LinkLibs:. In debug mode only for the msvc toolchain, this defaults to :StaticLinkMode.LinkIntermediateObjects:.

Parameters:mode – The link mode to set
csbuild.SetSupportedArchitectures(*architectures)

Specifies the architectures that this project supports. This can be used to limit –all-architectures from building everything supported by the toolchain, if the project is not set up to support all of the toolchain’s architectures.

csbuild.SetSupportedToolchains(*toolchains)

Specifies the toolchains that this project supports. This can be used to limit –all-toolchains from building everything supported by csbuild, if the project is not set up to support all of the toolchains.

csbuild.SetUserData(key, value)

Adds miscellaneous data to a project. This can be used later in a build event or in a format string.

This becomes an attribute on the project’s userData member variable. As an example, to set a value:

csbuild.SetUserData(“someData”, “someValue”)

Then to access it later:

project.userData.someData

Parameters:
  • key (str) – name of the variable to set
  • value (any) – value to set to that variable
csbuild.SetupDebugTarget()

Default debug target.

csbuild.SetupReleaseTarget()

Default release target.

class csbuild.Src(libName, scope=4, includeToolchains=None, includeArchitectures=None, excludeToolchains=None, excludeArchitectures=None)

Bases: object

class csbuild.StaticLinkMode

Bases: object

LinkIntermediateObjects = 1
LinkLibs = 0
csbuild.StopOnFirstError()

Stop compilation when the first error is encountered.

csbuild.Toolchain(*args)

Perform actions on the listed toolchains. Examples:

csbuild.Toolchain(“gcc”).NoPrecompile() csbuild.Toolchain(“gcc”, “msvc”).EnableWarningsAsErrors()

Parameters:args (arbitrary number of strings) – The list of toolchains to act on
Returns:A proxy object that enables functions to be applied to one or more specific toolchains.
csbuild.architecture(archs, override=False)

Specifies settings for a specific list of architectures.

csbuild.fileSettings(files, override=False)

Specifies settings that affect a single specific file

Parameters:
  • files (str or list[str]) – The file or files to apply these settings to
  • override (bool) – If this is true, existing functionality for this target will be discarded for this project.
csbuild.postBuildStep(func)

Decorator that creates a post-build step for the containing project. Post-build steps run after the project has successfully compiled and linked.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.postMakeStep(func)

Decorator that creates a post-make step for the containing project. Post-make steps run after all projects have finished building and linking. This step will only run if the entire build process was successful.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.postPrepareBuildStep(func)

Decorator that creates a post-compile step for the containing project. Post-PrepareBuild steps run just after the project completes its build preparation. This is the only place where running project.RediscoverFiles() has any appreciable effect.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.preBuildStep(func)

Decorator that creates a pre-build step for the containing project. Pre-build steps run just before the project begins compiling.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.preLinkStep(func)

Decorator that creates a pre-link step for the containing project. Pre-link steps run after a successful compile of the project, but before the project links.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.preMakeStep(func)

Decorator that creates a pre-make step for the containing project. Pre-make steps run after all projects’ preparation steps have completed and their final chunk sets have been collected, but before any compiling starts.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.prePrepareBuildStep(func)

Decorator that creates a pre-build step for the containing project. Pre-PrepareBuild steps run just before the project begins preparing its build tasks.

Parameters:func ((Implicit) function) – (Implicit) The function wrapped by this decorator

Note

The function this wraps should take a single argument, which will be of type csbuild.projectSettings.projectSettings.

csbuild.project(name, workingDirectory, depends=None, priority=-1, ignoreDependencyOrdering=False)

Decorator used to declare a project. linkDepends and srcDepends here will be used to determine project build order.

Parameters:
  • name (str) – A unique name to be used to refer to this project
  • workingDirectory (str) – The directory in which to perform build operations. This directory

(or a subdirectory) should contain the project’s source files.

Parameters:linkDepends – A list of other projects. This project will not be linked until the dependent projects

have completed their build process. These can be specified as either projName, Link(projName, scope), or Src(projName, scope).

projName will be converted to Link(projName, ScopeDef.Final) Link will cause the project it applies to to link this dependency. Src will cause the project it applies to to wait until this project finishes before it starts its build at all.

csbuild.projectGroup(name)

Specifies a grouping of projects. This will add scope to the global project settings, and will additionally be used in solution generation to group the projects.

Parameters:name (str) – The name to identify this project group
csbuild.scope(scope)
csbuild.target(name, override=False)

Specifies settings for a target. If the target doesn’t exist it will be implicitly created. If a target does exist with this name, this function will be appended to a list of functions to be run for that target name, unless override is True.

Parameters:
  • name (str) – The name for the target; i.e., “debug”, “release”
  • override (bool) – If this is true, existing functionality for this target will be discarded for this project.

Table Of Contents

This Page