1# Copyright 2022 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. 14 15import("//build_overrides/pi_pico.gni") 16import("//build_overrides/pigweed.gni") 17 18import("$dir_pw_build/target_types.gni") 19 20# Generates a pico/config_autogen.h file as part of a source set that provides 21# the required include directory as a public config. 22# 23# Example contents: 24# 25# // AUTO GENERATED BY A GN generate_config_header TARGET 26# #include "boards/pico.h" 27# #include "cmsis/rename_exceptions.h" 28# 29# Arguments: 30# config_header_files (required): Includes that should be written to the 31# generated header file. 32template("generate_config_header") { 33 assert(defined(invoker.config_header_files), "No headers provided") 34 35 _generated_header_dir = "${target_gen_dir}/${target_name}_include" 36 _generated_header_path = "${_generated_header_dir}/pico/config_autogen.h" 37 38 # Provide the include path so the header is exposed when targets depend on 39 # the generate_config_header target. 40 config("${target_name}.public_include_dirs") { 41 include_dirs = [ "${_generated_header_dir}" ] 42 } 43 44 # Actually generate config_autogen.h. 45 generated_file("${target_name}.generated_header") { 46 outputs = [ "${_generated_header_path}" ] 47 _lines = [ "// AUTO GENERATED BY A GN generate_config_header TARGET" ] 48 foreach(_header, invoker.config_header_files) { 49 _lines += [ "#include \"${_header}\"" ] 50 } 51 52 # Join with newline. 53 _NEWLINE_CHAR = "$0x0A" 54 contents = string_join(_NEWLINE_CHAR, _lines) 55 } 56 57 # This source set bundles up the generated header such that depending on 58 # this template will allow targets to include "pico/config_autogen.h". 59 pw_source_set("${target_name}") { 60 public_configs = [ 61 "${PICO_ROOT}/gn:disable_warnings", 62 ":${target_name}.public_include_dirs", 63 ] 64 deps = [ ":${target_name}.generated_header" ] 65 public = [ "${_generated_header_path}" ] 66 forward_variables_from(invoker, "*", [ "config_header_files" ]) 67 } 68} 69