summaryrefslogtreecommitdiffstatshomepage
path: root/examples/usercmodule/cppexample
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-03-31 00:45:43 +1100
committerDamien George <damien@micropython.org>2021-04-01 16:27:38 +1100
commitd87f42b0e53829052f17955ba1e17f938ae486fb (patch)
tree4c251495c6a5f51c15fb348f25f55bb4e6944dd7 /examples/usercmodule/cppexample
parentec79e445027857d219d139cd31af578124a8e913 (diff)
downloadmicropython-d87f42b0e53829052f17955ba1e17f938ae486fb.tar.gz
micropython-d87f42b0e53829052f17955ba1e17f938ae486fb.zip
examples/usercmodules: Simplify user C module enabling.
It's a bit of a pitfall with user C modules that including them in the build does not automatically enable them. This commit changes the docs and examples for user C modules to encourage writers of user C modules to enable them unconditionally. This makes things simpler and covers most use cases. See discussion in issue #6960, and also #7086. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'examples/usercmodule/cppexample')
-rw-r--r--examples/usercmodule/cppexample/examplemodule.c5
-rw-r--r--examples/usercmodule/cppexample/micropython.cmake6
2 files changed, 4 insertions, 7 deletions
diff --git a/examples/usercmodule/cppexample/examplemodule.c b/examples/usercmodule/cppexample/examplemodule.c
index ceb588bef6..dfb7856837 100644
--- a/examples/usercmodule/cppexample/examplemodule.c
+++ b/examples/usercmodule/cppexample/examplemodule.c
@@ -22,4 +22,7 @@ const mp_obj_module_t cppexample_user_cmodule = {
};
// Register the module to make it available in Python.
-MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, MODULE_CPPEXAMPLE_ENABLED);
+// Note: the "1" in the third argument means this module is always enabled.
+// This "1" can be optionally replaced with a macro like MODULE_CPPEXAMPLE_ENABLED
+// which can then be used to conditionally enable this module.
+MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, 1);
diff --git a/examples/usercmodule/cppexample/micropython.cmake b/examples/usercmodule/cppexample/micropython.cmake
index 43e8d887f5..6da972c94e 100644
--- a/examples/usercmodule/cppexample/micropython.cmake
+++ b/examples/usercmodule/cppexample/micropython.cmake
@@ -12,11 +12,5 @@ target_include_directories(usermod_cppexample INTERFACE
${CMAKE_CURRENT_LIST_DIR}
)
-# Enable the module automatically by adding the relevant compile definitions.
-target_compile_definitions(usermod_cppexample INTERFACE
- MODULE_CPPEXAMPLE_ENABLED=1
-)
-
# Link our INTERFACE library to the usermod target.
target_link_libraries(usermod INTERFACE usermod_cppexample)
-