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. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/target_types.gni") 18 19declare_args() { 20 # Location of MCUXpresso SDK directory 21 dir_pw_third_party_mcuxpresso = "" 22 23 # If compiling a project against an MCUXpresso SDK, this variable can be set 24 # to the name of the pw_source_set you create using `pw_mcuxpresso_sdk` to 25 # enable additional Pigweed support. 26 pw_third_party_mcuxpresso_SDK = "" 27} 28 29# Creates a source set for an MCUXpresso SDK. 30# 31# In addition to the named source set, two configs are created; one named 32# `${target_name}__defines` contains pre-processor definitions for the SDK 33# project and the other named `${target_name}__includes` defines the include 34# paths. These may be used to break circular dependencies. 35# 36# Args: 37# manifest: The MCUXpresso SDK manifest XML file describing the components of 38# the SDK. 39# 40# sdk_dir: Optional path to directory containing the SDK. When ommitted the 41# parent of `manifest` is used, which is usually the correct definition. 42# 43# include: list of SDK components to include in the project. 44# 45# exclude: Optional list of SDK components to exclude from the project. 46# 47# device_core: Optional name of device core to filter components for. 48# 49# allow_circular_includes_from, configs, deps, public_configs, public_deps: 50# Optional extra properties for the source set. 51# 52# Example: 53# 54# pw_mcuxpresso_sdk("sample_project_sdk") { 55# manifest = "$dir_pw_third_party/mcuxpresso/EVK-MIMXRT595_manifest_v3_13.xml" 56# include = [ "project_template.evkmimxrt595.MIMXRT595S" ] 57# device_core = "cm33_MIMXRT595S" 58# } 59# 60# pw_executable("hello_world") { 61# sources = [ "hello_world.cc "] 62# deps = [ ":sample_project_sdk" ] 63# } 64# 65template("pw_mcuxpresso_sdk") { 66 assert(defined(invoker.manifest), "pw_mcuxpresso_sdk requires a manifest") 67 68 if (defined(invoker.sdk_dir)) { 69 _sdk_dir = invoker.sdk_dir 70 } else { 71 _sdk_dir = get_path_info(invoker.manifest, "dir") 72 } 73 74 _script_args = [ 75 "gn", 76 rebase_path(invoker.manifest), 77 "--prefix=$_sdk_dir", 78 ] 79 80 if (defined(invoker.include)) { 81 foreach(dependency, invoker.include) { 82 _script_args += [ 83 "--include", 84 dependency, 85 ] 86 } 87 } 88 89 if (defined(invoker.exclude)) { 90 foreach(dependency, invoker.exclude) { 91 _script_args += [ 92 "--exclude", 93 dependency, 94 ] 95 } 96 } 97 98 if (defined(invoker.device_core)) { 99 _script_args += [ 100 "--device_core", 101 invoker.device_core, 102 ] 103 } 104 105 # This script finds the components distributed with the SDK. 106 _script = "$dir_pw_build_mcuxpresso/py/pw_build_mcuxpresso/__main__.py" 107 _project = exec_script(_script, _script_args, "scope", [ invoker.manifest ]) 108 109 config("${target_name}__defines") { 110 forward_variables_from(_project, [ "defines" ]) 111 } 112 113 config("${target_name}__includes") { 114 forward_variables_from(_project, [ "include_dirs" ]) 115 } 116 117 pw_source_set(target_name) { 118 forward_variables_from(_project, 119 [ 120 "libs", 121 "public", 122 "sources", 123 ]) 124 125 public_configs = [ 126 ":${target_name}__defines", 127 ":${target_name}__includes", 128 ] 129 if (defined(invoker.public_configs)) { 130 public_configs += invoker.public_configs 131 } 132 133 forward_variables_from(invoker, 134 [ 135 "configs", 136 "deps", 137 "public_deps", 138 "allow_circular_includes_from", 139 ]) 140 } 141} 142