component_get_requirements.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. include("${BUILD_PROPERTIES_FILE}")
  2. include("${COMPONENT_PROPERTIES_FILE}")
  3. function(idf_build_get_property var property)
  4. cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
  5. if(__GENERATOR_EXPRESSION)
  6. message(FATAL_ERROR "Getting build property generator expression not
  7. supported before idf_component_register().")
  8. endif()
  9. set(${var} ${${property}} PARENT_SCOPE)
  10. endfunction()
  11. idf_build_get_property(idf_path IDF_PATH)
  12. include(${idf_path}/tools/cmake/utilities.cmake)
  13. include(${idf_path}/tools/cmake/version.cmake)
  14. function(__component_get_property var component_target property)
  15. set(_property __component_${component_target}_${property})
  16. set(${var} ${${_property}} PARENT_SCOPE)
  17. endfunction()
  18. macro(require_idf_targets)
  19. endmacro()
  20. macro(idf_component_register)
  21. set(options)
  22. set(single_value)
  23. set(multi_value SRCS SRC_DIRS EXCLUDE_SRCS
  24. INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES
  25. PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES)
  26. cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" "${ARGN}")
  27. set(__component_requires "${__REQUIRES}")
  28. set(__component_priv_requires "${__PRIV_REQUIRES}")
  29. set(__component_registered 1)
  30. return()
  31. endmacro()
  32. macro(register_component)
  33. set(__component_requires "${COMPONENT_REQUIRES}")
  34. set(__component_priv_requires "${COMPONENT_PRIV_REQUIRES}")
  35. set(__component_registered 1)
  36. return()
  37. endmacro()
  38. macro(register_config_only_component)
  39. register_component()
  40. endmacro()
  41. idf_build_get_property(__common_reqs __COMPONENT_REQUIRES_COMMON)
  42. idf_build_get_property(__component_targets __COMPONENT_TARGETS)
  43. function(__component_get_requirements)
  44. # This is in a function (separate variable context) so that variables declared
  45. # and set by the included CMakeLists.txt does not bleed into the next inclusion.
  46. # We are only interested in the public and private requirements of components
  47. __component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
  48. __component_get_property(__component_name ${__component_target} COMPONENT_NAME)
  49. set(COMPONENT_NAME ${__component_name})
  50. set(COMPONENT_DIR ${__component_dir})
  51. set(COMPONENT_PATH ${__component_dir}) # for backward compatibility only, COMPONENT_DIR is preferred
  52. include(${__component_dir}/CMakeLists.txt OPTIONAL)
  53. spaces2list(__component_requires)
  54. spaces2list(__component_priv_requires)
  55. set(__component_requires "${__component_requires}" PARENT_SCOPE)
  56. set(__component_priv_requires "${__component_priv_requires}" PARENT_SCOPE)
  57. set(__component_registered ${__component_registered} PARENT_SCOPE)
  58. endfunction()
  59. set(CMAKE_BUILD_EARLY_EXPANSION 1)
  60. foreach(__component_target ${__component_targets})
  61. set(__component_requires "")
  62. set(__component_priv_requires "")
  63. set(__component_registered 0)
  64. __component_get_requirements()
  65. list(APPEND __component_requires "${__common_reqs}")
  66. # Remove duplicates and the component itself from its requirements
  67. __component_get_property(__component_alias ${__component_target} COMPONENT_ALIAS)
  68. __component_get_property(__component_name ${__component_target} COMPONENT_NAME)
  69. # Prevent component from linking to itself.
  70. if(__component_requires)
  71. list(REMOVE_DUPLICATES __component_requires)
  72. list(REMOVE_ITEM __component_requires ${__component_alias} ${__component_name})
  73. endif()
  74. if(__component_priv_requires)
  75. list(REMOVE_DUPLICATES __component_priv_requires)
  76. list(REMOVE_ITEM __component_priv_requires ${__component_alias} ${__component_name})
  77. endif()
  78. set(__contents
  79. "__component_set_property(${__component_target} REQUIRES \"${__component_requires}\")
  80. __component_set_property(${__component_target} PRIV_REQUIRES \"${__component_priv_requires}\")
  81. __component_set_property(${__component_target} __COMPONENT_REGISTERED ${__component_registered})"
  82. )
  83. set(__component_requires_contents "${__component_requires_contents}\n${__contents}")
  84. endforeach()
  85. file(WRITE ${COMPONENT_REQUIRES_FILE} "${__component_requires_contents}")