Commit 41b6d30c by Patrick Steinhardt

cmake: sanitize boolean options passed by user

Starting with our conversions to mix backend-autodetection and selection
into a single variable (USE_GSSAPI, USE_HTTPS, USE_SHA1), we have
introduced a simple STREQUAL to check for "ON", which indicates that the
user wants us to auto-detect available backends and pick any one that's
available. This behaviour deviates from previous behaviour, as passing a
value like "yes", "on" or "true" will in fact be treated like a backend
name and result in autodetection failure.

Fix the issue by introducing a new function `SanitizeBool`. Given a
variable that may hold a boolean value, the function will sanitize that
variable to hold either "ON" or "OFF". In case it is not a recognized
boolean, we will just keep the value as-is. This fixes the above
described issue.
parent ee3307a1
FUNCTION(SanitizeBool VAR)
STRING(TOLOWER "${${VAR}}" VALUE)
IF(VALUE STREQUAL "on")
SET(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "yes")
SET(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "true")
SET(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "1")
SET(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "off")
SET(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "no")
SET(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "false")
SET(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "0")
SET(${VAR} "OFF" PARENT_SCOPE)
ENDIF()
ENDFUNCTION()
......@@ -2,12 +2,15 @@
# We try to find any packages our backends might use
INCLUDE(SanitizeBool)
FIND_PACKAGE(GSSAPI)
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
INCLUDE(FindGSSFramework)
ENDIF()
# Auto-select GSS backend
SanitizeBool(USE_GSSAPI)
IF (USE_GSSAPI STREQUAL ON)
IF (GSSFRAMEWORK_FOUND)
SET(GSS_BACKEND "GSS.framework")
......
# Select the backend to use
INCLUDE(SanitizeBool)
# We try to find any packages our backends might use
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(mbedTLS)
......@@ -9,6 +11,7 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
ENDIF()
# Auto-select TLS backend
SanitizeBool(USE_HTTPS)
IF (USE_HTTPS STREQUAL ON)
IF (SECURITY_FOUND)
IF (SECURITY_HAS_SSLCREATECONTEXT)
......
# Select a hash backend
INCLUDE(SanitizeBool)
# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
SanitizeBool(USE_SHA1)
IF(USE_SHA1 STREQUAL ON OR USE_SHA1 STREQUAL "CollisionDetection")
SET(SHA1_BACKEND "CollisionDetection")
ELSEIF(USE_SHA1 STREQUAL "HTTPS")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment