Skip to content

FindOpenSSL module doesn't use pkg-config properly

The FindOpenSSL module starts with the following code:

if (UNIX)
  find_package(PkgConfig QUIET)
  pkg_check_modules(_OPENSSL QUIET openssl)
endif ()

Which fills in a number of _OPENSSL_* variables detailing the availability of OpenSSL on the platform given by pkg-config. Unfortunately, the rest of the FindOpenSSL module doesn't use any of this information, and does again regular find_library to find libssl and libcrypto.

While this works fine when dynamic linking, it fails short when doing static linking. Indeed, libcrypto.a internally uses libz.a (from the zlib library). When you're dynamic linking, you don't care about such second order dependencies, and linking with -lssl -lcrypto is sufficient. However, when static linking, you have to provide the list of all libraries to the linker, i.e -lssl -lcrypto -lz. pkg-config properly provides this information:

$ ./output/host/usr/bin/pkg-config --libs libcrypto
-L/home/thomas/projets/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr//lib -lcrypto -lz  

But CMake ignores it. Would it be possible to fix the FindOpenSSL module to address this issue?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information