CMake Build System: Difference between revisions
No edit summary |
No edit summary |
||
| Line 35: | Line 35: | ||
* <code>unikernel.ld</code> Baseline unikernel configuration. Available for all boards.<br>.text/.rodata in Flash, .data/.bss/heap in internal RAM. | * <code>unikernel.ld</code> Baseline unikernel configuration. Available for all boards.<br>.text/.rodata in Flash, .data/.bss/heap in internal RAM. | ||
* <code>processes.ld</code> Baseline fluid kernel configuration.<br>.text/.rodata in Flash, .data/.bss/heap/process pool in internal RAM. | * <code>processes.ld</code> Baseline fluid kernel configuration.<br>.text/.rodata in Flash, .data/.bss/heap/process pool in internal RAM. | ||
* <code>unikernel-xram-heap.ld</code> Unikernel configuration using external RAM only for the heap.<br>.text/.rodata in Flash, .data/.bss in internal RAM, heap in external RAM. | * <code>unikernel-xram-heap.ld</code> Unikernel configuration using external RAM only for the heap.<br>.text/.rodata in Flash, .data/.bss in internal RAM, heap in external RAM. | ||
* <code>processes-xram.ld</code> Fluid kernel configuration using external RAM only for the process pool.<br>.text/.rodata in Flash, .data/.bss/heap in internal RAM, process pool in external RAM. | |||
* <code>unikernel-xram.ld</code> Unikernel configuration using external RAM.<br>.text/.rodata in Flash, .data/.bss/heap in external RAM. Internal RAM is used for a statically allocated IRQ stack (also used at boot before external RAM is enabled). | |||
* <code>processes-kernel-xram.ld</code> Fluid kernel configuration using external RAM exclusively.<br>.text/.rodata in Flash, .data/.bss/heap/process pool in external RAM. Internal RAM is used for a statically allocated IRQ stack (also used at boot before external RAM is enabled). | |||
* <code>unikernel-all-in-xram.ld</code> Unikernel configuration for loading Miosix entirely into external RAM with a bootloader.<br>All sections and the heap in external RAM. | * <code>unikernel-all-in-xram.ld</code> Unikernel configuration for loading Miosix entirely into external RAM with a bootloader.<br>All sections and the heap in external RAM. | ||
Some boards have additional linker scripts reserving parts of RAM for special purposes (i.e. Safeguard Memory, SGM). | |||
|- | |- | ||
| MIOSIX_USER_CONFIG_PATH || Path to the config directory of your application. The default is <code>${CMAKE_SOURCE_DIR}/config</code>. If this directory does not exist, the defaults will be picked up (as the default config is in the search path). | | MIOSIX_USER_CONFIG_PATH || Path to the config directory of your application. The default is <code>${CMAKE_SOURCE_DIR}/config</code>. If this directory does not exist, the defaults will be picked up (as the default config is in the search path). | ||
| Line 50: | Line 52: | ||
| MIOSIX_ENABLE_LINKER_GC || Enables linker garbage collection (<code>-ffunction-sections -fdata-sections</code>). Default is ON (which is recommended for optimal code size). | | MIOSIX_ENABLE_LINKER_GC || Enables linker garbage collection (<code>-ffunction-sections -fdata-sections</code>). Default is ON (which is recommended for optimal code size). | ||
|- | |- | ||
| | |} | ||
== Chip-defined internal variables == | |||
Each directory specific to a chip includes a CMakeLists.txt that defines a set of variables that describes that chip. This is the list of variables that these scripts need to define. | |||
{| class="wikitable" | |||
|- | |||
! Variable !! Explanation | |||
|- | |||
| MIOSIX_CPU_INC || Path of the directory with Miosix include files for the CPU in this chip. The source files associated with the correct CPU are included in the MIOSIX_CHIP_SRC variable. | |||
|- | |||
| MIOSIX_MULTILIB_PATH || Path of the GCC multilibs for this CPU. Use by clang/LLVM support, to be removed in the future. | |||
|- | |||
| MIOSIX_CPU_FLAGS || Compiler flags selecting the CPU. Passed to the C and C++ compilers, and to the assembler and the C++ compiler while linking too. | |||
|- | |||
| MIOSIX_CHIP_{C | CXX}_FLAGS || Additional flags for the chip. Usually includes a <code>-D_CHIP_{CHIP_NAME}</code> option to make Miosix aware of the chip choice. | |||
|- | |||
| MIOSIX_CHIP_SRC || List of chip and CPU specific files to be compiled with the Miosix kernel. | |||
|} | |} | ||
Latest revision as of 16:05, 10 August 2026
Miosix 3 introduces a new build system, based on CMake. The CMake build system has the same capabilities of the old Miosix Makefiles, and in addition it allows better composability of Miosix with other external projects.
How to build Miosix with CMake
Building Miosix with CMake follows the standard workflow that you expect from any other CMake project. Change directory to the root of the Miosix application you want to build and execute the following commands:
mkdir build cd build cmake .. make
These commands assume your CMake configuration uses Unix Makefiles as the default generator.
Creating a kernelspace project with CMake
Creating a userspace binary with CMake
Configuration options
The Miosix CMake build system provides the following options, that can be set via the command line or by your application's CMakeLists.txt.
| Variable | Explanation |
|---|---|
| MIOSIX_BOARD | Name of the board Miosix should be configured for. This variable has no default and must be set from the command line or from the application's CMake scripts. |
| MIOSIX_BOARD_VARIANT | Name of a board variant. A few boards define variants when there are jumpers, or different component fitting options, that are minor and do not warrant the definition of a different board. Default is the empty string, which is appropriate for most boards. |
| MIOSIX_LINKER_SCRIPT | The linker script to use when linking executables with Miosix using miosix_link_target(). The linker script choice also influences compiler options by adding/removing defines that are required for Miosix to work with that linker script.
The standard linker script choices are:
Some boards have additional linker scripts reserving parts of RAM for special purposes (i.e. Safeguard Memory, SGM). |
| MIOSIX_USER_CONFIG_PATH | Path to the config directory of your application. The default is ${CMAKE_SOURCE_DIR}/config. If this directory does not exist, the defaults will be picked up (as the default config is in the search path).
|
| MIOSIX_USER_BOARD_SETTINGS_PATH | Path to the config directory of the selected board. The default is ${MIOSIX_USER_CONFIG_PATH}/board/${MIOSIX_BOARD}. If this directory does not exist, the defaults will be picked up (as the default config is in the search path).
|
| MIOSIX_ASM_FLAGS MIOSIX_C_FLAGS MIOSIX_CXX_FLAGS MIOSIX_EXE_LINKER_FLAGS |
Additional configuration flags that are passed to the compiler but are not necessary to build the kernel. You can customize these flags to change the warning level of compilers or linkers. Their use is not recommended. |
| MIOSIX_DISABLE_EXCEPTIONS | When set to ON, exceptions are disabled. Reduces code size. Default is OFF. Always use this flag instead of adding -fno-exceptions to C(XX)FLAGS, as it enables extra flags required by Miosix.
|
| MIOSIX_ENABLE_LINKER_GC | Enables linker garbage collection (-ffunction-sections -fdata-sections). Default is ON (which is recommended for optimal code size).
|
Chip-defined internal variables
Each directory specific to a chip includes a CMakeLists.txt that defines a set of variables that describes that chip. This is the list of variables that these scripts need to define.
| Variable | Explanation |
|---|---|
| MIOSIX_CPU_INC | Path of the directory with Miosix include files for the CPU in this chip. The source files associated with the correct CPU are included in the MIOSIX_CHIP_SRC variable. |
| MIOSIX_MULTILIB_PATH | Path of the GCC multilibs for this CPU. Use by clang/LLVM support, to be removed in the future. |
| MIOSIX_CPU_FLAGS | Compiler flags selecting the CPU. Passed to the C and C++ compilers, and to the assembler and the C++ compiler while linking too. |
| MIOSIX_CHIP_{C | CXX}_FLAGS | Additional flags for the chip. Usually includes a -D_CHIP_{CHIP_NAME} option to make Miosix aware of the chip choice.
|
| MIOSIX_CHIP_SRC | List of chip and CPU specific files to be compiled with the Miosix kernel. |