在 Windows 上使用 MSYS2/mingw64 CMake "Could NOT find OpenSSL"

CMake "Could NOT find OpenSSL" with MSYS2/mingw64 on Windows

我正在尝试使用 MSYS2mingw64 在 Windows 上编译 this project,当 运行 cmake . 我得到以下输出:

-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.16299.
-- Build type: Release
-- Source of Randomness: random_device
CMake Error at C:/msys64/mingw64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
  version "1.1.1b")
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/msys64/mingw64/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
  CMakeLists.txt:10 (find_package)

我安装了 OpenSSL,证据如下:

$ which openssl
/mingw64/bin/openssl

$ openssl version
OpenSSL 1.1.1b  26 Feb 2019

而它似乎正在寻找的 OPENSSL_CRYPTO_LIBRARY 是 /mingw64/lib/libcrypto.a/mingw64/lib/libcrypto.dll.a

真正让我陷入困境的是,在 CMake 错误消息中,它显示 "found version 1.1.1b",很明显它能够找到它。有人对如何解决此错误有任何建议吗?

事实证明,我需要将 -G "Unix Makefiles" 添加到我的 cmake 命令中。默认情况下,它正在生成 Visual Studio solutions/projects,这不是您在 mingw 中想要的,并且通过添加此标志,它能够找到 openssl 文件。