OPENSSL_ROOT_DIR for cmake

Viewed 10263

I have built & installed openssl 1.1.1 on my system:

openssl version
OpenSSL 1.1.1h-dev  xx XXX xxxx

The respective libcrypto.so and libssl.so are in /usr/local/lib64, headers in /usr/local/include. I created /etc/ld.so.conf.d/usrlocal.conf and added /usr/local/lib64 there to make sure the .so are loadable.

There is an older version (1.0.2) in /usr/lib64/ and /usr/include that i need to keep for other dependencies.

I am trying to compile OQS library (https://github.com/open-quantum-safe/liboqs) that requires

find_package(OpenSSL 1.1.1 REQUIRED)

When I try to compile the library, I get

CMake Error at /usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR: Found unsuitable version "1.0.2k", but
  required is at least "1.1.1" (found /usr/lib64/libcrypto.so)
Call Stack (most recent call first):
  /usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:443 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.17/Modules/FindOpenSSL.cmake:450 (find_package_handle_standard_args)
  CMakeLists.txt:26 (find_package)

I have tried setting OPENSSL_ROOT_DIR to almost any value imaginable without any result; the error remains.

It seems to me thatcmake only attempts to check OPENSSL_ROOT_DIR as last attempt, and that it terminates exploration for appropriate library version after finding the first suitable version...

Now the question is obvious - how to force CMAKE to find appropriate OpenSSL version?

UPDATE

(debunked in next update) As @Tsyvarev suggested in the comments, setting OPENSSL_ROOT_DIR as environment variable helped. That means no set(OPENSSL_ROOT_DIR ...) in CMakeLists.txt or -DOPENSSL_ROOT_DIR with cmake command, but export OPENSSL_ROOT_DIR=... is what helped find_package to find the correct version.

I am still running into issues with OQS, yet this time I believe they are caused by a different issue.

lib/liboqs.a(fips202x4.c.o): In function `keccak_squeezeblocks4x.constprop.1':
fips202x4.c:(.text.keccak_squeezeblocks4x.constprop.1+0x6b): undefined reference to `KeccakP1600times4_PermuteAll_24rounds'

UPDATE 2

I am actually using OQS in another CMakeLists.txt via FetchContent as:

FetchContent_Declare(liboqs 
    GIT_REPOSITORY https://github.com/onavratil-monetplus/liboqs 
    #GIT_TAG 0.2.0 
) 

I made my custom fork and tweaked their CMakeLists.txt to export targets so that I can link appropriate dependencies to my binary in cmake:

target_link_libraries(myexecutable PUBLIC OQS::oqs)

The strange thing is, if I let OQS find OpenSSL on its own, I will get to the same result as in the original answer - no matter if I use -D, set() or export =. However, if on my top level CMakeLists.txt i manually call find_package(OpenSSL 1.1.1 REQUIRED), it succeeds, respective variables OPENSSL_FOUND etc are set properly and OQS compiles. Btw I use cmake version 3.17.2.

After all it was this edit (finding OPENSSL myself) that fixed the problem, this way, -DOPENSSL_ROOT_DIR=/usr/local works as well.

1 Answers

I had the Problem when I needed openssl for an Android Project. In the scenario it helped to import openssl via gradle and then linking the fetched lib like described here

Related