File: ProjectVersioning.cmake

package info (click to toggle)
qt-color-widgets 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 916 kB
  • sloc: cpp: 6,923; sh: 236; makefile: 13
file content (80 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download | duplicates (3)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
define_property (TARGET
  PROPERTY GIT_DESCRIBE
  BRIEF_DOCS "Advanced version info for developers"
  FULL_DOCS "String with information that is important for developers during
  development process. This information includes git commit hash, durty status
  of repo, distance from the last tag.")

define_property (TARGET
  PROPERTY GIT_UNTRACKED_FILES
  BRIEF_DOCS "Information about presence of untracked files"
  FULL_DOCS "Used in helper functions generation to add .with-untracked suffix
  to version string. Suffix is only added if there are some untracked not
  ignored files in repository.")

set(HERE_DIR ${CMAKE_CURRENT_LIST_DIR})


function (target_version_information
	TARGET_NAME i_target_name
    EXPORT_HEADER i_export_header
    EXPORT_MACRO i_export_macro
    VERSIONED_ENTITY i_versioned_entity)

  find_file (
	headerFileTemplate
	"ProjectVersioning/version.h.in"
	PATHS ${CMAKE_MODULE_PATH})

    if ( NOT ${headerFileTemplate} )
        set(headerFileTemplate "${HERE_DIR}/ProjectVersioning/version.h.in")
    endif()

  find_file (
	sourceFileTemplate
	"ProjectVersioning/version.c.in"
	PATHS ${CMAKE_MODULE_PATH})

    if ( NOT ${sourceFileTemplate} )
        set(sourceFileTemplate "${HERE_DIR}/ProjectVersioning/version.c.in")
    endif()

  exec_program (
	"git"
	${CMAKE_SOURCE_DIR}
	ARGS "describe --always --dirty --long --tags"
	OUTPUT_VARIABLE gitDescribe)

  exec_program (
	"git"
	${CMAKE_SOURCE_DIR}
	ARGS "ls-files --others --exclude-standard"
	OUTPUT_VARIABLE gitUntracked)

  if (gitUntracked)
	set (gitUntracked ".with-untracked")
  endif (gitUntracked)

  configure_file (
	"${headerFileTemplate}"
	"${CMAKE_CURRENT_BINARY_DIR}/${i_versioned_entity}_version.h")

  configure_file(
	"${sourceFileTemplate}"
	"${CMAKE_BINARY_DIR}/${i_versioned_entity}_version.c")

  target_sources ("${i_target_name}"
    PRIVATE
    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${i_versioned_entity}_version.h>
    $<INSTALL_INTERFACE:include/${i_include_prefix}/${i_versioned_entity}_version.h>
	PRIVATE
	"${CMAKE_BINARY_DIR}/${i_versioned_entity}_version.c")

  set_target_properties (${i_target_name}
	PROPERTIES
	GIT_DESCRIBE "${gitDescribe}"
	GIT_UNTRACKED_FILES "${gitUntracked}")

  unset (headerFileTemplate PARENT_SCOPE)
  unset (sourceFileTemplate PARENT_SCOPE)
endfunction (target_version_information)