Skip to content

Commit

Permalink
get version from OpenSSL in CMakeLists.txt
Browse files Browse the repository at this point in the history
Signed-off-by: Fs <[email protected]>
  • Loading branch information
Fsu0413 committed Dec 12, 2023
1 parent c54fea7 commit 47e0b6e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

cmake_minimum_required(VERSION 3.22)

set(OPENSSL_VERSION_DAT_REGEX "([A-Z_]+)=(.*)")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/openssl/VERSION.dat" OPENSSL_VERSION_DAT)

foreach (i IN LISTS OPENSSL_VERSION_DAT)
if (i MATCHES "([A-Z_]+)=(.*)")
set("OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}")
string(LENGTH "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}}" "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH")
if (OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH GREATER_EQUAL 2)
string(SUBSTRING "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}}" 0 1 "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_STARTSWITH")
math(EXPR "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH1" "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH} - 1")
string(SUBSTRING "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}}" "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH1}" -1 "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_ENDSWITH")
if ( ( OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_STARTSWITH STREQUAL "\"" ) AND ( OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_ENDSWITH STREQUAL "\"" ) )
math(EXPR "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH2" "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH} - 2")
string(SUBSTRING "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}}" 1 "${OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_LENGTH2}" "OPENSSL_VERSION_DAT_${CMAKE_MATCH_1}_STR")
endif()
endif()
endif()
endforeach()

project(OpenSSL
VERSION 3.0.12
VERSION "${OPENSSL_VERSION_DAT_MAJOR}.${OPENSSL_VERSION_DAT_MINOR}.${OPENSSL_VERSION_DAT_PATCH}"
DESCRIPTION "TLS/SSL and crypto library"
HOMEPAGE_URL "https://www.openssl.org/"
LANGUAGES C CXX
)

# for generating opensslv.h
set(OPENSSL_RELEASE_DATE "24 Oct 2023")
set(OPENSSL_RELEASE_DATE "${OPENSSL_VERSION_DAT_RELEASE_DATE_STR}")

if (PROJECT_VERSION_MAJOR LESS 3)
set(OPENSSL_VERSION_PRE3_SUFFICES
Expand Down

0 comments on commit 47e0b6e

Please sign in to comment.