'CMake/KConfig header generation

I want to add configurability to some project to quickly iterate different settings. For this I wanted to use KConfig. I followed documentation online but besides writing the actual KConfig there is little information on how to use it within a build system like CMake and looking for reference did not yield a minimal example either: Github

main.cpp:

int main(){
    return CONFIG_RETURN_VALUE;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(example_project)

add_executable(example src/main.cpp)
target_compile_options(example PUBLIC -std=c++1y -Wall -Wfloat-conversion)
target_include_directories(example PUBLIC src/main)

KConfig:

menu "TestConfig"

config RETURN_VALUE
   int "Return value"
   default 15
   help
      The return value for main

endmenu

I generated a .conf file but I do not know how proceed from here. I know that there must be some step which will yield a autoconf.h file that can be included and will contain all the macro definitions, but how do I tell CMake to perform this "transformation"?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source