cmake: allow overriding kconfig, kconfig_projbuild on registration

This commit is contained in:
Renz Bagaporo 2020-04-02 21:02:09 +08:00
parent f8d0c5770b
commit ebf07d353d
3 changed files with 29 additions and 4 deletions

View file

@ -1268,7 +1268,9 @@ the first element/member instead.
[LDFRAGMENTS ldfragment1 ldfragment2 ...] [LDFRAGMENTS ldfragment1 ldfragment2 ...]
[REQUIRED_IDF_TARGETS target1 target2 ...] [REQUIRED_IDF_TARGETS target1 target2 ...]
[EMBED_FILES file1 file2 ...] [EMBED_FILES file1 file2 ...]
[EMBED_TXTFILES file1 file2 ...]) [EMBED_TXTFILES file1 file2 ...]
[KCONFIG kconfig]
[KCONFIG_PROJBUILD kconfig_projbuild])
Register a component to the build system. Much like the ``project()`` CMake command, this should be called from the component's Register a component to the build system. Much like the ``project()`` CMake command, this should be called from the component's
CMakeLists.txt directly (not through a function or macro) and is recommended to be called before any other command. Here are some CMakeLists.txt directly (not through a function or macro) and is recommended to be called before any other command. Here are some
@ -1291,6 +1293,8 @@ The arguments for ``idf_component_register`` include:
- PRIV_REQUIRES - private component requirements for the component; ignored on config-only components - PRIV_REQUIRES - private component requirements for the component; ignored on config-only components
- LDFRAGMENTS - component linker fragment files - LDFRAGMENTS - component linker fragment files
- REQUIRED_IDF_TARGETS - specify the only target the component supports - REQUIRED_IDF_TARGETS - specify the only target the component supports
- KCONFIG - override the default Kconfig file
- KCONFIG_PROJBUILD - override the default Kconfig.projbuild file
The following are used for :ref:`embedding data into the component<cmake_embed_data>`, and is considered as source files The following are used for :ref:`embedding data into the component<cmake_embed_data>`, and is considered as source files
when determining if a component is config-only. This means that even if the component does not specify source files, a static library is still when determining if a component is config-only. This means that even if the component does not specify source files, a static library is still

View file

@ -416,9 +416,11 @@ endfunction()
# @param[in, optional] REQUIRED_IDF_TARGETS (multivalue) the list of IDF build targets that the component only supports # @param[in, optional] REQUIRED_IDF_TARGETS (multivalue) the list of IDF build targets that the component only supports
# @param[in, optional] EMBED_FILES (multivalue) list of binary files to embed with the component # @param[in, optional] EMBED_FILES (multivalue) list of binary files to embed with the component
# @param[in, optional] EMBED_TXTFILES (multivalue) list of text files to embed with the component # @param[in, optional] EMBED_TXTFILES (multivalue) list of text files to embed with the component
# @param[in, optional] KCONFIG (single value) override the default Kconfig
# @param[in, optional] KCONFIG_PROJBUILD (single value) override the default Kconfig
function(idf_component_register) function(idf_component_register)
set(options) set(options)
set(single_value) set(single_value KCONFIG KCONFIG_PROJBUILD)
set(multi_value SRCS SRC_DIRS EXCLUDE_SRCS set(multi_value SRCS SRC_DIRS EXCLUDE_SRCS
INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES
PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES) PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES)

View file

@ -23,13 +23,15 @@ endmacro()
macro(idf_component_register) macro(idf_component_register)
set(options) set(options)
set(single_value) set(single_value KCONFIG KCONFIG_PROJBUILD)
set(multi_value SRCS SRC_DIRS EXCLUDE_SRCS set(multi_value SRCS SRC_DIRS EXCLUDE_SRCS
INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES
PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES) PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" "${ARGN}") cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" "${ARGN}")
set(__component_requires "${__REQUIRES}")
set(__component_priv_requires "${__PRIV_REQUIRES}") set(__component_priv_requires "${__PRIV_REQUIRES}")
set(__component_requires "${__REQUIRES}")
set(__component_kconfig "${__KCONFIG}")
set(__component_kconfig_projbuild "${__KCONFIG_PROJBUILD}")
set(__component_registered 1) set(__component_registered 1)
return() return()
endmacro() endmacro()
@ -64,6 +66,8 @@ function(__component_get_requirements)
set(__component_requires "${__component_requires}" PARENT_SCOPE) set(__component_requires "${__component_requires}" PARENT_SCOPE)
set(__component_priv_requires "${__component_priv_requires}" PARENT_SCOPE) set(__component_priv_requires "${__component_priv_requires}" PARENT_SCOPE)
set(__component_kconfig "${__component_kconfig}" PARENT_SCOPE)
set(__component_kconfig_projbuild "${__component_kconfig_projbuild}" PARENT_SCOPE)
set(__component_registered ${__component_registered} PARENT_SCOPE) set(__component_registered ${__component_registered} PARENT_SCOPE)
endfunction() endfunction()
@ -97,6 +101,21 @@ foreach(__component_target ${__component_targets})
__component_set_property(${__component_target} PRIV_REQUIRES \"${__component_priv_requires}\") __component_set_property(${__component_target} PRIV_REQUIRES \"${__component_priv_requires}\")
__component_set_property(${__component_target} __COMPONENT_REGISTERED ${__component_registered})" __component_set_property(${__component_target} __COMPONENT_REGISTERED ${__component_registered})"
) )
if(__component_kconfig)
get_filename_component(__component_kconfig "${__component_kconfig}" ABSOLUTE)
set(__contents
"${__contents}\n__component_set_property(${__component_target} KCONFIG \"${__component_kconfig}\""
)
endif()
if(__component_kconfig_projbuild)
get_filename_component(__component_kconfig "${__component_kconfig}" ABSOLUTE)
set(__contents
"${__contents}\n__component_set_property(${__component_target} KCONFIG_PROJBUILD \"${__component_kconfig_projbuild}\""
)
endif()
set(__component_requires_contents "${__component_requires_contents}\n${__contents}") set(__component_requires_contents "${__component_requires_contents}\n${__contents}")
endforeach() endforeach()