]> granicus.if.org Git - esp-idf/commitdiff
cmake: Add sdkconfig.defaults support
authorAngus Gratton <angus@espressif.com>
Mon, 22 Jan 2018 03:32:02 +0000 (14:32 +1100)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
tools/cmake/idf_functions.cmake
tools/cmake/kconfig.cmake
tools/kconfig_new/confgen.py

index d7f9bb2354d32601dfebe2743f303cd84583ca8e..101f8e10f38a6876429566c6b97f06a7092b6387 100644 (file)
@@ -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)
 
 
index d7ec6f4c386c3f77c7149d9357acb8e4594cc676..6d93ab19263e9cc48476baa17da540291e5019cc 100644 (file)
@@ -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})
 
index ca5ee63903efa442f6652e5a264e4c1581106dcf..00c92c3b66cade57ef3e1d7911d1bc1427a5f51c 100755 (executable)
@@ -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: