Using Kconfig configuration file

Overview

Kconfig configuration files allow you to specify a list of options to be set when configuring your application with CMake.

By default, the configuration file is named .config. However, the GWT SDK changes this default to sdk.config by setting the KCONFIG_CONFIG environment variable.

Although a configuration file is not mandatory, it can be quite helpful if your application requires specific settings to function properly.

Selecting a Configuration File

The SDK’s CMake process provides a way to manually choose a configuration file for your application, overriding the KCONFIG_CONFIG environment variable mechanism.

To do this, you can add the following argument to your CMake command:

cmake -B <build_directory> -DKCONFIG_CONFIG=<your_config_file>

Note

The KCONFIG_CONFIG variable set in the CMake command line is different from the KCONFIG_CONFIG environment variable, which is used to define the default configuration file name.

Behavior

Persistence

The specified configuration file name will be stored in CMake’s cache, meaning it will persist until the build directory is deleted, or the content of the KCONFIG_CONFIG variable is modified from command line.

Fast Override

The CMake command can be rerun with a different configuration file, which will replace the option list defined by the first file with the one from the second.

# Set option list to default value
cmake -B <build_directory>

# Override option list with values from the config file
cmake -B <build_directory> -DKCONFIG_CONFIG=my_config_file.config

or

# Set option list to default value
cmake -B <build_directory> -DKCONFIG_CONFIG=debug.config

# -> Will replace debug options by release ones
cmake -B <build_directory> -DKCONFIG_CONFIG=release.config

Reset to default sdk.config

Running the CMake command again without the -DKCONFIG_CONFIG=<your_config_file> argument won’t reset the value to its default (sdk.config). To do this, you must explicitly assign sdk.config to the KCONFIG_CONFIG variable from the command line, or delete the build directory. If you delete the build directory, be aware that unsaved menuconfig options will be lost.

Freezeconfig

After loading a configuration file, you can still modify the application settings using menuconfig. These modifications can be saved to the specified configuration file using the freezeconfig target.

# Initialize CMake with a specific configuration file
cmake -B <build_directory> -DKCONFIG_CONFIG=debug.config

# Modify the configuration options interactively
cmake --build <build_directory> --target menuconfig

# Save the changes to the previously specified configuration file
cmake --build <build_directory> --target freezeconfig