FindOpenSSL: CMake3.26 breaks Threads detection when linking OpenSSL statically
With the following file:
cmake_minimum_required(VERSION 3.21)
project(testlib LANGUAGES C CXX)
add_library(testlib test.cpp)
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
target_link_libraries(testlib PUBLIC OpenSSL::SSL)
and dummy (empty) test.cpp
and test.h
I got the following error:
$ rm -rf build && OPENSSL_ROOT_DIR=/data/tmp/tmp.fnNNA2nUUX/chroot /home/cm/cmake-3.26.0-rc3-linux-x86_64/bin/cmake -S . -B build
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.7")
-- Found OpenSSL: /data/tmp/tmp.fnNNA2nUUX/chroot/lib64/libcrypto.a (found version "1.0.2")
-- Configuring done (4.3s)
CMake Error at /home/cm/cmake-3.26.0-rc3-linux-x86_64/share/cmake-3.26/Modules/FindOpenSSL.cmake:167 (set_property):
The link interface of target "OpenSSL::Crypto" contains:
Threads::Threads
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
Call Stack (most recent call first):
/home/cm/cmake-3.26.0-rc3-linux-x86_64/share/cmake-3.26/Modules/FindOpenSSL.cmake:692 (_OpenSSL_target_add_dependencies)
CMakeLists.txt:11 (find_package)
CMake Error at /home/cm/cmake-3.26.0-rc3-linux-x86_64/share/cmake-3.26/Modules/FindOpenSSL.cmake:167 (set_property):
The link interface of target "OpenSSL::SSL" contains:
Threads::Threads
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
Call Stack (most recent call first):
/home/cm/cmake-3.26.0-rc3-linux-x86_64/share/cmake-3.26/Modules/FindOpenSSL.cmake:726 (_OpenSSL_target_add_dependencies)
CMakeLists.txt:11 (find_package)
-- Generating done (0.2s)
CMake Generate step failed. Build files cannot be regenerated correctly.
I suspect this is brought in by !7986 (diffs)
It does not occur with CMake 3.25.0
Edited by Matias Lopez