From 84248221509670c132e96289dd9061b970499f00 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Sat, 15 Jun 2019 11:17:16 +0800 Subject: [PATCH 1/5] cmake: set CONFIG_DIR build property Add CONFIG_DIR as a build property, so that components don't have to derive it from one of the generated config files. --- components/esp32/CMakeLists.txt | 3 +-- components/esp_wifi/CMakeLists.txt | 3 ++- tools/cmake/component.cmake | 7 +++---- tools/cmake/kconfig.cmake | 1 + 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index abcc0ada17..9d763b41b9 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -70,8 +70,7 @@ else() #symbols in it. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_panic_highint_hdl") - idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER) - get_filename_component(config_dir ${sdkconfig_header} DIRECTORY) + idf_build_get_property(config_dir CONFIG_DIR) # Preprocess esp32.ld linker script to include configuration, becomes esp32_out.ld set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld) add_custom_command( diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index e4ba2db060..5349e905ac 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -44,11 +44,12 @@ if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION) # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy # the object file to a raw binary + idf_build_get_property(config_dir CONFIG_DIR) add_custom_command( OUTPUT ${phy_init_data_bin} DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h COMMAND ${CMAKE_C_COMPILER} -x c -c - -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${build_dir}/config + -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${config_dir} -o phy_init_data.obj ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin} diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 22b3528ec6..39b45a738f 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -427,8 +427,7 @@ function(idf_component_register) list(REMOVE_ITEM common_reqs ${component_lib}) link_libraries(${common_reqs}) - idf_build_get_property(sdkconfig_h SDKCONFIG_HEADER) - get_filename_component(sdkconfig_h ${sdkconfig_h} DIRECTORY) + idf_build_get_property(config_dir CONFIG_DIR) # The contents of 'sources' is from the __component_add_sources call if(sources OR __EMBED_FILES OR __EMBED_TXTFILES) @@ -436,14 +435,14 @@ function(idf_component_register) __component_set_property(${component_target} COMPONENT_TYPE LIBRARY) target_include_directories(${component_lib} PUBLIC ${__INCLUDE_DIRS}) target_include_directories(${component_lib} PRIVATE ${__PRIV_INCLUDE_DIRS}) - target_include_directories(${component_lib} PUBLIC ${sdkconfig_h}) + target_include_directories(${component_lib} PUBLIC ${config_dir}) set_target_properties(${component_lib} PROPERTIES OUTPUT_NAME ${COMPONENT_NAME}) __ldgen_add_component(${component_lib}) else() add_library(${component_lib} INTERFACE) __component_set_property(${component_target} COMPONENT_TYPE CONFIG_ONLY) target_include_directories(${component_lib} INTERFACE ${__INCLUDE_DIRS}) - target_include_directories(${component_lib} INTERFACE ${sdkconfig_h}) + target_include_directories(${component_lib} INTERFACE ${config_dir}) endif() # Alias the static/interface library created for linking to external targets. diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 28be99371e..08344e78d9 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -189,6 +189,7 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults) idf_build_set_property(SDKCONFIG_JSON ${sdkconfig_json}) idf_build_set_property(SDKCONFIG_CMAKE ${sdkconfig_cmake}) idf_build_set_property(SDKCONFIG_JSON_MENUS ${sdkconfig_json_menus}) + idf_build_set_property(CONFIG_DIR ${config_dir}) idf_build_get_property(menuconfig_depends __MENUCONFIG_DEPENDS) From 2fff500a1c60f44741c4279b6ad177eba6331438 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Sat, 15 Jun 2019 11:20:43 +0800 Subject: [PATCH 2/5] cmake: export IDF_TARGET to menuconfig Pass value of IDF_TARGET to menuconfig invocation. --- tools/cmake/kconfig.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 08344e78d9..97702935ee 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -205,6 +205,7 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults) "COMPONENT_KCONFIGS_PROJBUILD=${kconfig_projbuilds}" "IDF_CMAKE=y" "KCONFIG_CONFIG=${sdkconfig}" + "IDF_TARGET=${idf_target}" ${mconf} ${root_kconfig} # VERBATIM cannot be used here because it cannot handle ${mconf}="winpty mconf-idf" and the escaping must be # done manually From 64d37f5cb9d3e6b09bc37562c5bd9ad272516bab Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Sat, 15 Jun 2019 11:26:32 +0800 Subject: [PATCH 3/5] cmake: fix issues with build process Fix issue when COMPONENTS are is not specified for idf_build_process, no component is included in the build. --- tools/cmake/build.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 84f6f154fc..ff43ba1023 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -367,15 +367,20 @@ macro(idf_build_process target) __build_check_python() idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${target} APPEND) - __component_get_requirements() # Perform early expansion of component CMakeLists.txt in CMake scripting mode. # It is here we retrieve the public and private requirements of each component. # It is also here we add the common component requirements to each component's # own requirements. + __component_get_requirements() + + idf_build_get_property(component_targets __COMPONENT_TARGETS) # Finally, do component expansion. In this case it simply means getting a final list # of build component targets given the requirements set by each component. + + # Check if we need to trim the components first, and build initial components list + # from that. if(__COMPONENTS) unset(component_targets) foreach(component ${__COMPONENTS}) @@ -390,7 +395,7 @@ macro(idf_build_process target) foreach(component_target ${component_targets}) __build_expand_requirements(${component_target}) endforeach() - unset(__COMPONENT_TARGETS_SEEN) + idf_build_unset_property(__COMPONENT_TARGETS_SEEN) # Get a list of common component requirements in component targets form (previously # we just have a list of component names) From 7a19894aec84dd18ead58687212ff3fb4e15f6ea Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 17 Jun 2019 12:20:12 +0800 Subject: [PATCH 4/5] esptool_py: better display logs when generating binary Since OUTPUT argument of custom command does not currently support generator expressions, the project image is only generated as a side effect. The primary generated file is a timestamp file. Unfortunately as a consequence the output logs when the binary is about to be generated is not as helpful anymore. Set a custom comment that is more descriptive of what is happening, and provide more feedback as to what has been generated. --- components/esptool_py/project_include.cmake | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index d6c888f437..b847680c88 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -75,28 +75,33 @@ set(PROJECT_BIN "${elf_name}.bin") # # Add 'app.bin' target - generates with elf2image # -add_custom_command(OUTPUT "${build_dir}/.app_hash" +add_custom_command(OUTPUT "${build_dir}/.bin_timestamp" COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_ELF2IMAGE_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${unsigned_project_binary}" "${elf}" - COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${unsigned_project_binary}" > "${build_dir}/.app_hash" + COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${unsigned_project_binary}" + COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${unsigned_project_binary}" > "${build_dir}/.bin_timestamp" DEPENDS ${elf} VERBATIM WORKING_DIRECTORY ${build_dir} + COMMENT "Generating binary image from built executable" ) -add_custom_target(gen_project_binary DEPENDS "${build_dir}/.app_hash") +add_custom_target(gen_project_binary DEPENDS "${build_dir}/.bin_timestamp") if(NOT BOOTLOADER_BUILD AND CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES) # for locally signed secure boot image, add a signing step to get from unsigned app to signed app - add_custom_command(OUTPUT "${build_dir}/.signed_app_hash" + add_custom_command(OUTPUT "${build_dir}/.signed_bin_timestamp" COMMAND ${ESPSECUREPY} sign_data --keyfile ${secure_boot_signing_key} -o "${build_dir}/${PROJECT_BIN}" "${build_dir}/${unsigned_project_binary}" - COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${PROJECT_BIN}" > "${build_dir}/.signed_app_hash" - DEPENDS "${build_dir}/.app_hash" + COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${build_dir}/${PROJECT_BIN}" + "from ${build_dir}/${unsigned_project_binary}" + COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${PROJECT_BIN}" > "${build_dir}/.signed_bin_timestamp" + DEPENDS "${build_dir}/.bin_timestamp" VERBATIM + COMMENT "Generating signed binary image" ) - add_custom_target(gen_signed_project_binary DEPENDS "${build_dir}/.signed_app_hash") + add_custom_target(gen_signed_project_binary DEPENDS "${build_dir}/.signed_bin_timestamp") add_dependencies(gen_project_binary gen_signed_project_binary) endif() @@ -106,6 +111,7 @@ else() add_custom_target(bootloader ALL DEPENDS gen_project_binary) endif() + if(NOT BOOTLOADER_BUILD AND CONFIG_SECURE_BOOT_ENABLED AND NOT CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES) From 11924d76cb8b81c0b060bb1cd4b3a40ef44caff2 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 17 Jun 2019 12:14:02 +0800 Subject: [PATCH 5/5] cmake: clarify build trimming docs How idf_build_component and the COMPONENTS argument to idf_build_process interact is not clear/misleading. Clarify their interaction in the docs. Closes: https://github.com/espressif/esp-idf/issues/3630 --- docs/en/api-guides/build-system-cmake.rst | 10 ++++++++-- tools/cmake/build.cmake | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/en/api-guides/build-system-cmake.rst b/docs/en/api-guides/build-system-cmake.rst index 08f9e3a396..455149fec5 100644 --- a/docs/en/api-guides/build-system-cmake.rst +++ b/docs/en/api-guides/build-system-cmake.rst @@ -943,7 +943,10 @@ the first element/member instead. idf_build_component(component_dir) -Add a directory *component_dir* that contains a component to the build. +Present a directory *component_dir* that contains a component to the build system. Relative paths are converted to absolute paths with respect to current directory. +All calls to this command must be performed before `idf_build_process`. + +This command does not guarantee that the component will be processed during build (see the `COMPONENTS` argument description for `idf_build_process`) .. code-block:: none @@ -970,7 +973,10 @@ The call requires the target chip to be specified with *target* argument. Option - SDKCONFIG - output path of generated sdkconfig file; defaults to PROJECT_DIR/sdkconfig or CMAKE_SOURCE_DIR/sdkconfig depending if PROJECT_DIR is set - SDKCONFIG_DEFAULTS - defaults file to use for the build; defaults to empty - BUILD_DIR - directory to place ESP-IDF build-related artifacts, such as generated binaries, text files, components; defaults to CMAKE_BINARY_DIR -- COMPONENTS - starting components for trimming the build; components not in the list are automatically if they are required in the expanded dependency tree +- COMPONENTS - select components to process among the components known by the build system (added via `idf_build_component`). This argument is used to trim the build. + Other components are automatically added if they are required in the dependency chain, i.e. + the public and private requirements of the components in this list are automatically added, and in turn the public and private requirements of those requirements, + so on and so forth. If not specified, all components known to the build system are processed. .. code-block:: none diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index ff43ba1023..5383581f12 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -163,12 +163,14 @@ endfunction() # idf_build_component # -# @brief Specify component directory for the build system to process. +# @brief Present a directory that contains a component to the build system. # Relative paths are converted to absolute paths with respect to current directory. -# Any component that needs to be processed has to be specified using this -# command before calling idf_build_process. +# All calls to this command must be performed before idf_build_process. # -# @param[in] component_dir directory of the component to process +# @note This command does not guarantee that the component will be processed +# during build (see the COMPONENTS argument description for command idf_build_process) +# +# @param[in] component_dir directory of the component function(idf_build_component component_dir) idf_build_get_property(prefix __PREFIX) __component_add(${component_dir} ${prefix} 0) @@ -335,7 +337,16 @@ endfunction() # @param[in, optional] SDKCONFIG_DEFAULTS (single value) config defaults file to use for the build; defaults # to none (Kconfig defaults or previously generated config are used) # @param[in, optional] BUILD_DIR (single value) directory for build artifacts; defautls to CMAKE_BINARY_DIR -# @param[in, optional] COMPONENTS (multivalue) starting components for trimming build +# @param[in, optional] COMPONENTS (multivalue) select components to process among the components +# known by the build system +# (added via `idf_build_component`). This argument is used to trim the build. +# Other components are automatically added if they are required +# in the dependency chain, i.e. +# the public and private requirements of the components in this list +# are automatically added, and in +# turn the public and private requirements of those requirements, +# so on and so forth. If not specified, all components known to the build system +# are processed. macro(idf_build_process target) set(options) set(single_value PROJECT_DIR PROJECT_VER PROJECT_NAME BUILD_DIR SDKCONFIG SDKCONFIG_DEFAULTS)