The [build] section is where to change compilation settings.
Example:
[build]
sources = ["src"]
includes = ["include", "some_lib/include"]
[build.flags]
c = ["<default>", "-DMY_DEFINE=1"]
rust = ["<default>", "-Zub-checks=yes"]
cargo = ["<default>", "--features", "my-feature"]
The root of a particular project is the directory that contains the config (Megaton.toml). For all values that determine a path, unless otherwise specified, the path is relative to the project root.
For each key, if a default value/behavior is not specified, it is required in the config. Otherwise it is optional.
This section can be extended with profiles.
Key: build.sources
Type: string[] (array of strings)
Paths to source directories to recursively scan for C/C++/Assembly source files. Sources generated by Megaton are automatically included and do not need to be specified. If the mod contains only Rust code, this can be omitted. Sources will be detected and matched based on file extension. The following extensions will be detected:
- C:
.c - C++:
.cc,.c++,.cpp - Assembly:
.s,.asm
Inheritance: Append
Default: []
Key: build.includes
Type: string[] (array of strings)
Paths to include directories to be passed to the compiler as -I flags. Headers generated by Megaton (including headers from the Megaton library) are automatically included and do not need to be specified.
Inheritance: Append
Default: []
Key: build.libpaths
Type: string[] (array of strings)
Paths to library directories to be passed to the compiler as -L flags.
Inheritance: Append
Default: []
Key: build.libraries
Type: string[] (array of strings)
Libraries to be linked. These will be passed as -l flags to the linker. The names of libraries here must be discoverable in the directories specified in build.libpaths. For example, to link the library “foo”, add “foo” to this array and place the file libfoo.so in one of the library paths.
Inheritance: Append
Default: []
Key: build.objects
Type: string[] (array of strings)
Additional .o and .a objects to link with, i.e. compiled objects that are not generated by Megaton.
Inheritance: Append
Default: []
Key: build.flags
Build flags to pass to the different tools on the build toolchain. All flags keys have the same inheritance behavior of Override.
In order to add a build flag, specify the value like this: [<"default">, -DDEBUG]. If the value is specified as [], The default flags will be disabled for that profile.
The default flags can be found here, and the flag extension behavior is detailed below.
| Property | <default> includes |
|---|---|
common | None |
c | common |
cxx | c |
as | cxx |
ld | common |
rust | None |
cargo | None |
For this flag config:
[build.flags]
c = ["<default>", "-DDEBUG"]
-DDEBUG will be added to the flags when invoking gcc
(using C flags), g++ (using CXX flags, extended from C flags), and as (using AS flags, extended from CXX flags).
Inheritance: Override
Default: ["<default>"]
Key: build.flags.common
Flags for all tools except rust and cargo.
Key: build.flags.c
Flags for the C compiler.
Key: build.flags.cxx
Flags for the C++ compiler.
Key: build.flags.as
Flags for the assembler to use with assembly sources.
Key: build.flags.ld
Flags for the linker.
C++ compiler is used for linking. Flags for ld
should be specified as -Wl,--flag instead of --flag.
Key: build.flags.rust
Flags for rust. Corresponds to the RUSTFLAGS environment variable. Rust flags can also be specified in Cargo.toml, but placing them here allows them to be dynamically enabled using Megaton’s profile system.
Restrictions: Can only be specified if cargo.enabled = true
Key: build.flags.cargo
Flags to be passed to cargo, such as feature flags.
Restrictions: Can only be specified if cargo.enabled = true