-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Cross-compilation conflict with OpenSSL host development files #3047
Comments
Well, thanks for looking at it... I take it we mean this kind of thing
I'm not sure what will happen on other platforms with the change... the last patch there was from @zzblydia, is it possible they could try the change on their platform? |
No problem. I also have a conan layer in my build environment and I needed to know if that one wasn't causing the problem. I looked into the FindOpenSSL.cmake module in the cmake repository and that also references the pkgconfig package for Unix. I would expect it to still work on other platforms too. The only platform I am worried about is the Mac one. It would be nice if someone could verify it there. |
The patch doesn't seem to make the mac situation any worse (with openssl from homebrew) but with or without the patch, you have to give it this kind of help
|
Setting the LWS_OPENSSL_LIBRARIES and LWS_OPENSSL_INCLUDE_DIRS bypasses the library detection from the build scripts altogether. It just overwrites the items detected by cmake. It is the workaround I implemented to make my cross compilation work for now. |
I think the difficulty is on OSX, there's no simple "good bet" to find OpenSSL installed pieces. Eg, the headers as installed by homebrew are at |
This issue is similar to the one I encountered last time, where the openssl library found through pkgconfig did not have an absolute path, resulting in a linking error. I modified I'm confused about the output of PC_OPENSSL_LINK_LIBRARIES in this issue because the cmake(your cmake version?) documentation states that when using pkg_check_modules, I also notice that pkgconfig is just for unix in the FindOpenSSL.cmake. If pkg_check_modules(PC_OPENSSL openssl QUIET) was removed, I'm concerned that it might not be able to find the openssl library correctly on certain platforms(e.g. windows which configure mingw OpenSSL libraries through pkgconfig). Is it better to check OPENSSL_FOUND before 'list(APPEND OPENSSL_LIBRARIES ${PC_OPENSSL_LINK_LIBRARIES})' ? |
Thanks for looking at it. I think maybe other things happening here related to:
The pc code is already contingent on OPENSSL_FOUND not being true, assuming this test is the right kind
is at the top of the existing stanza.
What does the toolchain file for your 926ejs build actually say? You should be defeating visibility of whatever is in the build host by having these in it
|
Oh... we run
if so it might be worth a try. |
Yes, that's what I'm trying to say. or if (NOT OPENSSL_FOUND AND PC_OPENSSL_FOUND). |
Following what's discussed, I added a patch that might help on main. |
I agree that the not found check is the better approach and will keep it working for other platforms. You only need to do the pkgconfig check if you haven't found OpenSSL yet. I tested the change on my cross-compile build and it works fine. I do have one recommendation though as a minor (performance) improvement:
I did some more testing on my Debian 11 host system regarding the OpenSSL and PkgConfig packages for cmake 3.26.3:
Clearly the first find already found the correct libraries for my host system. There is no need to do the second one in that case. When I am cross-compiling and use a specific platform build of OpenSSL, I specify OPENSSL_ROOT_DIR in the build process to point to the correct OpenSSL. CMake correctly finds these with the absolute paths as expected. The problem is that the pkgconfig statement also find the OpenSSL files on my host system, which are not compatible with my arm build. Even if it would find absolute paths to the OpenSSL libraries the build would still fail as it would link x86_64 libraries against my arm build. On a side note: I don't think it is the responsibility of the lws build files to include a PkgConfig check to find OpenSSL correctly. As you make use of cmake find logic using find_package(OpenSSL REQUIRED) you defer the responsibility to cmake to find your files. If this doesn't work on some platforms, it should be fixed/improved in the FindOpenSSL.cmake. The if not found is basically a workaround for something that is missing in cmake. |
To some extent, I agree with the above viewpoint(that On a side note); Also i test below content in CMakeLists.txt on debian11.8 with cmake 3.26.3 and openssl 1.1.1w.
it has output:
In fact there are also openssl 3.0.12 and openssl 3.2.0 on my environment(both are installed from source) for testing, but the finding output of pkg-config depends on openssl.pc/libssl.pc/libcrypto.pc in /usr/lib/x86_64-linux-gnu/pkgconfig folder. so i think it should use |
When cross-compiling libwebsockets for an embedded device it fails to correctly detect OpenSSL when the host system also contains OpenSSL development files.
NOTE: In the explanation of the problem I stripped some long folders from the build to make it more readable.
The build fails with a common error that has been seen in other cross-compilation issues:
Looking at the CMakeConfigureLog.yaml I found the following problem:
If I have set the OPENSSL_ROOT_DIR to 'openssl/1.1.1f' and cmake is perfectly capable to find the needed openssl libraries.
In the cross-compiling scenario the ssl and crypto library can't be found on the search path of the compiler. That shouldn't be a problem as cmake includes the absolute path to the libraries to be used during linking. When looking at the compilation line I noticed that the libraries are added twice:
I did a separate test cross compiling a program that depends on cmake and that build without problem. What I noticed there was that the definitions for OpenSSL found by cmake were different:
The last part ;ssl;crypto was not part of that build. The next question was why does the libwebsocket build add these two libraries to the list? I found the anwser in the 'lib/tls/CMakeLists.txt' file at lines 271,272,274.
The build file uses pkgconfig too to find openssl libraries and this added the extra ;ssl;crypto to the libraries. In my case I also have OpenSSL development files on my host system and pkgconfig will find these and add them as extra libraries to the list. When I removed the pkgconfig lines form the lib/tls/CMakeLists.txt file the cross-compilation build works.
I believe this can be removed from the build file. The responsibility to find the OpenSSL package lies with cmake and it seems very capable to find the correct paths and libraries during host builds as well as cross-compilation builds.
The text was updated successfully, but these errors were encountered: