|
2 | 2 |
|
3 | 3 | **WIP** |
4 | 4 |
|
| 5 | +## Purpose |
| 6 | + |
5 | 7 | This directory is provided to allow LoRaMac-node to be built as a static library for inclusion in other projects. |
6 | 8 |
|
7 | | -## CMake Options |
| 9 | +This directory contains a set of CMakeLists.txt files that shadow the directory structure under `src`. A backwards |
| 10 | +compatible change is made to the project root CMakeLists.txt which, when provided with the option `LORAMAC_AS_LIB`, |
| 11 | +will direct CMake to reference the as-lib directory instead of src. The option default is OFF so that the past |
| 12 | +build behaviour is preserved as the default. |
| 13 | + |
| 14 | +CMake configuration options are provided that mirror equivalent options in the `src` configuration tree, but a |
| 15 | +standard `LORAMAC_` prefix is applied to all options to aid interoperability with other project sources. |
| 16 | + |
| 17 | +## Supported CMake Configuration Options |
8 | 18 |
|
9 | 19 | - LORAMAC_AS_LIB:BOOL Whether to build the project as a static library (when ON), or to build the example applications |
10 | 20 | - LORAMAC_SUFFIX:STRING Defaults to empty, but can be set to any string to allow for multiple static libraries to |
11 | 21 | be build (for example with different region support) |
12 | | -- LORAMAC_SECURE_ELEMENT Name of the secure element, defaults to SOFT_SE |
13 | | -- LORAMAC_SECURE_ELEMENT_PRE_PROVISIONED Whether the secure element is pre-provisioned (default ON) |
14 | | -- LORAMAC_SOFT_SE_AES_DEC_PREKEYED Whether the SOFT SE secure elements AES support is DEC Prekeyed (default ON) |
15 | | -- LORAMAC_RADIO Name of the radio driver, defaults to sx1272 |
16 | | -- LORAMAC_USE_RADIO_DEBUG Enable Radio Debug GPIO's (default OFF) |
| 22 | +- LORAMAC_SECURE_ELEMENT:STRING Name of the secure element, defaults to SOFT_SE |
| 23 | +- LORAMAC_SECURE_ELEMENT_PRE_PROVISIONED:BOOL Whether the secure element is pre-provisioned (default ON) |
| 24 | +- LORAMAC_RADIO:STRING Name of the radio driver, defaults to sx1272 |
| 25 | +- LORAMAC_USE_RADIO_DEBUG:BOOL Enable Radio Debug GPIO's (default OFF) |
| 26 | + |
| 27 | +## Preparation for loading and building |
| 28 | + |
| 29 | +You must establish your toolchain prior to your first CMake `project()` call (which triggers toolchain detection). It |
| 30 | +is beyond the scope of this document to describe how to do that for your platform. |
| 31 | + |
| 32 | +You will need to provide a board implementation that suits your project. A number of standard boards are provided |
| 33 | +in the LoRaMac-node project which can be copied after the first CMake configure pass. Typically you will copy one of these |
| 34 | +(from the `/src/boards` directory) into your own project sources and make any necessary changes. |
| 35 | + |
| 36 | +NB: Pre-built board implementation targets are not provided due to the complexity of providing included or project |
| 37 | +specific HAL libraries. `CMakeLists.txt` files are included in the board implementation directories that can be used |
| 38 | +as a starting point for your own project. |
| 39 | + |
| 40 | +Depending on your platform, you may need to obtain Hardware Abstraction Libraries that are used by the board |
| 41 | +implementation that you choose. LoRaMac-node includes some of these for the provided board implementations (in the |
| 42 | +`/src/board/mcu` directory), but you may wish provide your own version (perhaps via FetchContent from the official |
| 43 | +sources). |
| 44 | + |
| 45 | +## Configuring via FetchContent to create a single library |
| 46 | + |
| 47 | +``` |
| 48 | +FetchContent_Declare( |
| 49 | + loramac |
| 50 | + GIT_REPOSITORY https://github.com/Lora-net/LoRaMac-node |
| 51 | + GIT_TAG master # branch or version tag, such a v4.7.0 |
| 52 | +) |
| 53 | +
|
| 54 | +set(LORAMAC_AS_LIB ON) |
| 55 | +set(LORAMAC_RADIO sx1276) |
| 56 | +set(REGION_EU868 ON) |
| 57 | +FetchContent_MakeAvailable(loramac) |
| 58 | +
|
| 59 | +# add your own target |
| 60 | +
|
| 61 | +add_executable(MyProject C) |
| 62 | +target_sources(MyProject main.c) |
| 63 | +target_link_libraries(MyProject loramac) |
| 64 | +``` |
| 65 | + |
| 66 | +## Configuring via FetchContent to create multiple libraries |
| 67 | + |
| 68 | +FetchContent should be used to load the project at CMake configure time (rather than build time using ExternalProject). |
| 69 | + |
| 70 | +``` |
| 71 | +FetchContent_Declare( |
| 72 | + loramac |
| 73 | + GIT_REPOSITORY https://github.com/Lora-net/LoRaMac-node |
| 74 | + GIT_TAG master |
| 75 | +) |
| 76 | +
|
| 77 | +FetchContent_GetProperties(loramac) |
| 78 | +if (NOT loramac_POPULATED) |
| 79 | + FetchContent_Populate(loramac) |
| 80 | +endif() |
| 81 | +
|
| 82 | +set(LORAMAC_AS_LIB ON) |
| 83 | +set(LORAMAC_RADIO sx1276) |
| 84 | +set(LORAMAC_SUFFIX -Europe) |
| 85 | +set(REGION_EU868 ON) |
| 86 | +add_subdirectory(loramac_SOURCE_DIR loramac${LORAMAC_SUFFIX}) |
| 87 | +
|
| 88 | +set(REGION_EU868 OFF) |
| 89 | +set(REGION_US915 ON) |
| 90 | +set(LORAMAC_SUFFIX -US) |
| 91 | +add_subdirectory(loramac_SOURCE_DIR loramac${LORAMAC_SUFFIX}) |
| 92 | +
|
| 93 | +# You now have targets loramac-Europe and loramac-US to link to your own targets |
| 94 | +
|
| 95 | +add_executable(MyProject C) |
| 96 | +target_sources(MyProject main.c) |
| 97 | +target_link_libraries(MyProject loramac-Europe) |
| 98 | +``` |
17 | 99 |
|
18 | 100 | ## TODO |
19 | 101 |
|
20 | | -- FetchContent should not override GIT_SUBMODULES or lr1110-driver and atecc608a-tnglora-se/cryptoauthlib won't be loaded |
21 | | -- AES_DEC_PREKEYED - why did I define this in the project, it may not be needed |
|
0 commit comments