# Copyright 2022 The Pigweed Authors # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. import("//build_overrides/pi_pico.gni") import("//build_overrides/pigweed.gni") import("$dir_pw_build/target_types.gni") # Generates a pico/config_autogen.h file as part of a source set that provides # the required include directory as a public config. # # Example contents: # # // AUTO GENERATED BY A GN generate_config_header TARGET # #include "boards/pico.h" # #include "cmsis/rename_exceptions.h" # # Arguments: # config_header_files (required): Includes that should be written to the # generated header file. template("generate_config_header") { assert(defined(invoker.config_header_files), "No headers provided") _generated_header_dir = "${target_gen_dir}/${target_name}_include" _generated_header_path = "${_generated_header_dir}/pico/config_autogen.h" # Provide the include path so the header is exposed when targets depend on # the generate_config_header target. config("${target_name}.public_include_dirs") { include_dirs = [ "${_generated_header_dir}" ] } # Actually generate config_autogen.h. generated_file("${target_name}.generated_header") { outputs = [ "${_generated_header_path}" ] _lines = [ "// AUTO GENERATED BY A GN generate_config_header TARGET" ] foreach(_header, invoker.config_header_files) { _lines += [ "#include \"${_header}\"" ] } # Join with newline. _NEWLINE_CHAR = "$0x0A" contents = string_join(_NEWLINE_CHAR, _lines) } # This source set bundles up the generated header such that depending on # this template will allow targets to include "pico/config_autogen.h". pw_source_set("${target_name}") { public_configs = [ "${PICO_ROOT}/gn:disable_warnings", ":${target_name}.public_include_dirs", ] deps = [ ":${target_name}.generated_header" ] public = [ "${_generated_header_path}" ] forward_variables_from(invoker, "*", [ "config_header_files" ]) } }