• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  set(option_args)
31  set(one_value_args ELF_FILE OUTPUT)
32  set(multi_value_args)
33  _pw_parse_argv_strict(pw_bloaty_config
34      1 "${option_args}" "${one_value_args}" "${multi_value_args}"
35  )
36
37  if("${arg_ELF_FILE}" STREQUAL "")
38    message(FATAL_ERROR
39      "pw_bloaty_config requires an input ELF file in ELF_FILE. "
40      "No ELF_FILE was listed for ${NAME}")
41  endif()
42
43  if("${arg_OUTPUT}" STREQUAL "")
44    message(FATAL_ERROR
45      "pw_bloaty_config requires an output config file in OUTPUT. "
46      "No OUTPUT was listed for ${NAME}")
47  endif()
48
49  add_library(${NAME} INTERFACE)
50  add_dependencies(${NAME} INTERFACE ${NAME}_generated_config)
51
52  add_custom_command(
53    COMMENT "Generating ${NAME}'s ${arg_OUTPUT} for ${arg_ELF_FILE}."
54    COMMAND
55       ${Python3_EXECUTABLE}
56       "$ENV{PW_ROOT}/pw_bloat/py/pw_bloat/bloaty_config.py"
57       ${arg_ELF_FILE} -o ${arg_OUTPUT} -l warning
58    DEPENDS ${arg_ELF_FILE}
59    OUTPUT ${arg_OUTPUT} POST_BUILD
60  )
61  add_custom_target(${NAME}_generated_config
62    DEPENDS ${arg_OUTPUT}
63  )
64endfunction()
65