| # Copyright (c) 2022 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/build.gni") | 
 | import("//build_overrides/chip.gni") | 
 |  | 
 | import("${chip_root}/build/chip/tools.gni") | 
 | import("${chip_root}/build/config/mac/mac_sdk.gni") | 
 | import("${chip_root}/examples//chip-tool/chip-tool.gni") | 
 |  | 
 | if (config_use_interactive_mode) { | 
 |   import("//build_overrides/editline.gni") | 
 | } | 
 |  | 
 | assert(chip_build_tools) | 
 |  | 
 | declare_args() { | 
 |   chip_codesign = current_os == "ios" | 
 | } | 
 |  | 
 | sdk = "macosx" | 
 | sdk_build_dir_suffix = "" | 
 | if (getenv("SDKROOT") != "") { | 
 |   sdk = getenv("SDKROOT") | 
 |   sdk_root_parts = string_split(getenv("SDKROOT"), ".") | 
 |   sdk_build_dir_suffix = "-${sdk_root_parts[0]}" | 
 | } | 
 | output_sdk_type = "Debug${sdk_build_dir_suffix}" | 
 |  | 
 | action("build-darwin-framework") { | 
 |   script = "${chip_root}/scripts/build/build_darwin_framework.py" | 
 |  | 
 |   inputs = [ | 
 |     "${chip_root}/src/darwin/Framework/CHIP", | 
 |     "${chip_root}/src/darwin/Framework/CHIP/zap-generated", | 
 |     "${chip_root}/src/darwin/Framework/Matter.xcodeproj", | 
 |   ] | 
 |  | 
 |   args = [ | 
 |     "--project_path", | 
 |     rebase_path("${chip_root}/src/darwin/Framework/Matter.xcodeproj", | 
 |                 root_build_dir), | 
 |     "--out_path", | 
 |     "macos_framework_output", | 
 |     "--target", | 
 |     "Matter Framework", | 
 |     "--log_path", | 
 |     rebase_path("${root_build_dir}/darwin_framework_build.log", root_build_dir), | 
 |   ] | 
 |  | 
 |   if (sdk != "macosx") { | 
 |     args += [ | 
 |       "--target_sdk", | 
 |       sdk, | 
 |       "--target_arch", | 
 |       mac_target_arch, | 
 |     ] | 
 |   } | 
 |  | 
 |   output_name = "Matter.framework" | 
 |   outputs = [ | 
 |     "${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/${output_name}", | 
 |     "${root_build_dir}/darwin_framework_build.log", | 
 |     "${root_out_dir}/macos_framework_output/ModuleCache.noindex/", | 
 |     "${root_out_dir}/macos_framework_output/Logs", | 
 |     "${root_out_dir}/macos_framework_output/Index", | 
 |     "${root_out_dir}/macos_framework_output/Build", | 
 |   ] | 
 | } | 
 |  | 
 | config("config") { | 
 |   include_dirs = [ | 
 |     ".", | 
 |     "${chip_root}/examples/darwin-framework-tool/commands/common", | 
 |     "${chip_root}/zzz_generated/darwin-framework-tool", | 
 |     "${chip_root}/zzz_generated/controller-clusters", | 
 |     "${chip_root}/examples/chip-tool", | 
 |     "${chip_root}/zzz_generated/chip-tool", | 
 |     "${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/", | 
 |   ] | 
 |  | 
 |   framework_dirs = [ | 
 |     "${root_out_dir}/macos_framework_output/Build/Products/${output_sdk_type}/", | 
 |   ] | 
 |  | 
 |   defines = [ | 
 |     "CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}", | 
 |     "CONFIG_USE_INTERACTIVE_MODE=${config_use_interactive_mode}", | 
 |   ] | 
 |  | 
 |   cflags = [ | 
 |     "-Wconversion", | 
 |     "-fobjc-arc", | 
 |  | 
 |     # For now disable unguarded-availability-new warnings because we | 
 |     # are not building against a system Matter.framework here anyway. | 
 |     "-Wno-unguarded-availability-new", | 
 |   ] | 
 | } | 
 |  | 
 | executable("darwin-framework-tool") { | 
 |   sources = [ | 
 |     "${chip_root}/examples/chip-tool/commands/common/Command.cpp", | 
 |     "${chip_root}/examples/chip-tool/commands/common/Command.h", | 
 |     "${chip_root}/examples/chip-tool/commands/common/Commands.cpp", | 
 |     "${chip_root}/examples/chip-tool/commands/common/Commands.h", | 
 |     "${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp", | 
 |     "commands/clusters/ClusterCommandBridge.h", | 
 |     "commands/clusters/ModelCommandBridge.mm", | 
 |     "commands/clusters/ReportCommandBridge.h", | 
 |     "commands/clusters/WriteAttributeCommandBridge.h", | 
 |     "commands/common/CHIPCommandBridge.mm", | 
 |     "commands/common/CHIPCommandStorageDelegate.mm", | 
 |     "commands/common/CHIPToolKeypair.mm", | 
 |     "commands/common/MTRDevice_Externs.h", | 
 |     "commands/common/MTRError.mm", | 
 |     "commands/common/MTRError_Utils.h", | 
 |     "commands/common/MTRLogging.h", | 
 |     "commands/pairing/Commands.h", | 
 |     "commands/pairing/OpenCommissioningWindowCommand.h", | 
 |     "commands/pairing/OpenCommissioningWindowCommand.mm", | 
 |     "commands/pairing/PairingCommandBridge.mm", | 
 |     "commands/pairing/PairingDelegateBridge.mm", | 
 |     "commands/payload/SetupPayloadParseCommand.mm", | 
 |     "commands/provider/Commands.h", | 
 |     "commands/provider/OTAProviderDelegate.mm", | 
 |     "commands/provider/OTASoftwareUpdateInteractive.mm", | 
 |     "commands/storage/Commands.h", | 
 |     "commands/storage/StorageManagementCommand.mm", | 
 |     "main.mm", | 
 |   ] | 
 |  | 
 |   deps = [ | 
 |     ":build-darwin-framework", | 
 |     "${chip_root}/src/app/tests/suites/commands/delay", | 
 |  | 
 |     # IM is needed for MTRError | 
 |     "${chip_root}/src/app/tests/suites/commands/interaction_model", | 
 |  | 
 |     # Log is needed by tests UserPrompt and Log | 
 |     "${chip_root}/src/app/tests/suites/commands/log", | 
 |  | 
 |     # System is needed by tests FactoryReset etc.. | 
 |     "${chip_root}/src/app/tests/suites/commands/system", | 
 |  | 
 |     # pics is needed by tests | 
 |     "${chip_root}/src/app/tests/suites/pics", | 
 |     "${chip_root}/third_party/inipp", | 
 |     "${chip_root}/third_party/jsoncpp", | 
 |   ] | 
 |  | 
 |   if (config_use_interactive_mode) { | 
 |     sources += [ "commands/interactive/InteractiveCommands.mm" ] | 
 |     deps += [ "${editline_root}:editline" ] | 
 |   } | 
 |  | 
 |   ldflags = [ | 
 |     "-rpath", | 
 |     "@executable_path/macos_framework_output/Build/Products/${output_sdk_type}/", | 
 |   ] | 
 |  | 
 |   frameworks = [ | 
 |     "Matter.framework", | 
 |     "Security.framework", | 
 |   ] | 
 |  | 
 |   public_configs = [ ":config" ] | 
 |  | 
 |   output_dir = root_out_dir | 
 | } | 
 |  | 
 | if (chip_codesign) { | 
 |   action("codesign") { | 
 |     script = "entitlements/codesign.py" | 
 |     public_deps = [ ":darwin-framework-tool" ] | 
 |  | 
 |     args = [ | 
 |       "--target_path", | 
 |       rebase_path("${root_build_dir}/darwin-framework-tool", root_build_dir), | 
 |       "--log_path", | 
 |       rebase_path("${root_build_dir}/codesign_log.txt", root_build_dir), | 
 |     ] | 
 |  | 
 |     output_name = "codesign_log.txt" | 
 |     outputs = [ "${root_build_dir}/${output_name}" ] | 
 |   } | 
 | } |