Debian Codegraph @

cmake/Modules/GenerateMap.cmake

raw
1 #
2 # Copyright (c) 2018 Anderson Toshiyuki Sasaki <[email protected]>
3 #
4 # Redistribution and use is allowed according to the terms of the New
5 # BSD license.
6 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
7 #
8
9 #.rst:
10 # GenerateMap
11 # -----------
12 #
13 # This is a helper script for FindABImap.cmake.
14 #
15 # Generates a symbols version script using the abimap tool.
16 # This script is run in build time to use the correct command depending on the
17 # existence of the file provided ``CURRENT_MAP``.
18 #
19 # If the file exists, the ``abimap update`` subcommand is used to update the
20 # existing map. Otherwise, the ``abimap new`` subcommand is used to create a new
21 # map file.
22 #
23 # If the file provided in ``CURRENT_MAP`` exists, it is copied to the
24 # ``OUTPUT_PATH`` before updating.
25 # This is required because ``abimap`` do not generate output if no symbols were
26 # changed when updating an existing file.
27 #
28 # Expected defined variables
29 # --------------------------
30 #
31 # ``SYMBOLS``:
32 # Required file containing the symbols to be used as input. Usually this is
33 # the ``OUTPUT`` generated by ``extract_symbols()`` function provided in
34 # FindABImap.cmake
35 #
36 # ``RELEASE_NAME_VERSION``:
37 # Required, expects the library name and version information to be added to
38 # the symbols in the format ``library_name_1_2_3``
39 #
40 # ``CURRENT_MAP``:
41 # Required, expects the path to the current map file (or the path were it
42 # should be)
43 #
44 # ``OUTPUT_PATH``:
45 # Required, expects the output file path.
46 #
47 # ``ABIMAP_EXECUTABLE``:
48 # Required, expects the path to the ``abimap`` tool.
49 #
50 # Optionally defined variables
51 # ----------------------------
52 #
53 # ``FINAL``:
54 # If defined, will mark the modified set of symbols in the symbol version
55 # script as final, preventing later changes using ``abimap``.
56 #
57 # ``BREAK_ABI``:
58 # If defined, the build will not fail if symbols were removed.
59 # If defined and a symbol is removed, a new release is created containing
60 # all symbols from all released versions. This makes an incompatible release.
61 #
62
63 if (NOT DEFINED RELEASE_NAME_VERSION)
64 message(SEND_ERROR "RELEASE_NAME_VERSION not defined")
65 endif()
66
67 if (NOT DEFINED SYMBOLS)
68 message(SEND_ERROR "SYMBOLS not defined")
69 endif()
70
71 if (NOT DEFINED CURRENT_MAP)
72 message(SEND_ERROR "CURRENT_MAP not defined")
73 endif()
74
75 if (NOT DEFINED OUTPUT_PATH)
76 message(SEND_ERROR "OUTPUT_PATH not defined")
77 endif()
78
79 if (NOT ABIMAP_EXECUTABLE)
80 message(SEND_ERROR "ABIMAP_EXECUTABLE not defined")
81 endif()
82
83 set(ARGS_LIST)
84
85 if (FINAL)
86 list(APPEND ARGS_LIST "--final")
87 endif()
88
89 if (EXISTS ${CURRENT_MAP})
90 if (BREAK_ABI)
91 list(APPEND ARGS_LIST "--allow-abi-break")
92 endif()
93
94 execute_process(
95 COMMAND
96 ${CMAKE_COMMAND} -E copy_if_different ${CURRENT_MAP} ${OUTPUT_PATH}
97 COMMAND
98 ${ABIMAP_EXECUTABLE} update ${ARGS_LIST}
99 -r ${RELEASE_NAME_VERSION}
100 -i ${SYMBOLS}
101 -o ${OUTPUT_PATH}
102 ${CURRENT_MAP}
103 RESULT_VARIABLE result
104 )
105 else ()
106 execute_process(
107 COMMAND
108 ${ABIMAP_EXECUTABLE} new ${ARGS_LIST}
109 -r ${RELEASE_NAME_VERSION}
110 -i ${SYMBOLS}
111 -o ${OUTPUT_PATH}
112 RESULT_VARIABLE result
113 )
114 endif()
115
116 if (NOT "${result}" STREQUAL "0")
117 message(SEND_ERROR "Map generation failed")
118 endif()