From 4c9f30a869740ce94283b4f774df099e00d1210d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 9 Aug 2019 12:30:23 +0800 Subject: [PATCH 01/11] cmake: set component properties --- tools/ci/test_build_system_cmake.sh | 8 ++++++++ tools/cmake/component.cmake | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 5b2828d84..bbe299b92 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -510,6 +510,14 @@ endmenu\n" >> ${IDF_PATH}/Kconfig; mv CMakeLists.txt.bak CMakeLists.txt rm -rf CMakeLists.txt.bak + print_status "Component properties are set" + clean_build_dir + cp CMakeLists.txt CMakeLists.txt.bak + printf "\nidf_component_get_property(srcs main SRCS)\nmessage(STATUS SRCS:\${srcs})" >> CMakeLists.txt + (idf.py reconfigure | grep "SRCS:$(realpath main/main.c)") || failure "Component properties should be set" + rm -rf CMakeLists.txt + mv CMakeLists.txt.bak CMakeLists.txt + rm -rf CMakeLists.txt.bak print_status "All tests completed" if [ -n "${FAILURES}" ]; then diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 6959af26c..21950dee9 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -479,6 +479,8 @@ function(idf_component_register) # COMPONENT_TARGET is deprecated but is made available with same function # as COMPONENT_LIB for compatibility. set(COMPONENT_TARGET ${component_lib} PARENT_SCOPE) + + __component_set_properties() endfunction() # From 6781d01e895e9befde737863b5650110b287e9eb Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 9 Aug 2019 16:35:31 +0800 Subject: [PATCH 02/11] cmake: fix encrypted project flash arg file generation --- components/esptool_py/flash_encrypted_project_args.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esptool_py/flash_encrypted_project_args.in b/components/esptool_py/flash_encrypted_project_args.in index db16bc6cd..a1875e69e 100644 --- a/components/esptool_py/flash_encrypted_project_args.in +++ b/components/esptool_py/flash_encrypted_project_args.in @@ -1,3 +1,3 @@ --encrypt ${ESPTOOLPY_FLASH_PROJECT_OPTIONS} -$, +$ From c34d313a86f235bb72b958bf14b79d139dcb947a Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 12 Aug 2019 20:32:14 +0800 Subject: [PATCH 03/11] mbedtls: add source files to appropriate library --- components/mbedtls/CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt index 5cfac4d9b..20e0a38f0 100644 --- a/components/mbedtls/CMakeLists.txt +++ b/components/mbedtls/CMakeLists.txt @@ -19,17 +19,18 @@ set_property(TARGET mbedtls PROPERTY SOURCES ${src_tls}) set(mbedtls_targets mbedtls mbedcrypto mbedx509) # Add port files to mbedtls targets -target_sources(mbedtls PRIVATE "${COMPONENT_DIR}/port/esp_bignum.c" +target_sources(mbedtls PRIVATE "${COMPONENT_DIR}/port/mbedtls_debug.c" + "${COMPONENT_DIR}/port/net_sockets.c") + +target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_bignum.c" "${COMPONENT_DIR}/port/esp_hardware.c" - "${COMPONENT_PATH}/port/esp_sha.c" + "${COMPONENT_DIR}/port/esp_mem.c" + "${COMPONENT_DIR}/port/esp_sha.c" "${COMPONENT_DIR}/port/esp_sha1.c" "${COMPONENT_DIR}/port/esp_sha256.c" "${COMPONENT_DIR}/port/esp_sha512.c" - "${COMPONENT_DIR}/port/mbedtls_debug.c" - "${COMPONENT_DIR}/port/net_sockets.c" "${COMPONENT_DIR}/port/esp32/aes.c" "${COMPONENT_DIR}/port/esp32/sha.c") -target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_mem.c") foreach(target ${mbedtls_targets}) target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h") From 8778c551ebd8ee98ee415311928d3f51f69f9fad Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 16 Aug 2019 17:46:50 +0800 Subject: [PATCH 04/11] cmake: set build dir for mconf-idf Fixes an issue where if idf_build_process is called in a CMake subdirectory, menuconfig looks for the mconf-idf binary in the wrong place (in the subdirectory build dir instead of root binary dir). --- tools/cmake/kconfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index d1d34234d..872e0d44d 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -47,7 +47,7 @@ function(__kconfig_init) externalproject_add(mconf-idf SOURCE_DIR ${src_path} CONFIGURE_COMMAND "" - BINARY_DIR "kconfig_bin" + BINARY_DIR "${CMAKE_BINARY_DIR}/kconfig_bin" BUILD_COMMAND rm -f ${src_path}/zconf.lex.c ${src_path}/zconf.hash.c COMMAND make -f ${src_path}/Makefile mconf-idf BUILD_BYPRODUCTS ${MCONF} From b669495d97e8c19d54d5765c7d41408746c22aee Mon Sep 17 00:00:00 2001 From: Per Malmberg Date: Tue, 20 Aug 2019 20:56:24 +0200 Subject: [PATCH 05/11] Make sure ESP_PLATFORM is defined when processing CMake files. --- tools/cmake/component.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 21950dee9..bca102d60 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -213,6 +213,7 @@ function(__component_get_requirements) __component_write_properties(${component_properties_file}) execute_process(COMMAND "${CMAKE_COMMAND}" + -D "ESP_PLATFORM=1" -D "BUILD_PROPERTIES_FILE=${build_properties_file}" -D "COMPONENT_PROPERTIES_FILE=${component_properties_file}" -D "COMPONENT_REQUIRES_FILE=${component_requires_file}" From 520ecb0c4d145f0eeb3ffeb9c944f8886427bea5 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 27 Aug 2019 10:26:34 +0800 Subject: [PATCH 06/11] ldgen: fix build issue on make when build dir is a symlink Fixes an issue where build fails if the build directory is a symlink. The issue is caused by the rule target and the final executable dependency not matching. Closes https://github.com/espressif/esp-idf/issues/3626 --- components/esp32/Makefile.projbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp32/Makefile.projbuild b/components/esp32/Makefile.projbuild index cf8746f26..d13dbe2d0 100644 --- a/components/esp32/Makefile.projbuild +++ b/components/esp32/Makefile.projbuild @@ -10,7 +10,7 @@ ifneq ("$(filter esp32,$(TEST_COMPONENTS_LIST))","") CPPFLAGS += -DESP_TIMER_DYNAMIC_OVERFLOW_VAL endif ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32.project.ld.in -ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(abspath $(BUILD_DIR_BASE)/esp32) +ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(realpath $(BUILD_DIR_BASE)/esp32) # Target to generate linker script generator from fragments presented by each of # the components From b6c89984a9477f36b2dcd0176fbe0846d44c6cfe Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 27 Aug 2019 09:24:17 +0800 Subject: [PATCH 07/11] cmake: fix build failure when git repo is initialized but no first commit Closes https://github.com/espressif/esp-idf/issues/3920 --- tools/cmake/project.cmake | 6 +++--- .../third_party/GetGitRevisionDescription.cmake.in | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index ff9b75ec6..36b331313 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -38,9 +38,9 @@ function(__project_get_revision var) if(PROJECT_VER_GIT) set(PROJECT_VER ${PROJECT_VER_GIT}) else() - message(STATUS "Project is not inside a git repository, \ - will not use 'git describe' to determine PROJECT_VER.") - set(PROJECT_VER "1") + message(STATUS "Project is not inside a git repository, or git repository has no commits;" + " will not use 'git describe' to determine PROJECT_VER.") + set(PROJECT_VER 0) endif() endif() endif() diff --git a/tools/cmake/third_party/GetGitRevisionDescription.cmake.in b/tools/cmake/third_party/GetGitRevisionDescription.cmake.in index 6d8b708ef..0cf025b14 100644 --- a/tools/cmake/third_party/GetGitRevisionDescription.cmake.in +++ b/tools/cmake/third_party/GetGitRevisionDescription.cmake.in @@ -24,10 +24,12 @@ if(HEAD_CONTENTS MATCHES "ref") if(EXISTS "@GIT_DIR@/${HEAD_REF}") configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) else() - configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) - file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) - if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") - set(HEAD_HASH "${CMAKE_MATCH_1}") + if(EXISTS "@GIT_DIR@/packed-refs") + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() endif() endif() else() From f62798cb8b1325f5d0be067417a35b9dbf620b35 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Wed, 21 Aug 2019 12:43:19 +0800 Subject: [PATCH 08/11] cmake: make default version 1 --- docs/en/api-guides/build-system.rst | 2 +- tools/cmake/build.cmake | 4 ++-- tools/cmake/project.cmake | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 8a28a1e16..e432f8686 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -973,7 +973,7 @@ The call requires the target chip to be specified with *target* argument. Option - PROJECT_DIR - directory of the project; defaults to CMAKE_SOURCE_DIR - PROJECT_NAME - name of the project; defaults to CMAKE_PROJECT_NAME -- PROJECT_VER - version/revision of the project; defaults to "0.0.0" +- PROJECT_VER - version/revision of the project; defaults to "1" - 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 diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 5383581f1..c9088ba86 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -330,7 +330,7 @@ endfunction() # @param[in, optional] PROJECT_DIR (single value) directory of the main project the buildsystem # is processed for; defaults to CMAKE_SOURCE_DIR # @param[in, optional] PROJECT_VER (single value) version string of the main project; defaults -# to 0.0.0 +# to 1 # @param[in, optional] PROJECT_NAME (single value) main project name, defaults to CMAKE_PROJECT_NAME # @param[in, optional] SDKCONFIG (single value) sdkconfig output path, defaults to PROJECT_DIR/sdkconfig # if PROJECT_DIR is set and CMAKE_SOURCE_DIR/sdkconfig if not @@ -366,7 +366,7 @@ macro(idf_build_process target) __build_set_default(PROJECT_DIR ${CMAKE_SOURCE_DIR}) __build_set_default(PROJECT_NAME ${CMAKE_PROJECT_NAME}) - __build_set_default(PROJECT_VER "0.0.0") + __build_set_default(PROJECT_VER 1) __build_set_default(BUILD_DIR ${CMAKE_BINARY_DIR}) idf_build_get_property(project_dir PROJECT_DIR) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 36b331313..3deb01488 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -40,7 +40,7 @@ function(__project_get_revision var) else() message(STATUS "Project is not inside a git repository, or git repository has no commits;" " will not use 'git describe' to determine PROJECT_VER.") - set(PROJECT_VER 0) + set(PROJECT_VER 1) endif() endif() endif() From 3f1ec39a8d184597a7949d02e6fb78c97d62fd3d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Wed, 21 Aug 2019 12:00:55 +0800 Subject: [PATCH 09/11] cmake: fix issue with checking build process args --- tools/cmake/build.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index c9088ba86..9285a53e1 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -295,7 +295,7 @@ endmacro() # macro(__build_set_default var default) set(_var __${var}) - if(${_var}) + if(NOT "${_var}" STREQUAL "") idf_build_set_property(${var} "${${_var}}") else() idf_build_set_property(${var} "${default}") From c711e969cc2e755678ea6828b5b1bbd19185c04c Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 6 Aug 2019 11:00:37 +0800 Subject: [PATCH 10/11] components: fix incorrect include dir args --- components/esp-tls/CMakeLists.txt | 2 +- components/tcp_transport/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esp-tls/CMakeLists.txt b/components/esp-tls/CMakeLists.txt index f6cc17c80..ea6b61216 100644 --- a/components/esp-tls/CMakeLists.txt +++ b/components/esp-tls/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRCS "esp_tls.c" INCLUDE_DIRS "." - PRIVATE_INCLUDE_DIRS "private_include" + PRIV_INCLUDE_DIRS "private_include" REQUIRES mbedtls PRIV_REQUIRES lwip nghttp) diff --git a/components/tcp_transport/CMakeLists.txt b/components/tcp_transport/CMakeLists.txt index 9d5028a1b..fe7e71bf3 100644 --- a/components/tcp_transport/CMakeLists.txt +++ b/components/tcp_transport/CMakeLists.txt @@ -5,5 +5,5 @@ idf_component_register(SRCS "transport.c" "transport_utils.c" "transport_strcasestr.c" INCLUDE_DIRS "include" - PRIVATE_INCLUDE_DIRS "private_include" + PRIV_INCLUDE_DIRS "private_include" REQUIRES lwip esp-tls) From e71e4da38832a3ee603790c2feef7fc57256185d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 6 Aug 2019 10:59:48 +0800 Subject: [PATCH 11/11] cmake: check include directories --- tools/cmake/component.cmake | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index bca102d60..e25a758a1 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -233,10 +233,10 @@ function(__component_get_requirements) file(REMOVE ${component_requires_file}) endfunction() -# __component_add_sources, __component_check_target +# __component_add_sources, __component_check_target, __component_add_include_dirs # -# Utility macros for component registration. Adds source files and checks target requirements -# respectively. +# Utility macros for component registration. Adds source files and checks target requirements, +# and adds include directories respectively. macro(__component_add_sources sources) set(sources "") if(__SRCS) @@ -280,6 +280,16 @@ macro(__component_add_sources sources) list(REMOVE_DUPLICATES sources) endmacro() +macro(__component_add_include_dirs lib dirs type) + foreach(dir ${dirs}) + get_filename_component(_dir ${dir} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_LIST_DIR}) + if(NOT IS_DIRECTORY ${_dir}) + message(FATAL_ERROR "Include directory '${_dir}' is not a directory.") + endif() + target_include_directories(${lib} ${type} ${_dir}) + endforeach() +endmacro() + macro(__component_check_target) if(__REQUIRED_IDF_TARGETS) idf_build_get_property(idf_target IDF_TARGET) @@ -325,6 +335,7 @@ macro(__component_set_all_dependencies) endif() endmacro() + # idf_component_get_property # # @brief Retrieve the value of the specified component property @@ -437,16 +448,16 @@ function(idf_component_register) if(sources OR __EMBED_FILES OR __EMBED_TXTFILES) add_library(${component_lib} STATIC ${sources}) __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 ${config_dir}) + __component_add_include_dirs(${component_lib} "${__INCLUDE_DIRS}" PUBLIC) + __component_add_include_dirs(${component_lib} "${__PRIV_INCLUDE_DIRS}" PRIVATE) + __component_add_include_dirs(${component_lib} "${config_dir}" PUBLIC) 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 ${config_dir}) + __component_add_include_dirs(${component_lib} "${__INCLUDE_DIRS}" INTERFACE) + __component_add_include_dirs(${component_lib} "${config_dir}" INTERFACE) endif() # Alias the static/interface library created for linking to external targets.