CMake Build System: Difference between revisions

From Miosix Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:
== Creating a userspace binary with CMake ==
== Creating a userspace binary with CMake ==


== Configuring a Miosix CMake project ==
== 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.
 
{| class="wikitable"
|-
! 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 <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:
{| class="wikitable"
|-
| unikernel.ld || Baseline unikernel configuration
|-
|}
|-
| 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_BOARD_SETTINGS_PATH || Path to the config directory of the selected board. The default is <code>${MIOSIX_USER_CONFIG_PATH}/board/${MIOSIX_BOARD}</code>. If this directory does not exist, the defaults will be picked up (as the default config is in the search path).
|-
| MIOSIX_ASM_FLAGS<br>MIOSIX_C_FLAGS<br>MIOSIX_CXX_FLAGS<br>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 <code>-fno-exceptions</code> to C(XX)FLAGS, as it enables extra flags required by Miosix.
|-
| MIOSIX_ENABLE_LINKER_GC || Enables linker garbage collection (<code>-ffunction-sections -fdata-sections</code>). Default is ON (which is recommended for optimal code size).
|-
|
|}

Revision as of 18:33, 9 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
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).