FetchMegBrainVersion.cmake 1.5 KB
Newer Older
1 2 3
# Parses the version set in src/core/include/megbrain/version.h Exports the following
# variables: MGB_VER_MAJOR: Major version MGB_VER_MINOR: Minor version MGB_VER_PATCH:
# Patch version MGB_IS_DEV: Is development version MGB_VER_STRING: Version string
4 5
option(MGB_FORCE_DEV_VERSION "Force -dev tag in version stamp" OFF)

6
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/core/include/megbrain/version.h" content)
7

8 9
string(REGEX MATCH "MGB_MAJOR +([0-9]+)" _ ${content})
set(MGB_VER_MAJOR ${CMAKE_MATCH_1})
10

11 12
string(REGEX MATCH "MGB_MINOR +([0-9]+)" _ ${content})
set(MGB_VER_MINOR ${CMAKE_MATCH_1})
13

14 15
string(REGEX MATCH "MGB_PATCH *([0-9]+)" _ ${content})
set(MGB_VER_PATCH ${CMAKE_MATCH_1})
16

17 18
string(REGEX MATCH "MGE_MAJOR +([0-9]+)" _ ${content})
set(MGE_VER_MAJOR ${CMAKE_MATCH_1})
19

20 21
string(REGEX MATCH "MGE_MINOR +([0-9]+)" _ ${content})
set(MGE_VER_MINOR ${CMAKE_MATCH_1})
22

23 24
string(REGEX MATCH "MGE_PATCH *([0-9]+)" _ ${content})
set(MGE_VER_PATCH ${CMAKE_MATCH_1})
25

26 27
string(REGEX MATCH "MGE_EXTRA_NAME *\"(.*)\"" _ ${content})
set(MGE_EXTRA_NAME ${CMAKE_MATCH_1})
M
Megvii Engine Team 已提交
28

29 30
if(MGB_FORCE_DEV_VERSION)
  set(MGB_IS_DEV 1)
31
else()
32 33
  string(REGEX MATCH "MGB_IS_DEV +([01])" _ ${content})
  set(MGB_IS_DEV ${CMAKE_MATCH_1})
34 35
endif()

36 37
if(DEFINED MGB_VER_MAJOR)
  set(MGB_VER_STRING "${MGB_VER_MAJOR}.${MGB_VER_MINOR}.${MGB_VER_PATCH}")
38
else()
39
  set(MGB_VER_STRING "${MGE_VER_MAJOR}.${MGE_VER_MINOR}.${MGE_VER_PATCH}")
40
endif(DEFINED MGB_VER_MAJOR)
41 42
if(MGB_IS_DEV)
  set(MGB_VER_STRING "${MGB_VER_STRING}-dev")
43 44
endif()

45
message(STATUS "Building MegBrain ${MGB_VER_STRING}")