aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules/GenerateMap.cmake
blob: c22dfbc3c330a021e6caaf74e3f8dd4d51853bf5 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#
#  Copyright (c) 2018 Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
#
#  Redistribution and use is allowed according to the terms of the New
#  BSD license.
#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

#.rst:
# GenerateMap
# -----------
#
# This is a helper script for FindABImap.cmake.
#
# Generates a symbols version script using the abimap tool.
# This script is run in build time to use the correct command depending on the
# existence of the file provided ``CURRENT_MAP``.
#
# If the file exists, the ``abimap update`` subcommand is used to update the
# existing map. Otherwise, the ``abimap new`` subcommand is used to create a new
# map file.
#
# If the file provided in ``CURRENT_MAP`` exists, it is copied to the
# ``OUTPUT_PATH`` before updating.
# This is required because ``abimap`` do not generate output if no symbols were
# changed when updating an existing file.
#
# Expected defined variables
# --------------------------
#
# ``SYMBOLS``:
#   Required file containing the symbols to be used as input. Usually this is
#   the ``OUTPUT`` generated by ``extract_symbols()`` function provided in
#   FindABImap.cmake
#
# ``RELEASE_NAME_VERSION``:
#   Required, expects the library name and version information to be added to
#   the symbols in the format ``library_name_1_2_3``
#
# ``CURRENT_MAP``:
#   Required, expects the path to the current map file (or the path were it
#   should be)
#
# ``OUTPUT_PATH``:
#   Required, expects the output file path.
#
# ``ABIMAP_EXECUTABLE``:
#   Required, expects the path to the ``abimap`` tool.
#
# Optionally defined variables
# ----------------------------
#
# ``FINAL``:
#   If defined, will mark the modified set of symbols in the symbol version
#   script as final, preventing later changes using ``abimap``.
#
# ``BREAK_ABI``:
#   If defined, the build will not fail if symbols were removed.
#   If defined and a symbol is removed, a new release is created containing
#   all symbols from all released versions. This makes an incompatible release.
#

if (NOT DEFINED RELEASE_NAME_VERSION)
    message(SEND_ERROR "RELEASE_NAME_VERSION not defined")
endif()

if (NOT DEFINED SYMBOLS)
    message(SEND_ERROR "SYMBOLS not defined")
endif()

if (NOT DEFINED CURRENT_MAP)
    message(SEND_ERROR "CURRENT_MAP not defined")
endif()

if (NOT DEFINED OUTPUT_PATH)
    message(SEND_ERROR "OUTPUT_PATH not defined")
endif()

if (NOT ABIMAP_EXECUTABLE)
    message(SEND_ERROR "ABIMAP_EXECUTABLE not defined")
endif()

set(ARGS_LIST)

if (FINAL)
    list(APPEND ARGS_LIST "--final")
endif()

if (EXISTS ${CURRENT_MAP})
    if (BREAK_ABI)
        list(APPEND ARGS_LIST "--allow-abi-break")
    endif()

    execute_process(
      COMMAND
        ${CMAKE_COMMAND} -E copy_if_different ${CURRENT_MAP} ${OUTPUT_PATH}
      COMMAND
        ${ABIMAP_EXECUTABLE} update ${ARGS_LIST}
        -r ${RELEASE_NAME_VERSION}
        -i ${SYMBOLS}
        -o ${OUTPUT_PATH}
        ${CURRENT_MAP}
      RESULT_VARIABLE result
    )
else ()
    execute_process(
      COMMAND
        ${ABIMAP_EXECUTABLE} new ${ARGS_LIST}
        -r ${RELEASE_NAME_VERSION}
        -i ${SYMBOLS}
        -o ${OUTPUT_PATH}
      RESULT_VARIABLE result
    )
endif()

if (NOT "${result}" STREQUAL "0")
    message(SEND_ERROR "Map generation failed")
endif()