]> granicus.if.org Git - esp-idf/commitdiff
cmake: add command to get config value
authorRenz Christian Bagaporo <renz@espressif.com>
Thu, 9 May 2019 07:19:59 +0000 (15:19 +0800)
committerRenz Christian Bagaporo <renz@espressif.com>
Tue, 14 May 2019 10:01:14 +0000 (18:01 +0800)
docs/en/api-guides/build-system-cmake.rst
tools/cmake/build.cmake
tools/cmake/project.cmake

index 734588838f7c254cf2a7432ac6d0c5852c453be4..a3c068bf909b72e7ed7ae1c61ece0bd0f68628ed 100644 (file)
@@ -980,6 +980,14 @@ The call requires the target chip to be specified with *target* argument. Option
 Specify the executable *executable* for ESP-IDF build. This attaches additional targets such as dependencies related to
 flashing, generating additional binary files, etc. Should be called after ``idf_build_process``.
 
+.. code-block:: none
+
+  idf_build_get_config(var config [GENERATOR_EXPRESSION])
+
+Get the value of the specified config. Much like build properties, specifying
+*GENERATOR_EXPRESSION* will retrieve the generator expression string for that config, instead of the actual value, which
+can be used with CMake commands that support generator expressions. Actual config values are only known after call to `idf_build_process`, however.
+
 .. _cmake-build-properties:
 
 idf-build-properties
index 51bcfcd129603934e0175e86584dff2bb46d8fe2..bd2184977b32862b649244ab856db051bdb41b4d 100644 (file)
@@ -297,6 +297,23 @@ macro(__build_set_default var default)
     unset(_var)
 endmacro()
 
+#
+# Import configs as build instance properties so that they are accessible
+# using idf_build_get_config(). Config has to have been generated before calling
+# this command.
+#
+function(__build_import_configs)
+    # Include the sdkconfig cmake file, since the following operations require
+    # knowledge of config values.
+    idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
+    include(${sdkconfig_cmake})
+
+    idf_build_set_property(__CONFIG_VARIABLES "${CONFIGS_LIST}")
+    foreach(config ${CONFIGS_LIST})
+        set_property(TARGET __idf_build_target PROPERTY ${config} "${${config}}")
+    endforeach()
+endfunction()
+
 # idf_build_process
 #
 # @brief Main processing step for ESP-IDF build: config generation, adding components to the build,
@@ -349,6 +366,7 @@ macro(idf_build_process target)
     idf_build_get_property(sdkconfig SDKCONFIG)
     idf_build_get_property(sdkconfig_defaults SDKCONFIG_DEFAULTS)
     __kconfig_generate_config("${sdkconfig}" "${sdkconfig_defaults}")
+    __build_import_configs()
 
     # Write the partial build properties to a temporary file.
     # The path to this generated file is set to a short-lived build
@@ -468,4 +486,17 @@ function(idf_build_executable elf)
 
     # Add dependency of the build target to the executable
     add_dependencies(${elf} __idf_build_target)
+endfunction()
+
+# idf_build_get_config
+#
+# @brief Get value of specified config variable
+function(idf_build_get_config var config)
+    cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
+    if(__GENERATOR_EXPRESSION)
+        set(val "$<TARGET_PROPERTY:__idf_build_target,${config}>")
+    else()
+        get_property(val TARGET __idf_build_target PROPERTY ${config})
+    endif()
+    set(${var} ${val} PARENT_SCOPE)
 endfunction()
\ No newline at end of file
index 4522d0a2cff316054da209beeb7e3766c9e10535..d7bf90f05b19f01d2f1026852f55d2550cdba97d 100644 (file)
@@ -397,4 +397,15 @@ macro(project project_name)
     idf_build_executable(${project_elf})
 
     __project_info("${test_components}")
+
+    # Make build variables and config variables available after project call (of course the value
+    # of these variables can be accessed via idf_build_get_property or idf_build_get_config)
+    idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
+    include(${sdkconfig_cmake})
+
+    idf_build_get_property(build_properties __BUILD_PROPERTIES)
+    foreach(build_property ${build_properties})
+        idf_build_get_property(val ${build_property})
+        set(${build_property} "${val}")
+    endforeach()
 endmacro()