Merge branch 'bugfix/cmake_changes_fixes' into 'master'

CMake: various bugfixes

See merge request idf/esp-idf!5030
This commit is contained in:
Ivan Grokhotkov 2019-05-21 15:53:15 +08:00
commit e1a3dc50de
4 changed files with 47 additions and 26 deletions

View file

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

View file

@ -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"
@ -147,7 +147,10 @@ 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})
__component_dir_quick_check(is_component ${component_dir})
if(is_component)
__component_add(${component_dir} ${prefix})
endif()
endforeach()
# Set components required by all other components in the build
@ -439,12 +442,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

View file

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

View file

@ -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)
__component_dir_quick_check(is_component ${component_dir})
if(is_component)
idf_build_component(${component_dir})
endif()
endif()
endforeach()
endif()
@ -397,15 +401,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()