Quick note, On ubuntu if you already have OpenSSL3 installed, you'll need to compile and install 1.1 alongside.
Download OpenSSL 1.1 Source: Download the source code for OpenSSL 1.1 from the official website:
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz tar -xzf openssl-1.1.1.tar.gz cd openssl-1.1.1
Build and Install OpenSSL 1.1: Build and install OpenSSL 1.1 from the source. You can install it in a custom directory to avoid conflicts with the existing OpenSSL installation.
./config --prefix=/usr/local/openssl-1.1 --openssldir=/usr/local/openssl-1.1 make sudo make install
Update CMakeLists.txt to Use Custom OpenSSL 1.1: Update your CMakeLists.txt to use the custom installation path for OpenSSL 1.1:
set(OPENSSL_ROOT_DIR "/usr/local/openssl-1.1")
set(OPENSSL_INCLUDE_DIR "/usr/local/openssl-1.1/include")
set(OPENSSL_CRYPTO_LIBRARY "/usr/local/openssl-1.1/lib/libcrypto.so")
set(OPENSSL_SSL_LIBRARY "/usr/local/openssl-1.1/lib/libssl.so")
set(OPENSSL_LIBRARIES "/usr/local/openssl-1.1/lib/libssl.so;/usr/local/openssl-1.1/lib/libcrypto.so")
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
link_directories(${OPENSSL_LIBRARIES})
target_link_libraries(my_executable ${OPENSSL_LIBRARIES})