1
0
mirror of https://github.com/kakwa/uts-server synced 2024-12-04 23:15:54 +01:00

adding small cmake module to detect LibreSSL and using it in CMakeLists.txt

This commit is contained in:
kakwa 2017-04-21 08:52:25 +02:00
parent 730aa230b8
commit f01f72f913
2 changed files with 65 additions and 5 deletions

View File

@ -55,12 +55,16 @@ MESSAGE(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
MESSAGE(STATUS "OpenSSL version: ${OPENSSL_VERSION}")
MESSAGE(STATUS "OS Detected: ${CMAKE_SYSTEM_NAME}")
find_package(LibreSSL)
MESSAGE(STATUS "LibreSSL Detected: ${IS_LIBRESSL}")
if(NOT(DEFINED OPENSSL_API_1_1))
if(${OPENSSL_VERSION} VERSION_GREATER 1.0.99)
set(OPENSSL_API_1_1 ON)
else()
set(OPENSSL_API_1_1 OFF)
endif()
if(${OPENSSL_VERSION} VERSION_GREATER 1.0.99 AND NOT(${IS_LIBRESSL}))
set(OPENSSL_API_1_1 ON)
else()
set(OPENSSL_API_1_1 OFF)
endif()
endif()

56
cmake/FindLibreSSL.cmake Normal file
View File

@ -0,0 +1,56 @@
#.rst
# FindLibreSSL
# ------------
#
# Detect if OpenSSL is in fact LibreSSL, and recovers libressl version.
#
# Requires running FindOpenSSL previously
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# ``LIBRESSL_VERSION``
# This is set to ``$major.$minor.$revision$patch`` (e.g. ``2.3.1f``).
#
# ``IS_LIBRESSL``
# Boolean, set to true if LibreSSL
#
if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" libressl_version_str
REGEX "^#[\t ]*define[\t ]+LIBRESSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
if(libressl_version_str)
# The version number is encoded as 0xMNNFFPPS: major minor fix patch status
# The status gives if this is a developer or prerelease and is ignored here.
# Major, minor, and fix directly translate into the version numbers shown in
# the string. The patch field translates to the single character suffix that
# indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so
# on.
string(REGEX REPLACE "^.*LIBRESSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$"
"\\1;\\2;\\3;\\4;\\5" LIBRESSL_VERSION_LIST "${libressl_version_str}")
list(GET LIBRESSL_VERSION_LIST 0 LIBRESSL_VERSION_MAJOR)
list(GET LIBRESSL_VERSION_LIST 1 LIBRESSL_VERSION_MINOR)
from_hex("${LIBRESSL_VERSION_MINOR}" LIBRESSL_VERSION_MINOR)
list(GET LIBRESSL_VERSION_LIST 2 LIBRESSL_VERSION_FIX)
from_hex("${LIBRESSL_VERSION_FIX}" LIBRESSL_VERSION_FIX)
list(GET LIBRESSL_VERSION_LIST 3 LIBRESSL_VERSION_PATCH)
if (NOT LIBRESSL_VERSION_PATCH STREQUAL "00")
from_hex("${LIBRESSL_VERSION_PATCH}" _tmp)
# 96 is the ASCII code of 'a' minus 1
math(EXPR LIBRESSL_VERSION_PATCH_ASCII "${_tmp} + 96")
unset(_tmp)
# Once anyone knows how OpenSSL would call the patch versions beyond 'z'
# this should be updated to handle that, too. This has not happened yet
# so it is simply ignored here for now.
string(ASCII "${LIBRESSL_VERSION_PATCH_ASCII}" LIBRESSL_VERSION_PATCH_STRING)
endif ()
set(LIBRESSL_VERSION "${LIBRESSL_VERSION_MAJOR}.${LIBRESSL_VERSION_MINOR}.${LIBRESSL_VERSION_FIX}${LIBRESSL_VERSION_PATCH_STRING}")
set(IS_LIBRESSL ON)
else ()
set(IS_LIBRESSL OFF)
endif ()
endif ()