|
|
@@ -125,6 +125,23 @@ function(__component_dir_quick_check var component_dir)
|
|
|
set(${var} ${res} PARENT_SCOPE)
|
|
|
endfunction()
|
|
|
|
|
|
+#
|
|
|
+# Write a CMake file containing all component and their properties. This is possible because each component
|
|
|
+# keeps a list of all its properties.
|
|
|
+#
|
|
|
+function(__component_write_properties output_file)
|
|
|
+ idf_build_get_property(component_targets __COMPONENT_TARGETS)
|
|
|
+ foreach(component_target ${component_targets})
|
|
|
+ __component_get_property(component_properties ${component_target} __COMPONENT_PROPERTIES)
|
|
|
+ foreach(property ${component_properties})
|
|
|
+ __component_get_property(val ${component_target} ${property})
|
|
|
+ set(component_properties_text
|
|
|
+ "${component_properties_text}\nset(__component_${component_target}_${property} ${val})")
|
|
|
+ endforeach()
|
|
|
+ file(WRITE ${output_file} "${component_properties_text}")
|
|
|
+ endforeach()
|
|
|
+endfunction()
|
|
|
+
|
|
|
#
|
|
|
# Add a component to process in the build. The components are keeped tracked of in property
|
|
|
# __COMPONENT_TARGETS in component target form.
|
|
|
@@ -184,44 +201,35 @@ endfunction()
|
|
|
# Given a component directory, get the requirements by expanding it early. The expansion is performed
|
|
|
# using a separate CMake script (the expansion is performed in a separate instance of CMake in scripting mode).
|
|
|
#
|
|
|
-function(__component_get_requirements error requires_var priv_requires_var component_dir)
|
|
|
+function(__component_get_requirements)
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
- idf_build_get_property(build_properties_file BUILD_PROPERTIES_FILE)
|
|
|
- idf_build_get_property(idf_target IDF_TARGET)
|
|
|
|
|
|
- # This function assumes that the directory has been checked to contain a component, thus
|
|
|
- # no check is performed here.
|
|
|
+ idf_build_get_property(build_dir BUILD_DIR)
|
|
|
+ set(build_properties_file ${build_dir}/build_properties.temp.cmake)
|
|
|
+ set(component_properties_file ${build_dir}/component_properties.temp.cmake)
|
|
|
+ set(component_requires_file ${build_dir}/component_requires.temp.cmake)
|
|
|
+
|
|
|
+ __build_write_properties(${build_properties_file})
|
|
|
+ __component_write_properties(${component_properties_file})
|
|
|
+
|
|
|
execute_process(COMMAND "${CMAKE_COMMAND}"
|
|
|
- -D "IDF_PATH=${idf_path}"
|
|
|
- -D "IDF_TARGET=${idf_target}"
|
|
|
- -D "COMPONENT_DIR=${component_dir}"
|
|
|
-D "BUILD_PROPERTIES_FILE=${build_properties_file}"
|
|
|
- -D "CMAKE_BUILD_EARLY_EXPANSION=1"
|
|
|
+ -D "COMPONENT_PROPERTIES_FILE=${component_properties_file}"
|
|
|
+ -D "COMPONENT_REQUIRES_FILE=${component_requires_file}"
|
|
|
-P "${idf_path}/tools/cmake/scripts/component_get_requirements.cmake"
|
|
|
RESULT_VARIABLE result
|
|
|
ERROR_VARIABLE error
|
|
|
)
|
|
|
|
|
|
if(NOT result EQUAL 0)
|
|
|
- set(error "${error}" PARENT_SCOPE)
|
|
|
- return()
|
|
|
+ message(FATAL_ERROR "${error}")
|
|
|
endif()
|
|
|
|
|
|
- string(REGEX REPLACE ";" "\\\\;" _output "${error}")
|
|
|
- string(REGEX REPLACE "\n" ";" _output "${_output}")
|
|
|
- list(REVERSE _output)
|
|
|
-
|
|
|
- if(_output)
|
|
|
- list(GET _output 1 _output)
|
|
|
-
|
|
|
- string(REGEX MATCH "\(.*\):::\(.*\)" _output "${_output}")
|
|
|
+ include(${component_requires_file})
|
|
|
|
|
|
- string(REPLACE ":" ";" requires "${CMAKE_MATCH_1}")
|
|
|
- string(REPLACE ":" ";" priv_requires "${CMAKE_MATCH_2}")
|
|
|
- endif()
|
|
|
-
|
|
|
- set(${requires_var} ${requires} PARENT_SCOPE)
|
|
|
- set(${priv_requires_var} ${priv_requires} PARENT_SCOPE)
|
|
|
+ file(REMOVE ${build_properties_file})
|
|
|
+ file(REMOVE ${component_properties_file})
|
|
|
+ file(REMOVE ${component_requires_file})
|
|
|
endfunction()
|
|
|
|
|
|
# __component_add_sources, __component_check_target
|
|
|
@@ -280,6 +288,39 @@ macro(__component_check_target)
|
|
|
endif()
|
|
|
endmacro()
|
|
|
|
|
|
+# __component_set_dependencies, __component_set_all_dependencies
|
|
|
+#
|
|
|
+# Links public and private requirements for the currently processed component
|
|
|
+macro(__component_set_dependencies reqs type)
|
|
|
+ foreach(req ${reqs})
|
|
|
+ if(req IN_LIST build_component_targets)
|
|
|
+ __component_get_property(req_lib ${req} COMPONENT_LIB)
|
|
|
+ target_link_libraries(${component_lib} ${type} ${req_lib})
|
|
|
+ endif()
|
|
|
+ endforeach()
|
|
|
+endmacro()
|
|
|
+
|
|
|
+macro(__component_set_all_dependencies)
|
|
|
+ __component_get_property(type ${component_target} COMPONENT_TYPE)
|
|
|
+ idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
|
|
+
|
|
|
+ if(NOT type STREQUAL CONFIG_ONLY)
|
|
|
+ __component_get_property(reqs ${component_target} __REQUIRES)
|
|
|
+ __component_set_dependencies("${reqs}" PUBLIC)
|
|
|
+
|
|
|
+ __component_get_property(priv_reqs ${component_target} __PRIV_REQUIRES)
|
|
|
+ __component_set_dependencies("${priv_reqs}" PRIVATE)
|
|
|
+ else()
|
|
|
+ __component_get_property(reqs ${component_target} __REQUIRES)
|
|
|
+ foreach(req ${reqs})
|
|
|
+ if(req IN_LIST build_component_targets)
|
|
|
+ __component_get_property(req_lib ${req} COMPONENT_LIB)
|
|
|
+ target_link_libraries(${component_lib} INTERFACE ${req_lib})
|
|
|
+ endif()
|
|
|
+ endforeach()
|
|
|
+ endif()
|
|
|
+endmacro()
|
|
|
+
|
|
|
# idf_component_get_property
|
|
|
#
|
|
|
# @brief Retrieve the value of the specified component property
|
|
|
@@ -323,6 +364,7 @@ function(idf_component_set_property component property val)
|
|
|
endif()
|
|
|
endfunction()
|
|
|
|
|
|
+
|
|
|
# idf_component_register
|
|
|
#
|
|
|
# @brief Register a component to the build, creating component library targets etc.
|
|
|
@@ -423,6 +465,9 @@ function(idf_component_register)
|
|
|
__ldgen_add_fragment_files("${__LDFRAGMENTS}")
|
|
|
endif()
|
|
|
|
|
|
+ # Set dependencies
|
|
|
+ __component_set_all_dependencies()
|
|
|
+
|
|
|
# Add the component to built components
|
|
|
idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND)
|
|
|
idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND)
|