diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd8260af5..e457a3499d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(LIBRESSL_TESTS "Build tests" ON) option(ENABLE_ASM "Enable assembly" ON) option(ENABLE_EXTRATESTS "Enable extra tests that may be unreliable on some platforms" OFF) option(ENABLE_NC "Enable installing TLS-enabled nc(1)" OFF) +option(ENABLE_SPECTRE_MITIGATION "Enable MSVC Spectre mitigation" OFF) set(OPENSSLDIR ${OPENSSLDIR} CACHE PATH "Set the default openssl directory" FORCE) set(LIBRESSL_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/LibreSSL" CACHE STRING "Installation directory for the CMake targets") @@ -150,6 +151,13 @@ if(MSVC) add_definitions(-Dinline=__inline) message(STATUS "Using [${CMAKE_C_COMPILER_ID}] compiler") + if(ENABLE_SPECTRE_MITIGATION) + if(MSVC_VERSION LESS 1912) + message(FATAL_ERROR "Spectre mitigation unavailable before MSVC 2017 15.5") + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre") + endif() + include(TestBigEndian) TEST_BIG_ENDIAN(HAVE_BIG_ENDIAN) if(HAVE_BIG_ENDIAN)