Merge branch 'bugfix/misc_cmake_changes' into 'master'

Follow up CMake changes/fixes

See merge request idf/esp-idf!5267
This commit is contained in:
Angus Gratton 2019-06-21 13:27:55 +08:00
commit d1da76e369
7 changed files with 52 additions and 23 deletions

View File

@ -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(

View File

@ -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}

View File

@ -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)

View File

@ -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

View File

@ -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)
@ -367,15 +378,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 +406,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)

View File

@ -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.

View File

@ -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)
@ -204,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