Version String parsen

Letzte Änderung: 01.02.2018

CMake hat umfangreiche Methoden zur Text-Verarbeitung

string(...)

Im Beispiel werden die Elemente einer Versionnummer gelesen

function(get_versions versionstring libname major minor patch)
    string(REGEX REPLACE "([A-Za-z0-9_]*)-[vV].*" "\\1" locallibname ${versionstring} )
    set(libname ${locallibname} PARENT_SCOPE)
    string(REGEX REPLACE "^([A-Za-z0-9_]*-[vV])([0-9]*)([.][0-9]*[.][0-9]*-?.*)$" "\\2" numbers ${versionstring} )
    status_ref(CMAKE_MATCH_2)
    set(major ${numbers} PARENT_SCOPE)
    string(REGEX REPLACE "^([A-Za-z0-9_]*-[vV][0-9]*[.])([0-9]*)([.][0-9]*-?.*)$" "\\2" numbers ${versionstring} )
    set(minor ${numbers} PARENT_SCOPE)
    string(REGEX REPLACE "^([A-Za-z0-9_]*-[vV][0-9]*[.][0-9]*[.])([0-9]*)(-?.*)$" "\\2" numbers ${versionstring} )
    set(patch ${numbers} PARENT_SCOPE)
endfunction()

Verwendung:

get_versions("TTNLib-V0.1.18-Patch14" libname major minor patch)
status_ref(libname)
status_ref(major)
status_ref(minor)
status_ref(patch)

Ergebnis:

STATUS: libname = "TTN9Lib"
STATUS: major = "0"
STATUS: minor = "1"
STATUS: patch = "18"




© 2003-2018 th-thielemann.de