From 078c69e6891e703d5592e201b2b6670c961824b8 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 20 May 2019 14:23:28 +0800 Subject: [PATCH 1/5] cmake: remove redundant variable setting --- tools/cmake/project.cmake | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index d7bf90f05b..4522d0a2cf 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -397,15 +397,4 @@ 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() From 5175a152d9802dcecb1938fe27cf2e7cd2d0f04e Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 20 May 2019 14:36:55 +0800 Subject: [PATCH 2/5] cmake: exclude dot-dirs from added components --- tools/cmake/build.cmake | 6 +++++- tools/cmake/project.cmake | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index bd2184977b..ad46d3d8da 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -147,7 +147,11 @@ function(__build_init idf_path) file(GLOB component_dirs ${idf_path}/components/*) foreach(component_dir ${component_dirs}) get_filename_component(component_dir ${component_dir} ABSOLUTE) - __component_add(${component_dir} ${prefix}) + get_filename_component(base_dir ${component_dir} NAME) + string(SUBSTRING "${base_dir}" 0 1 first_char) + if(NOT first_char STREQUAL ".") + __component_add(${component_dir} ${prefix}) + endif() endforeach() # Set components required by all other components in the build diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 4522d0a2cf..0cb2d6db92 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -148,7 +148,11 @@ function(__project_init components_var test_components_var) file(GLOB component_dirs ${component_dir}/*) foreach(component_dir ${component_dirs}) if(EXISTS ${component_dir}/CMakeLists.txt) - idf_build_component(${component_dir}) + get_filename_component(base_dir ${component_dir} NAME) + string(SUBSTRING "${base_dir}" 0 1 first_char) + if(NOT first_char STREQUAL ".") + idf_build_component(${component_dir}) + endif() endif() endforeach() endif() From e3eb945fd2c4590cae59dd81cb5b08ab62673f33 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 20 May 2019 14:51:59 +0800 Subject: [PATCH 3/5] cmake: restore use of GNU extensions from libc --- 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 ad46d3d8da..e20b68cc48 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -91,7 +91,7 @@ function(__build_set_default_build_specifications) unset(c_compile_options) unset(cxx_compile_options) - list(APPEND compile_definitions "-DHAVE_CONFIG_H") + list(APPEND compile_definitions "-DHAVE_CONFIG_H" "-D_GNU_SOURCE") list(APPEND compile_options "-ffunction-sections" "-fdata-sections" From e1726a91ce7e11ffe707b1070b856171cf4baaad Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 20 May 2019 15:07:15 +0800 Subject: [PATCH 4/5] cmake: project includes should know about ESP_PLATFORM variable --- CMakeLists.txt | 3 --- tools/cmake/build.cmake | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 139dce9c65..beccd08a63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,9 +62,6 @@ elseif(CONFIG_STACK_CHECK_ALL) list(APPEND compile_options "-fstack-protector-all") endif() -# All targets built under this scope is with the ESP-IDF build system -set(ESP_PLATFORM 1) -list(APPEND compile_definitions "-DESP_PLATFORM") idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index e20b68cc48..531d343c2a 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -443,12 +443,18 @@ macro(idf_build_process target) idf_build_set_property(___COMPONENT_REQUIRES_COMMON ${lib} APPEND) endforeach() + # All targets built under this scope is with the ESP-IDF build system + set(ESP_PLATFORM 1) + idf_build_set_property(COMPILE_DEFINITIONS "-DESP_PLATFORM" APPEND) + __build_process_project_includes() # Perform component processing (inclusion of project_include.cmake, adding component # subdirectories, creating library targets, linking libraries, etc.) idf_build_get_property(idf_path IDF_PATH) add_subdirectory(${idf_path} ${build_dir}/esp-idf) + + unset(ESP_PLATFORM) endmacro() # idf_build_executable From b4ad6c14261e1f464e93bb566438076b8780618d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 20 May 2019 18:46:57 +0800 Subject: [PATCH 5/5] cmake: refactor quick check given component dirs --- tools/cmake/build.cmake | 5 ++--- tools/cmake/component.cmake | 40 ++++++++++++++++++++++++++++--------- tools/cmake/project.cmake | 4 ++-- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 531d343c2a..2371c94623 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -147,9 +147,8 @@ function(__build_init idf_path) file(GLOB component_dirs ${idf_path}/components/*) foreach(component_dir ${component_dirs}) get_filename_component(component_dir ${component_dir} ABSOLUTE) - get_filename_component(base_dir ${component_dir} NAME) - string(SUBSTRING "${base_dir}" 0 1 first_char) - if(NOT first_char STREQUAL ".") + __component_dir_quick_check(is_component ${component_dir}) + if(is_component) __component_add(${component_dir} ${prefix}) endif() endforeach() diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 2f65dca2ec..b3dd460c83 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -95,6 +95,36 @@ macro(__component_set_properties) __component_set_property(${component_target} REQUIRED_IDF_TARGETS "${__REQUIRED_IDF_TARGETS}") endmacro() +# +# Perform a quick check if given component dir satisfies basic requirements. +# +function(__component_dir_quick_check var component_dir) + set(res 1) + get_filename_component(abs_dir ${component_dir} ABSOLUTE) + + # Check this is really a directory and that a CMakeLists.txt file for this component exists + # - warn and skip anything which isn't valid looking (probably cruft) + if(NOT IS_DIRECTORY "${abs_dir}") + message(STATUS "Unexpected file in components directory: ${abs_dir}") + set(res 0) + endif() + + get_filename_component(base_dir ${abs_dir} NAME) + string(SUBSTRING "${base_dir}" 0 1 first_char) + + if(NOT first_char STREQUAL ".") + if(NOT EXISTS "${abs_dir}/CMakeLists.txt") + message(STATUS "Component directory ${abs_dir} does not contain a CMakeLists.txt file. " + "No component will be added") + set(res 0) + endif() + else() + set(res 0) # quietly ignore dot-folders + endif() + + set(${var} ${res} PARENT_SCOPE) +endfunction() + # # Add a component to process in the build. The components are keeped tracked of in property # __COMPONENT_TARGETS in component target form. @@ -112,16 +142,8 @@ function(__component_add component_dir prefix) get_filename_component(abs_dir ${component_dir} ABSOLUTE) get_filename_component(base_dir ${abs_dir} NAME) - # Check this is really a directory and that a CMakeLists.txt file for this component exists - # - warn and skip anything which isn't valid looking (probably cruft) - if(NOT IS_DIRECTORY "${abs_dir}") - message(WARNING "Unexpected file in components directory: ${abs_dir}") - return() - endif() if(NOT EXISTS "${abs_dir}/CMakeLists.txt") - message(WARNING "Component directory ${abs_dir} does not contain a CMakeLists.txt file. " - "No component will be added") - return() + message(FATAL_ERROR "Directory '${component_dir}' does not contain a component.") endif() set(component_name ${base_dir}) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 0cb2d6db92..3726fa0fb1 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -149,8 +149,8 @@ function(__project_init components_var test_components_var) foreach(component_dir ${component_dirs}) if(EXISTS ${component_dir}/CMakeLists.txt) get_filename_component(base_dir ${component_dir} NAME) - string(SUBSTRING "${base_dir}" 0 1 first_char) - if(NOT first_char STREQUAL ".") + __component_dir_quick_check(is_component ${component_dir}) + if(is_component) idf_build_component(${component_dir}) endif() endif()