Skip to content

Instantly share code, notes, and snippets.

@scivision

scivision/CheckTLS.cmake

Last active Jun 1, 2021
Embed
What would you like to do?
Check if CMake TLS is working
cmake_minimum_required(VERSION 3.19)
function(check_tls)
# some CMake may not have SSL/TLS enabled, or may have missing/broken system certificates.
# this is a publicly-usable service (as per their TOS)
set(url https://www.howsmyssl.com/a/check)
set(temp ${PROJECT_BINARY_DIR}/check_tls.json)
if(NOT EXISTS ${temp})
message(STATUS "CheckTLS: ${url} => ${temp}")
file(DOWNLOAD ${url} ${temp} INACTIVITY_TIMEOUT 5)
endif()
file(READ ${temp} json)
string(JSON rating ERROR_VARIABLE e GET ${json} rating)
message(VERBOSE "TLS status: ${rating}")
if(NOT rating STREQUAL "Probably Okay")
message(WARNING "TLS seems to be broken on your system. Downloads will probably fail. ${rating}")
endif()
endfunction(check_tls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment