# Copyright (c) 2022 Huawei Device Co., Ltd. # 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_root/ark_var.gni") template("ohos_executable") { if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { subsystem_name = invoker.subsystem_name part_name = invoker.part_name } else if (defined(invoker.subsystem_name)) { subsystem_name = invoker.subsystem_name part_name = subsystem_name } else { subsystem_name = "arkcompiler" part_name = "common" } assert(part_name != "") assert(subsystem_name != "") if (defined(invoker.unit_test) && invoker.unit_test) { output_dir = invoker.test_output_dir } else { output_dir = "${root_out_dir}/${subsystem_name}/${part_name}" } executable(target_name) { forward_variables_from(invoker, "*", [ "configs", "remove_configs", "subsystem_name", "install_enable", "part_name", "use_exceptions", "static_link", "output_dir", "unit_test", "external_deps", "stack_protector_ret", ]) output_dir = output_dir if (defined(invoker.configs)) { configs += invoker.configs } if (defined(invoker.remove_configs)) { configs -= invoker.remove_configs } if (defined(invoker.use_exceptions) && invoker.use_exceptions) { configs += [ "//arkcompiler/toolchain/build/config/compiler:exceptions" ] ldflags = [] } if (!defined(libs)) { libs = [] } if (!defined(ldflags)) { ldflags = [] } if (!defined(inputs)) { inputs = [] } if (defined(version_script)) { _version_script = rebase_path(version_script, root_build_dir) inputs += [ version_script ] ldflags += [ "-Wl,--version-script=${_version_script}" ] } if (defined(invoker.static_link) && invoker.static_link) { no_default_deps = true ldflags += [ "-static" ] configs -= [ "$build_root/config:executable_config" ] if (is_ohos) { import("$build_root/config/ohos/musl.gni") deps += [ "$build_root/third_party_gn/musl:soft_static_libs" ] } } else if (is_ohos) { if (current_cpu == "arm" || current_cpu == "arm64") { libs += [ "unwind" ] } libs += [ "c++" ] } if (defined(invoker.external_deps) && invoker.external_deps != []) { if (!defined(deps)) { deps = [] } external_deps_temp_file = "$target_gen_dir/${part_name}__${target_name}_external_deps_temp.json" arguments = [ "--root-src-dir", rebase_path("//", root_build_dir), "--external-deps-temp-file", rebase_path(external_deps_temp_file, root_build_dir), "--external-deps", ] arguments += invoker.external_deps exec_script("$build_root/templates/cxx/external_deps_handler.py", arguments, "string") external_deps_info = read_file(external_deps_temp_file, "json") if (defined(external_deps_info.deps)) { deps += external_deps_info.deps } } } } template("ohos_static_library") { if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { part_name = invoker.part_name } else if (defined(invoker.part_name)) { part_name = invoker.part_name } else if (defined(invoker.subsystem_name)) { part_name = invoker.subsystem_name } else { part_name = "common" } assert(part_name != "") static_library(target_name) { forward_variables_from(invoker, "*", [ "configs", "remove_configs", "subsystem_name", "part_name", "use_exceptions", "external_deps", "stack_protector_ret", ]) if (defined(invoker.configs)) { configs += invoker.configs } if (defined(invoker.remove_configs)) { configs -= invoker.remove_configs } if (defined(invoker.use_exceptions) && invoker.use_exceptions) { configs += [ "//arkcompiler/toolchain/build/config/compiler:exceptions" ] ldflags = [] } if (!defined(libs)) { libs = [] } if (!defined(include_dirs)) { include_dirs = [] } if (defined(invoker.external_deps) && invoker.external_deps != []) { if (!defined(deps)) { deps = [] } external_deps_temp_file = "$target_gen_dir/${part_name}__${target_name}_external_deps_temp.json" arguments = [ "--root-src-dir", rebase_path("//", root_build_dir), "--external-deps-temp-file", rebase_path(external_deps_temp_file, root_build_dir), "--external-deps", ] arguments += invoker.external_deps exec_script("$build_root/templates/cxx/external_deps_handler.py", arguments, "string") external_deps_info = read_file(external_deps_temp_file, "json") if (defined(external_deps_info.deps)) { deps += external_deps_info.deps } } } } template("ohos_shared_library") { if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { subsystem_name = invoker.subsystem_name part_name = invoker.part_name } else if (defined(invoker.subsystem_name)) { subsystem_name = invoker.subsystem_name part_name = subsystem_name } else { subsystem_name = "arkcompiler" part_name = "common" } output_dir = "${root_out_dir}/${subsystem_name}/${part_name}" shared_library(target_name) { forward_variables_from(invoker, "*", [ "relative_install_dir", "configs", "subsystem_name", "install_enable", "part_name", "output_dir", "install_images", "use_exceptions", "external_deps", "stack_protector_ret", "innerapi_tags", ]) output_dir = output_dir if (defined(invoker.configs)) { configs += invoker.configs } if (defined(invoker.remove_configs)) { configs -= invoker.remove_configs } if (!defined(libs)) { libs = [] } if (!defined(ldflags)) { ldflags = [] } if (!defined(inputs)) { inputs = [] } if (defined(version_script)) { _version_script = rebase_path(version_script, root_build_dir) inputs += [ version_script ] ldflags += [ "-Wl,--version-script=${_version_script}" ] } if (is_ohos) { if (defined(invoker.stl)) { cflags_cc += [ "-nostdinc++", "-I" + rebase_path( "//prebuilts/clang/ohos/${host_platform_dir}/llvm_ndk/include/c++/v1", root_build_dir), ] ldflags += [ "-nostdlib++", "-L" + rebase_path("${clang_stl_path}/${abi_target}/c++", root_build_dir), ] libs += [ invoker.stl ] } else { if (current_cpu == "arm" || current_cpu == "arm64") { libs += [ "unwind" ] } libs += [ "c++" ] } } if (defined(invoker.external_deps) && invoker.external_deps != []) { if (!defined(deps)) { deps = [] } external_deps_temp_file = "$target_gen_dir/${part_name}__${target_name}_external_deps_temp.json" arguments = [ "--root-src-dir", rebase_path("//", root_build_dir), "--external-deps-temp-file", rebase_path(external_deps_temp_file, root_build_dir), "--external-deps", ] arguments += invoker.external_deps exec_script("$build_root/templates/cxx/external_deps_handler.py", arguments, "string") external_deps_info = read_file(external_deps_temp_file, "json") if (defined(external_deps_info.deps)) { deps += external_deps_info.deps } } } } template("ohos_source_set") { if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { subsystem_name = invoker.subsystem_name part_name = invoker.part_name } else if (defined(invoker.subsystem_name)) { subsystem_name = invoker.subsystem_name part_name = subsystem_name } else { subsystem_name = "arkcompiler" part_name = "common" } assert(subsystem_name != "") assert(part_name != "") source_set(target_name) { forward_variables_from(invoker, "*", [ "configs", "remove_configs", "no_default_deps", "external_deps", "license_file", "license_as_sources", "use_exceptions", "subsystem_name", "part_name", "stack_protector_ret", ]) if (defined(invoker.configs)) { configs += invoker.configs } if (defined(invoker.remove_configs)) { configs -= invoker.remove_configs } if (defined(invoker.external_deps) && invoker.external_deps != []) { external_deps_temp_file = "$target_gen_dir/${part_name}__${target_name}_external_deps_temp.json" arguments = [ "--root-src-dir", rebase_path("//", root_build_dir), "--external-deps-temp-file", rebase_path(external_deps_temp_file, root_build_dir), "--external-deps", ] arguments += invoker.external_deps exec_script("$build_root/templates/cxx/external_deps_handler.py", arguments, "string") external_deps_info = read_file(external_deps_temp_file, "json") if (defined(external_deps_info.deps)) { deps += external_deps_info.deps } } } } template("ohos_copy") { assert(defined(invoker.sources), "sources must be defined for ${target_name}.") assert(defined(invoker.outputs), "outputs must be defined for ${target_name}.") if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { copy_subsystem_name = invoker.subsystem_name copy_part_name = invoker.part_name } else if (defined(invoker.subsystem_name)) { copy_subsystem_name = invoker.subsystem_name copy_part_name = copy_subsystem_name } else { copy_subsystem_name = "common" copy_part_name = copy_subsystem_name } assert(copy_subsystem_name != "") assert(copy_part_name != "") copy(target_name) { forward_variables_from(invoker, "*", [ "relative_install_dir", "module_source_dir", "module_install_name", "license_file", "install_enable", "module_type", ]) } }