Skip to content

Commit cc497d4

Browse files
Gadgetoiddpgeorge
authored andcommitted
examples/usercmodule: Add micropython.cmake to the C and CPP examples.
examples/usercmodule/micropython.cmake: Root micropython.cmake file is responsible for including modules. examples/usercmodule/cexample/micropython.cmake: examples/usercmodule/cppexample/micropython.cmake: Module micropython.cmake files define the target and link it to usermod. Signed-off-by: Phil Howard <phil@pimoroni.com>
1 parent 0cf12dd commit cc497d4

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Create an INTERFACE library for our C module.
2+
add_library(usermod_cexample INTERFACE)
3+
4+
# Add our source files to the lib
5+
target_sources(usermod_cexample INTERFACE
6+
${CMAKE_CURRENT_LIST_DIR}/examplemodule.c
7+
)
8+
9+
# Add the current directory as an include directory.
10+
target_include_directories(usermod_cexample INTERFACE
11+
${CMAKE_CURRENT_LIST_DIR}
12+
)
13+
14+
# Enable the module automatically by adding the relevant compile definitions.
15+
target_compile_definitions(usermod_cexample INTERFACE
16+
MODULE_CEXAMPLE_ENABLED=1
17+
)
18+
19+
# Link our INTERFACE library to the usermod target.
20+
target_link_libraries(usermod INTERFACE usermod_cexample)
21+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Create an INTERFACE library for our CPP module.
2+
add_library(usermod_cppexample INTERFACE)
3+
4+
# Add our source files to the library.
5+
target_sources(usermod_cppexample INTERFACE
6+
${CMAKE_CURRENT_LIST_DIR}/example.cpp
7+
${CMAKE_CURRENT_LIST_DIR}/examplemodule.c
8+
)
9+
10+
# Add the current directory as an include directory.
11+
target_include_directories(usermod_cppexample INTERFACE
12+
${CMAKE_CURRENT_LIST_DIR}
13+
)
14+
15+
# Enable the module automatically by adding the relevant compile definitions.
16+
target_compile_definitions(usermod_cppexample INTERFACE
17+
MODULE_CPPEXAMPLE_ENABLED=1
18+
)
19+
20+
# Link our INTERFACE library to the usermod target.
21+
target_link_libraries(usermod INTERFACE usermod_cppexample)
22+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This top-level micropython.cmake is responsible for listing
2+
# the individual modules we want to include.
3+
# Paths are absolute, and ${CMAKE_CURRENT_LIST_DIR} can be
4+
# used to prefix subdirectories.
5+
6+
# Add the C example.
7+
include(${CMAKE_CURRENT_LIST_DIR}/cexample/micropython.cmake)
8+
9+
# Add the CPP example.
10+
include(${CMAKE_CURRENT_LIST_DIR}/cppexample/micropython.cmake)
11+

0 commit comments

Comments
 (0)