From: Angus Gratton Date: Mon, 22 Jan 2018 03:32:02 +0000 (+1100) Subject: cmake: Add sdkconfig.defaults support X-Git-Tag: v3.1-rc2~9^2~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f8e07fd8f083625d6e6a78a9a7d42d3e5dc5891;p=esp-idf cmake: Add sdkconfig.defaults support --- diff --git a/tools/cmake/idf_functions.cmake b/tools/cmake/idf_functions.cmake index d7f9bb2354..101f8e10f3 100644 --- a/tools/cmake/idf_functions.cmake +++ b/tools/cmake/idf_functions.cmake @@ -111,11 +111,12 @@ endfunction() # Sets up flash-related targets function(idf_add_executable) set(exe_target ${PROJECT_NAME}.elf) - - spaces2list(${MAIN_SRCS}) + + spaces2list(MAIN_SRCS) add_executable(${exe_target} "${MAIN_SRCS}") add_map_file(${exe_target}) + endfunction(idf_add_executable) diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index d7ec6f4c38..6d93ab1926 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -44,9 +44,23 @@ function(kconfig_process_config) endif() endforeach(dir ${COMPONENT_PATHS}) + if(EXISTS ${SDKCONFIG}.defaults) + set(defaults_arg --defaults "${SDKCONFIG}.defaults") + endif() + + set(confgen_basecommand + ${PYTHON} ${IDF_PATH}/tools/kconfig_new/confgen.py + --kconfig ${ROOT_KCONFIG} + --config ${SDKCONFIG} + ${defaults_arg} + --create-config-if-missing + --env "COMPONENT_KCONFIGS=${kconfigs}" + --env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}") + # Generate the menuconfig target (uses C-based mconf tool) add_custom_target(menuconfig DEPENDS mconf + COMMAND ${confgen_basecommand} --output config ${SDKCONFIG} # create any missing config file, with defaults if necessary COMMAND ${CMAKE_COMMAND} -E env "COMPONENT_KCONFIGS=${kconfigs}" "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" @@ -59,12 +73,7 @@ function(kconfig_process_config) # makes sdkconfig.h and skdconfig.cmake # # This happens at cmake runtime not during the build - execute_process(COMMAND python ${IDF_PATH}/tools/kconfig_new/confgen.py - --kconfig ${ROOT_KCONFIG} - --config ${SDKCONFIG} - --create-config-if-missing - --env "COMPONENT_KCONFIGS=${kconfigs}" - --env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" + execute_process(COMMAND ${confgen_basecommand} --output header ${SDKCONFIG_HEADER} --output cmake ${SDKCONFIG_CMAKE}) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index ca5ee63903..00c92c3b66 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -32,13 +32,18 @@ import kconfiglib __version__ = "0.1" def main(): - parser = argparse.ArgumentParser(description='confgen.py v%s - Config Generation Tool' % __version__, prog='conftool') + parser = argparse.ArgumentParser(description='confgen.py v%s - Config Generation Tool' % __version__, prog=os.path.basename(sys.argv[0])) parser.add_argument('--config', help='Project configuration settings', nargs='?', default=None) + parser.add_argument('--defaults', + help='Optional project defaults file, used if --config file doesn\'t exist', + nargs='?', + default=None) + parser.add_argument('--create-config-if-missing', help='If set, a new config file will be saved if the old one is not found', action='store_true') @@ -73,13 +78,20 @@ def main(): config = kconfiglib.Kconfig(args.kconfig) + if args.defaults is not None: + # always load defaults first, so any items which are not defined in that config + # will have the default defined in the defaults file + if not os.path.exists(args.defaults): + raise RuntimeError("Defaults file not found: %s" % args.defaults) + config.load_config(args.defaults) + if args.config is not None: if os.path.exists(args.config): config.load_config(args.config) elif args.create_config_if_missing: print("Creating config file %s..." % args.config) config.write_config(args.config) - else: + elif args.default is None: raise RuntimeError("Config file not found: %s" % args.config) for output_type, filename in args.output: