a = "mypath"
b = "$a/foo.cc" # b -> "mypath/foo.cc"
c = "foo${a}bar.cc" # c -> "foomypathbar.cc"
a = [ "first" ]
a += [ "second" ] # [ "first", "second" ]
a += [ "third", "fourth" ] # [ "first", "second", "third", "fourth" ]
b = a + [ "fifth" ] # [ "first", "second", "third", "fourth", "fifth" ]
a = [ "first", "second", "third", "first" ]
b = a - [ "first" ] # [ "second", "third" ]
a -= [ "second" ] # [ "first", "third", "fourth" ]
a = [ "first", "second", "third" ]
b = a[1] # -> "second"
a = [“one”]
a = [“two”]#错误:用非空列表覆盖非空列表。
a = []#OK
a = [“two”]#OK
if(is_linux ||(is_win && target_cpu ==“x86”)){
sources -= [ "something.cc" ]
} else if(...){
...
} else {
...
}
foreach(i,mylist){
print(i) # Note: i is a copy of each element, not a reference to it.
}
print("hello, world")
assert(is_win, "This should only be executed on Windows")
static_library(“mylibrary”){
sources = [“a.cc”]
}
"foo.cc"
"src/foo.cc"
"../src/foo.cc"
“//net/foo.cc”
“//base/test/foo.cc”
"/usr/local/include/"
"/C:/Program Files/Windows Kits/Include"
类型 | 说明 |
---|---|
action | 运行一个脚本来生成一个文件 |
action_foreach | 为每个源文件运行一次脚本 |
bundle_data | 声明数据加入到Mac / iOS包 |
create_bundle | 创建一个Mac / iOS包 |
executable | 生成一个可执行文件 |
group | 引用一个或多个其他目标的虚拟依赖关系节点 |
shared_library | .dll或.so |
loadable_module | .dll或.so只能在运行时加载 |
source_set | 个轻量级的虚拟静态库(通常比真正的静态库更可取,因为它的构建速度会更快) |
static_library | .lib或.a文件(通常你会想要一个source_set) |
component | 源集或共享库,取决于构建类型 |
test | 测试可执行文件 在移动设备上,这将为测试创建适当的本机应用程序类型 |
app | 可执行文件或Mac / iOS应用程序 |
android_apk | 制作一个APK。有很多其他的Android模版,看//build/config/android/rules.gni |
config("myconfig") {
includes = [ "src/include" ]
defines = [ "ENABLE_DOOM_MELON" ]
}
executable("doom_melon") {
configs = [ ":myconfig" ]
}
config("my_external_library_config") {
includes = "."
defines = [ "DISABLE_JANK" ]
}
shared_library("my_external_library") {
...
# Targets that depend on this get this config applied.
public_configs = [ ":my_external_library_config" ]
}
static_library("intermediate_library") {
...
# Targets that depend on this one also get the configs from "my external library".
public_deps = [ ":my_external_library" ]
}
# Declares a script that compiles IDL files to source, and then compiles those
#source files.
template("idl") { #Always base helper targets on target_name so they're unique。Target name
#will be the string passed as the name when the template is invoked.
idl_target_name =“$ {target_name} _generate”
action_foreach(idl_target_name){
...
}
#Your template should always define a target with the name target_name.
#When other targets depend on your template invocation, this will be the
#destination of that dependency.
source_set(target_name){
...
deps = [ ":$idl_target_name" ] # Require the sources to be compiled.
}
}
import("//tools/idl_compiler.gni")
idl("my_interfaces") {
sources = [ "a.idl", "b.idl" ]
}
template("idl") {
source_set(target_name){
sources = invoker.sources
}
}
本文分享自 Rice 嵌入式开发技术分享 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!