File: buildnumber.cmake

package info (click to toggle)
obs-source-clone 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 632 kB
  • sloc: ansic: 1,020; sh: 259; makefile: 23; cpp: 16
file content (30 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# CMake build number module

include_guard(GLOBAL)

# Define build number cache file
set(
  _BUILD_NUMBER_CACHE
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/.CMakeBuildNumber"
  CACHE INTERNAL
  "OBS build number cache file"
)

# Read build number from cache file or manual override
if(NOT DEFINED PLUGIN_BUILD_NUMBER)
  if(EXISTS "${_BUILD_NUMBER_CACHE}")
    file(READ "${_BUILD_NUMBER_CACHE}" PLUGIN_BUILD_NUMBER)
    math(EXPR PLUGIN_BUILD_NUMBER "${PLUGIN_BUILD_NUMBER}+1")
  else()
    if("$ENV{CI}")
      if("$ENV{GITHUB_RUN_ID}")
        set(PLUGIN_BUILD_NUMBER "$ENV{GITHUB_RUN_ID}")
      elseif("$ENV{GITLAB_RUN_ID}")
        set(PLUGIN_BUILD_NUMBER "$ENV{GITLAB_RUN_ID}")
      else()
        set(PLUGIN_BUILD_NUMBER "1")
      endif()
    endif()
  endif()
  file(WRITE "${_BUILD_NUMBER_CACHE}" "${PLUGIN_BUILD_NUMBER}")
endif()