xref: /aosp_15_r20/external/pigweed/pw_bloat/bloat.cmake (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14include_guard(GLOBAL)
15
16include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
17
18# This function creates a library under the specified ${NAME} which provides a
19# a generated bloaty configuration for a given ELF file using
20# pw_bloat.bloaty_config.
21#
22# Produces the ${OUTPUT} Bloaty McBloatface configuration file.
23#
24# Args:
25#
26#   NAME - name of the library to create
27#   ELF_FILE - The input ELF file to process using pw_bloat.bloaty_config
28#   OUTPUT - The output Bloaty McBloatface configuration file
29function(pw_bloaty_config NAME)
30  pw_parse_arguments(
31    NUM_POSITIONAL_ARGS
32      1
33    ONE_VALUE_ARGS
34      ELF_FILE
35      OUTPUT
36    REQUIRED_ARGS
37      ELF_FILE
38      OUTPUT
39  )
40  add_library(${NAME} INTERFACE)
41  add_dependencies(${NAME} INTERFACE ${NAME}_generated_config)
42
43  add_custom_command(
44    COMMENT "Generating ${NAME}'s ${arg_OUTPUT} for ${arg_ELF_FILE}."
45    COMMAND
46       ${Python3_EXECUTABLE}
47       "$ENV{PW_ROOT}/pw_bloat/py/pw_bloat/bloaty_config.py"
48       ${arg_ELF_FILE} -o ${arg_OUTPUT} -l warning
49    DEPENDS ${arg_ELF_FILE}
50    OUTPUT ${arg_OUTPUT} POST_BUILD
51  )
52  add_custom_target(${NAME}_generated_config
53    DEPENDS ${arg_OUTPUT}
54  )
55endfunction()
56