-
Notifications
You must be signed in to change notification settings - Fork 66
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
Install mbedtls also when used as static library #346
Conversation
Since the iotivity-lite headers include mbedtls headers, the mbedtls library needs to be installed also when it is statically linked. The CMake property EXCLUDE_FROM_ALL prevented that.
🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed. ℹ️ To verify your latest change (fd024ad), label this PR with |
@Oxymoron79 Isn't changing directory to Though I don't recall any special reason why not to do it, I think I did it because I wanted to keep the |
During investigations for this answer, I noticed that my initial statement that the "iotivity-lite headers include mbedtls headers" is not true. But instead I found that if iotivity-lite links mbedtls statically, the user of iotivity-lite needs to have the static library of mbedtls installed.
If I understand the Makefile correctly, it does not need a separate installation of mbedtls, since it includes the mbedtls sources into the iotivty-lite sources (it does not make use of the mbedtls build system as the CMake does now) and thus does not need to link to the mbedtls library. So, this PR actually brings the CMake build closer to the Makefile build. |
@Oxymoron79 What's the use case? Maybe I'm missing it, because I only use installation on Linux...? Or do you want to use mbedTLS code from inside your binary? Here's my understanding of our mbedTLS usage: |
@Danielius1922 We use the iotivity-lite library as a dependency of a C++ library which is used in applications that run on a wide range of platforms. So I package iotivity-lite for a wide variety of platforms: Linux with deb packages, embedded linux devices with Yocto (ARM & Intel architectures), Windows 10 and we are looking into adding microcontrollers using Zephyr. The iotivity-lite version we currently use is an older one (2.2.5), where the CMake build of iotivity-lite builds mbedtls from the mbedtls source files. Now we want to update to a newer version of iotivity-lite where @jkralik was actually working on for us and I am reviewing his proposed changes. This is where I stumbled across the extra manual step to install the mbedtls library. For the wide variety of build systems and packaging I do, such an extra step usually turns out to be hard to maintain properly.
Yes, that's true - I noticed this today as well: The mbedtls headers are not the reason that require that extra installation step. Sorry about this wrong statement of mine. However...
This seems not to be the case with my test application: The application uses the shared library of iotivity-lite (which was built with And when I check the symbols in the iotivity-lite libraries with
So, it seems to me, that the installation of the mbedtls libraries is required, even if |
@Oxymoron79 Ah sorry, it turns out that CMake doesn't work like I thought it did. When you link a static library with another static library (in our case iotivity-lite libs with mbedtls libs) it doesn't archive the dependency (mbedtls) into the library (iotivity-lite), but simply takes note of the depedency and propagates everything when you link a (non-library) target with your library. |
@Danielius1922 The other solution would be to install the static mbedtls library 😉 That also seems to be the standard way. What would be the downside of that solution? |
Yes indeed. We will install it, the only thing I'm thinking about is the fact that we modify the mbedtls and whether that can cause any issues or not. Whether it would maybe make sense to rename the library from mbedtls to iotivty-lite-mbedtls or something to avoid clashing with an installation of a standard mbedtls. |
That's a good point. Renaming the mbedtls library is a good suggestion! I intended to address this issue when packaging iotivity-lite by marking the package that it provides/conflicts with the mbedtls package. But a renamed mbedtls library (my suggestion would be "ocf-mbedtls") would be even better. |
I'm not sure with the renaming to |
Yeah, we seem to have a use case when a client wants to use a single instance of mbedtls library with iotivity-lite and some other binaries. Though I don't know how exactly are they are using it, renaming the mbedtls targets might break something for them, so we have to clarify that with them. For now we agreed with @jkralik on a compromise solution - to control whether mbedtls is installed by a CMake option. set(OC_INSTALL_MBEDTLS ON CACHE BOOL "Include mbedtls in installation")
...
if (OC_INSTALL_MBEDTLS)
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/mbedtls)
else()
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/mbedtls EXCLUDE_FROM_ALL)
endif() (Also something like |
@Danielius1922 I will update this PR with the option that you propose.
I am already working on exactly such a solution 😃 I'm almost finished - I just want to do some more tests and understand the patches a bit better. Shall I create a separate PR to present and discuss it? |
Nice, seems that it is an obvious thing to add since we both thought of it. Yes, make the PR, I'll check it out. |
Kudos, SonarCloud Quality Gate passed! |
@Oxymoron79 Could you push the branch with the CMake updates to enable use of preinstalled mbedTLS as we talked about back in December? We want to allow to use both preinstalled mbedTLS and tinyCBOR. If you have something (even if unfinished) you'll save me some work. |
@Danielius1922 Sorry for the delay. I have now created the draft PR: #356 |
Since the iotivity-lite headers include mbedtls headers, the mbedtls library needs to be installed also when it is statically linked. The CMake property EXCLUDE_FROM_ALL prevented that.