Commit 6e40ec4312 for openssl.org
commit 6e40ec4312976a5a61edbf0c4b669e6d138e2aa5
Author: Bartosz Kowalski <38248837+bartech-lab@users.noreply.github.com>
Date: Sun Sep 27 21:00:13 2026 +0200
exporters/cmake: find the prefix when reached through a symlinked dir
OpenSSLConfig.cmake finds its prefix by walking up from its own location.
When CMake reaches the file through a symlinked directory, the walk ends
in the wrong place. On distributions with a merged /usr, /lib is a
symlink to usr/lib, and CMake derives / as a search prefix from /bin in
PATH. It then loads /lib/cmake/OpenSSL/OpenSSLConfig.cmake, the walk
gives an empty prefix, and OPENSSL_INCLUDE_DIR becomes /include, which
does not exist.
Keep the walk, but when the real path of the directory holding the file
matches the real path of the configured CMAKECONFIGDIR, use the
configured PREFIX. This is the same check that CMake's own
configure_package_config_file() generates, so a relocated install still
resolves relative to where it is found.
Fixes #33012
Assisted-by: Claude:claude-opus-5-5
Reviewed-by: Richard Levitte <levitte@openssl.foundation>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Wed Dec 2 09:59:48 2026
Merged-from: https://github.com/openssl/openssl/pull/33411
diff --git a/exporters/cmake/OpenSSLConfig.cmake.in b/exporters/cmake/OpenSSLConfig.cmake.in
index aa3b20e4b2..4b6ffa18d3 100644
--- a/exporters/cmake/OpenSSLConfig.cmake.in
+++ b/exporters/cmake/OpenSSLConfig.cmake.in
@@ -99,6 +99,13 @@ get_filename_component(_ossl_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
foreach (split '/', $d);
}
-}
+get_filename_component(_ossl_real_current "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
+get_filename_component(_ossl_real_installed "{- unixify($OpenSSL::safe::installdata::CMAKECONFIGDIR[0], 1) -}" REALPATH)
+if(_ossl_real_current STREQUAL _ossl_real_installed)
+ set(_ossl_prefix "{- unixify($OpenSSL::safe::installdata::PREFIX[0], 1) -}")
+endif()
+unset(_ossl_real_current)
+unset(_ossl_real_installed)
if(_ossl_prefix STREQUAL "/")
set(_ossl_prefix "")
endif()