Skip to content

Instantly share code, notes, and snippets.

@jcfr
Last active April 2, 2018 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcfr/ec88de860e36a99d23485a56613045dc to your computer and use it in GitHub Desktop.
Save jcfr/ec88de860e36a99d23485a56613045dc to your computer and use it in GitHub Desktop.
#
# slicer_check_cmake_https
#
# Check if CMake supports downloading files using the HTTPS protocol. Fail if
# HTTPS is unsupported.
#
# CMake should support HTTPS when compiled with CMAKE_USE_OPENSSL enabled.
#
# Based on the script created by Jean-Christophe Fillion-Robin:
# https://gist.github.com/jcfr/e88a2a7cbc4ddd235186
#
set(GOOD_SSL "https://google.com")
set(BAD_SSL "https://self-signed.badssl.com")
#-------------------------------------------------------------------------------
message(STATUS "Trying to download from ${GOOD_SSL}")
file(DOWNLOAD ${GOOD_SSL} ${CMAKE_CURRENT_BINARY_DIR}/good_ssl TLS_VERIFY ON STATUS status)
if(NOT status MATCHES "^0.*")
message(FATAL_ERROR "Failed to download from ${GOOD_SSL}: ${status}")
endif()
message(STATUS "Trying to download from ${GOOD_SSL} - ok")
#-------------------------------------------------------------------------------
message(STATUS "Trying to download from ${BAD_SSL}")
file(DOWNLOAD ${BAD_SSL} ${CMAKE_CURRENT_BINARY_DIR}/bad_ssl TLS_VERIFY ON STATUS status)
if(status MATCHES "^0.*")
message(FATAL_ERROR "Download is expected to fail because of bad certs: ${status}")
endif()
message(STATUS "Trying to download from ${BAD_SSL} - failed as expected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment