| # Copyright 2021 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/pigweed.gni") |
| import("$dir_pw_arduino_build/arduino.gni") |
| import("$dir_pw_build/target_types.gni") |
| |
| # Declare a teensy arduino library target |
| # |
| # teensy_library_source_set creates a pw_source_set target for a specified library |
| # under $pw_arduino_build_CORE_PATH/teensy/hardware/teensy/avr/libraries. It gathers |
| # the c/cpp source files and include directories for the library. Caller of the |
| # template can provide additional attributes of a regular pw_source_set into the |
| # target. |
| # |
| # Example: |
| # |
| # The following defines a pw_source_set target for |
| # $pw_arduino_build_CORE_PATH/teensy/hardware/teensy/avr/libraries/NativeEthernet |
| # |
| # teensy_library_source_set("native_ethernet") { |
| # library_name = "NativeEthernet" |
| # # Additional values to pass |
| # public_deps = [ ... ] |
| # public_configs = [ ... ] |
| # } |
| # |
| # The template is only valid for arduino teensy. |
| assert( |
| pw_arduino_build_CORE_PATH != "" && pw_arduino_build_CORE_NAME == "teensy") |
| |
| template("teensy_library_source_set") { |
| assert(defined(invoker.library_name) && invoker.library_name != "") |
| _library_args = [ |
| "--library-path", |
| rebase_path( |
| "$pw_arduino_build_CORE_PATH/teensy/hardware/teensy/avr/libraries"), |
| "--library-names", |
| invoker.library_name, |
| ] |
| |
| show_command_args = arduino_show_command_args + _library_args |
| |
| # Gather the c files. |
| _library_c_files = exec_script(arduino_builder_script, |
| show_command_args + [ "--library-c-files" ], |
| "list lines") |
| |
| # Gather the cpp files. |
| _library_cpp_files = |
| exec_script(arduino_builder_script, |
| show_command_args + [ "--library-cpp-files" ], |
| "list lines") |
| |
| # Gather the include directories. |
| _library_include_dirs = |
| exec_script(arduino_builder_script, |
| show_command_args + [ "--library-include-dirs" ], |
| "list lines") |
| |
| public_config_name = target_name + "_public_config" |
| config(public_config_name) { |
| include_dirs = _library_include_dirs |
| } |
| |
| # Define the target |
| pw_source_set(target_name) { |
| # Gather values provided by inovker. |
| forward_variables_from(invoker, "*", [ "library_name" ]) |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ "$dir_pw_third_party/arduino:arduino_core_sources" ] |
| |
| if (!defined(sources)) { |
| sources = [] |
| } |
| sources += _library_c_files + _library_cpp_files |
| |
| if (!defined(include_dirs)) { |
| include_dirs = [] |
| } |
| include_dirs += _library_include_dirs |
| |
| if (!defined(remove_configs)) { |
| remove_configs = [] |
| } |
| remove_configs = [ "$dir_pw_build:strict_warnings" ] |
| |
| if (!defined(public_configs)) { |
| public_configs = [] |
| } |
| public_configs += [ ":$public_config_name" ] |
| } |
| } |