CMake Build System: Difference between revisions

From Miosix Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 33: Line 33:
| MIOSIX_LINKER_SCRIPT || The linker script to use when linking executables with Miosix using <code>miosix_link_target()</code>. The linker script choice also influences compiler options by adding/removing defines that are required for Miosix to work with that linker script.
| MIOSIX_LINKER_SCRIPT || The linker script to use when linking executables with Miosix using <code>miosix_link_target()</code>. 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:
The standard linker script choices are:
{| class="wikitable"
* <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.
| unikernel.ld || Baseline unikernel configuration
* <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-xram.ld</code> Fluid kernel configuration using external RAM.<br>.text/.rodata in Flash, .data/.bss/heap/process pool in internal RAM, process pool 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>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.
|-
|-
| 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).

Revision as of 11:51, 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:

  • unikernel.ld Baseline unikernel configuration. Available for all boards.
    .text/.rodata in Flash, .data/.bss/heap in internal RAM.
  • processes.ld Baseline fluid kernel configuration.
    .text/.rodata in Flash, .data/.bss/heap/process pool in internal RAM.
  • unikernel-xram.ld Unikernel configuration using external RAM.
    .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.
  • processes-xram.ld Fluid kernel configuration using external RAM.
    .text/.rodata in Flash, .data/.bss/heap/process pool in internal RAM, process pool in external RAM.
  • unikernel-xram-heap.ld Unikernel configuration using external RAM only for the heap.
    .text/.rodata in Flash, .data/.bss in internal RAM, heap in external RAM.
  • unikernel-all-in-xram.ld Unikernel configuration for loading Miosix entirely into external RAM with a bootloader.
    All sections and the heap in external RAM.
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).