| # Copyright (c) 2021 Project CHIP 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 |
| # |
| # http://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/p6.gni") |
| import("${p6_sdk_build_root}/p6_sdk.gni") |
| |
| declare_args() { |
| # Build target to use for p6 SDK. Use this to set global SDK defines. |
| p6_target_project = "" |
| } |
| |
| assert(p6_target_project != "", "p6_target_project must be specified") |
| |
| # Add includes, cflags, asmflags, etc in config |
| config("p6_sdk_config") { |
| # Pull out includes from generated json |
| # Treat these includes as system includes, so warnings in them are not fatal. |
| _include_dirs = [] |
| foreach(inc, mtb_json.includes) { |
| # Strip off leading -I part |
| _include_dirs += [ "/" + rebase_path(string_replace(inc, "-I", "", 1), |
| "/", |
| "${p6_sdk_build_root}/p6_sdk/") ] |
| } |
| |
| # Also add project include path (passed in from project build) |
| proj_path = get_label_info(p6_target_project, "dir") |
| _include_dirs += [ "/" + rebase_path("${proj_path}/include", "/", ".") ] |
| |
| cflags = [] |
| foreach(include_dir, _include_dirs) { |
| cflags += [ "-isystem" + include_dir ] |
| } |
| |
| # Pull out defines from generated json |
| defines = [] |
| foreach(def, mtb_json.defines) { |
| # Strip off leading -D part |
| defines += [ string_replace(def, "-D", "", 1) ] |
| } |
| |
| # Pull out static libs (.a files) from generated json |
| libs = [] |
| foreach(lib, mtb_json.libs) { |
| libs += [ "/" + rebase_path(lib, "/", "${p6_sdk_build_root}/p6_sdk/") ] |
| } |
| |
| cflags_c = mtb_json.cflags |
| cflags_cc = mtb_json.cxxflags |
| asmflags = mtb_json.asflags |
| ldflags = filter_exclude(mtb_json.ldflags, [ "-T*" ]) |
| |
| # Pull out linker flags with paths (-T flags) and make paths absolute |
| linker_script_flags = filter_include(mtb_json.ldflags, [ "-T*" ]) |
| foreach(flag, linker_script_flags) { |
| ldflags += [ "-T/" + rebase_path(string_replace(flag, "-T", "", 1), |
| "/", |
| "${p6_sdk_build_root}/p6_sdk/") ] |
| } |
| |
| # --specs=nano.specs is getting added twice and causing compile issues so remove from cxx flags here. |
| cflags_c -= [ "--specs=nano.specs" ] |
| cflags_cc -= [ "--specs=nano.specs" ] |
| asmflags -= [ "--specs=nano.specs" ] |
| ldflags -= [ "--specs=nano.specs" ] |
| } |
| |
| group("p6_build") { |
| public_configs = [ ":p6_sdk_config" ] |
| public_deps = [ p6_target_project ] |
| } |