Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
ccb3b500
Commit
ccb3b500
authored
Dec 29, 2022
by
Johny Mattsson
Browse files
Improvements to external component/module support.
Based on feedback from @tomsci - thanks!
parent
4c510a5a
Changes
3
Show whitespace changes
Inline
Side-by-side
components/modules/project_include.cmake
0 → 100644
View file @
ccb3b500
# Helper functions for external module registration.
# - extmod_register_conditional() for modules with a Kconfig option
# - extmod_register_unconditional() for always-enabled modules
function
(
extmod_register_conditional confname
)
if
(
${
CONFIG_NODEMCU_CMODULE_
${
confname
}}
)
# If the module is enabled in menuconfig, add the linker option
# "-u <confname>_module_selected1" to make the linker include this
# module. See components/core/include/module.h for further details
# on how this works.
message
(
"Including external module
${
confname
}
"
)
target_link_libraries
(
${
COMPONENT_LIB
}
"-u
${
confname
}
_module_selected1"
)
endif
()
endfunction
()
function
(
extmod_register_unconditional confname
)
message
(
"Including external module
${
confname
}
"
)
# The module macros rely on the presence of a CONFIG_NODEMCU_CMODULE_XXX
# def, so we have to add it explicitly as it won't be coming from Kconfig
target_compile_options
(
${
COMPONENT_LIB
}
PRIVATE
"-DCONFIG_NODEMCU_CMODULE_
${
confname
}
"
)
target_link_libraries
(
${
COMPONENT_LIB
}
"-u
${
confname
}
_module_selected1"
)
endfunction
()
extcomp-template/CMakeLists.txt
View file @
ccb3b500
# Modify this list as necessary to include all your source files.
# Update source files and includes as necessary
set
(
extmod_srcs
"mymod.c"
)
# If necessary, add items to the PRIV_REQUIRES list below
idf_component_register
(
idf_component_register
(
SRCS
${
extmod_srcs
}
SRCS
INCLUDE_DIRS
"."
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
"mymod.c"
PRIV_INCLUDE_DIRS
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
PRIV_REQUIRES
PRIV_REQUIRES
"base_nodemcu"
"base_nodemcu"
"lua"
"lua"
"platform"
"platform"
)
)
# The remainder is boiler-plate glue to get the linker to actually include
# To register the module with NodeMCU, use one of the below functions.
# the modules enabled in Kconfig. No user-serviceable parts inside.
# The name given MUST match the first argument to the NODEMCU_MODULE() in
# the module's C file.
# Match up all the extmod source files with their corresponding Kconfig
#
# option in the form NODEMCU_CMODULE_<modname> and if enabled, add a
# For modules with a Kconfig option, use:
# "-u <modname>_module_selected1" option to force the linker to include
extmod_register_conditional
(
MYMOD
)
# the module. See components/core/include/module.h for further details on
# ...and for modules without a Kconfig option, instead use:
# how this works.
#extmod_register_unconditional(MYMOD)
set
(
extmods_enabled
)
foreach
(
extmod_src
${
extmod_srcs
}
)
string
(
REPLACE
".c"
""
module_name
${
extmod_src
}
)
string
(
TOUPPER
${
module_name
}
module_ucase
)
set
(
mod_opt
"CONFIG_NODEMCU_CMODULE_
${
module_ucase
}
"
)
if
(
${${
mod_opt
}}
)
list
(
APPEND extmods_enabled
${
module_ucase
}
)
endif
()
endforeach
()
message
(
"Including the following modules:
${
extmods_enabled
}
"
)
foreach
(
mod
${
extmods_enabled
}
)
target_link_libraries
(
${
COMPONENT_LIB
}
"-u
${
mod
}
_module_selected1"
)
endforeach
()
extcomp-template/Kconfig
View file @
ccb3b500
menu "External modules"
config NODEMCU_CMODULE_MYMOD
bool "External NodeMCU module: mymod"
config NODEMCU_CMODULE_MYMOD
bool "Mymod module"
default "y"
default "y"
help
help
Includes the mymod module. This module is only an example for
Includes the mymod module. This module is only an example for
showing how to use external modules. Note that the config option
showing how to use external modules. Note that the config option
name has to be prefixed with NODEMCU_CMODULE_ and the suffix
name has to be prefixed with NODEMCU_CMODULE_ and the module
has to match the first argument in the NODEMCU_MODULE() macro
registered with extmod_register_conditional(MYMOD) in CMakeLists.txt
in the .c file.
endmenu
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment