pokowaka/jwt-cpp

Use standard cmake module FindOpenSSL.cmake to find OpenSSL

Opened this issue · 7 comments

Currently the JWT cmake file uses different ways to find OpenSSL on each platform. This makes the cmake file more complicated than necessary.

Even worse is that the standard way to let cmake find a dependency in a non-system path doesn't work. Normally if I want jwt-cpp to find an OpenSSL library installed in directory /foo/bar, I would include that path in CMAKE_PREFIX_PATH. This currently doesn't work (at least on Linux) because the cmake file uses pkconfig to find OpenSSL unless you define the following 3 (!) cmake variables:
OPENSSL_INCLUDE_DIRS
OPENSSL_LIBRARY_DIRS
OPENSSL_LIBRARIES

Also the conan recipe for jwt-cpp currently doesn't work correctly on Linux, because jwt-cpp ignores the CMAKE_PREFIX_PATH.

I suggest to keep the variables OPENSSL_INCLUDE_DIRS, OPENSSL_LIBRARY_DIRS, OPENSSL_LIBRARIES for backwards compatibility, but if they are not defined then use the normal way:
find_package(OpenSSL)
to find OpenSSL.

I will create a pull request when I have tested the change also on Mac and Windows.

ps: this should fix also issue #27

You can just create a pull request, it will be picked up by the auto builders, so you don't need to validate the build

@pokowaka The CI build for Linux fails because OpenSSL 1.0.1f is installed and I set the minimum version to 1.1.0.

When I build on my own Linux machine with OpenSSL 1.0.2 I get undefined references link errors to functions like HMAC_CTX_new (used in ssl_compat.h). On internet I read that these functions are available only from OpenSSL 1.1.0. And indeed the HMAC_CTX_new function is not included in the libssl nor libcrypto 1.0.2:


cd openssl
git checkout OpenSSL_1_0_2o
./config
make
nm libcrypto.a | grep HMAC_CTX_new  #no output
nm libssl.a | grep HMAC_CTX_new  #no output

Is jwt-cpp supposed to work with OpenSSL < 1.1.0 ?

@pokowaka Do you have time to answer the question in the previous comment ?
Thanks !

There is no specific reason other than the one you described above. I

Somehow the detected OpenSSL version was incorrect in my Linux build. Works fine now, will create new pull request.