title: OPENSSL_ROOT_DIR for cmake
body: <p>I have built &amp; <strong>installed openssl 1.1.1</strong> on my system:</p>
  
  <pre><code>openssl version
  OpenSSL 1.1.1h-dev  xx XXX xxxx
  </code></pre>
  
  <p>The respective <code>libcrypto.so</code> and <code>libssl.so</code> are in <code>/usr/local/lib64</code>, headers in <code>/usr/local/include</code>. I created <code>/etc/ld.so.conf.d/usrlocal.conf</code> and added <code>/usr/local/lib64</code> there to make sure the .so are loadable.</p>
  
  <p><strong>There is an older version (1.0.2)</strong> in <code>/usr/lib64/</code> and <code>/usr/include</code> that i need to keep for other dependencies. </p>
  
  <p>I am trying to compile OQS library (<a href="https://github.com/open-quantum-safe/liboqs" rel="nofollow noreferrer">https://github.com/open-quantum-safe/liboqs</a>) that requires</p>
  
  <pre><code>find_package(OpenSSL 1.1.1 REQUIRED)
  </code></pre>
  
  <p>When I try to compile the library, I get</p>
  
  <pre><code>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)
  </code></pre>
  
  <p><strong>I have tried setting <code>OPENSSL_ROOT_DIR</code></strong> to almost any value imaginable without any result; the error remains.</p>
  
  <p>It seems to me that<code>cmake</code> only attempts to check <code>OPENSSL_ROOT_DIR</code> as last attempt, and that it terminates exploration for appropriate library version after finding the first suitable version...</p>
  
  <p>Now the question is obvious - <strong>how to force CMAKE to find appropriate OpenSSL version?</strong> </p>
  
  <h2><strong>UPDATE</strong></h2>
  
  <p><strong>(debunked in next update)</strong> As @Tsyvarev suggested in the comments, setting OPENSSL_ROOT_DIR as environment variable helped. That means no <code>set(OPENSSL_ROOT_DIR ...)</code> in CMakeLists.txt or <code>-DOPENSSL_ROOT_DIR</code> with <code>cmake</code> command, but <code>export OPENSSL_ROOT_DIR=...</code> is what helped <code>find_package</code> to find the correct version.</p>
  
  <p>I am still running into issues with OQS, yet this time I believe they are caused by a different issue.</p>
  
  <pre><code>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'
  </code></pre>
  
  <h2><strong>UPDATE 2</strong></h2>
  
  <p>I am actually using OQS in another CMakeLists.txt via <code>FetchContent</code> as:</p>
  
  <pre><code>FetchContent_Declare(liboqs 
      GIT_REPOSITORY https://github.com/onavratil-monetplus/liboqs 
      #GIT_TAG 0.2.0 
  ) 
  </code></pre>
  
  <p>I made my custom fork and tweaked their CMakeLists.txt to export targets so that I can link appropriate dependencies to my binary in <code>cmake</code>:</p>
  
  <pre><code>target_link_libraries(myexecutable PUBLIC OQS::oqs)
  </code></pre>
  
  <p>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 <code>find_package(OpenSSL 1.1.1 REQUIRED)</code>, it succeeds, respective variables <code>OPENSSL_FOUND</code> etc are set properly and OQS compiles. Btw I use <code>cmake</code> version 3.17.2.</p>
  
  <p>After all it was this edit (finding OPENSSL myself) that fixed the problem, this way, <code>-DOPENSSL_ROOT_DIR=/usr/local</code> works as well. </p>