-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CMakeLists.txt for Mbed CLI v2 #35
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
add_library(mbed-mqtt INTERFACE) | ||
|
||
target_include_directories(mbed-mqtt | ||
INTERFACE | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/ | ||
./paho_mqtt-sn_embedded_c/MQTTSNClient/src/ | ||
./paho_mqtt_embedded_c/MQTTPacket/src/ | ||
./paho_mqtt_embedded_c/MQTTClient/src/ | ||
./paho_mqtt_embedded_c/MQTTClient/src/mbed/ | ||
./src/ | ||
) | ||
|
||
target_sources(mbed-mqtt | ||
INTERFACE | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNSerializePublish.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNSubscribeServer.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNUnsubscribeServer.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNPacket.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNConnectServer.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNSearchClient.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNUnsubscribeClient.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNSubscribeClient.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNSearchServer.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNConnectClient.c | ||
./paho_mqtt-sn_embedded_c/MQTTSNPacket/src/MQTTSNDeserializePublish.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTSerializePublish.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTConnectServer.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTConnectClient.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTDeserializePublish.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTUnsubscribeServer.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTPacket.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTUnsubscribeClient.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTSubscribeClient.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTSubscribeServer.c | ||
./paho_mqtt_embedded_c/MQTTPacket/src/MQTTFormat.c | ||
./src/MQTTClientMbedOs.cpp | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,22 @@ See [mbed_lib.json](mbed_lib.json) for all configurable options. | |
|
||
See [test README](TESTS/mqtt/README.md) to find out about tests-specific configuration configuration. | ||
|
||
### Building with CLI V2 | ||
|
||
Assuming you have this repository cloned or somehow available at the `<your-project-root>/mbed-mqtt` directory. | ||
|
||
Add to your project's `CMakeLists.txt` file the following lines: | ||
|
||
``` | ||
add_subdirectory(mbed-mqtt) | ||
|
||
target_link_libraries(${APP_TARGET} mbed-mqtt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. group them together to one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I've declared all dependencies explicitly, so this list has shrunk to just single entry |
||
target_link_libraries(${APP_TARGET} mbed-mbedtls) | ||
target_link_libraries(${APP_TARGET} mbed-nanostack) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why nanostack is required , shouldn't this be up to a consumer of this library (mqtt) to choose a stack (netsockets/nanostack, etc) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it is up to a consumer here, since it is just a suggestion in It now fails to compile, though, when I began tinkering with Anyway, thank you very much for the review so far! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It now has |
||
target_link_libraries(${APP_TARGET} mbed-greentea) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is greentea required? I dont think so (testing with greentea needs work to be enable with CMake) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically it is required for now, because otherwise it won't compile. But if PR #34 would be merged, then it will no longer be required and |
||
|
||
``` | ||
|
||
### API and usage | ||
|
||
Mbed-os uses [Eclipse paho project emmbedded c implementation of MQTT protocol](https://github.com/eclipse/paho.mqtt.embedded-c) and [MQTT-SN protocol](https://github.com/eclipse/paho.mqtt-sn.embedded-c/). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a license header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be an interface? I suspect STATIC would work for this library (no weak linking symbols) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this license header be sufficient? No names, just copyright, and SPDX identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right. Give me a couple more days and I will figure it out how to make it compile being
STATIC
. I'm not really competent neither withcmake
nor with mbed-os'CMakeLists.txt
files organization.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed my mind. Here is the reason why I think this library should be declared as
INTERFACE
:When it is declared as
STATIC
, it anyways turns out to be built alongside with mbed-os in any project. Therefore it uses all the same macros passed to the compiler on invocation. Consider an example when I havembedtls-config-changes.h
file in the root of my project and I pass it as"MBEDTLS_USER_CONFIG_FILE=\"mbedtls-config-changes.h\""
inmbed_app.json
. ThisMBEDTLS_USER_CONFIG_FILE
macro is passed to mbed-mqtt sources too when it is being built and this config header file cannot be found, because mbed-mqtt is being built separately as a static library and it is not aware of my project's root directory where the file is located. To mitigate this error I have to declare something like this in my project's rootCMakeLists.txt
:target_include_directories(mbed-mqtt PRIVATE .)
. When mbed-mqtt declared asINTERFACE
there is no such problems.When it is declared as
STATIC
, all mbed-mqtt dependencies are built separately from the project and number of files to be compiled becomes almost twice as many than if it was declared asINTERFACE
- 868 files whenINTERFACE
vs 1717 whenSTATIC
in my case. Basically the whole OS is being built twice. This is inconvenient.I have no evidence of any library for mbed-os declared as
STATIC
- they all are declared asINTERFACE
. Why mbed-mqtt should not be declared asINTERFACE
?