gn编译webrtc介绍

本文介绍了如何使用gn命令编译WebRTC源代码,包括通过gclient下载源码,gn的用途和原理,以及.gn文件的语法解析,如目标类型、依赖管理和变量传递。重点讲解了在Windows平台上编译WebRTC的gn语法,并举例说明了静态库的编译过程。
摘要由CSDN通过智能技术生成

说明:由于需要通过gn编译webrtc源代码和自研代码的添加,在此介绍gn命令和格式。

概述:我们通过gclient实现webrtc源码的下载,下载完成后使用gn命令进行编译,此时生成对应平台的文件(.ninja)。  

gn参考:https://www.chromium.org/developers/gn-build-configuration

gn介绍:(generate ninja )顾名思义为生成ninja文件,为一个编译工具,是GYP(Generate Your Project)的替代工具,由google开源c++编写实现,主要实现交叉编译,可以指定输出平台目标,且可以指定多个目标平台。

gn gen out/Default --args='target_os="linux" target_cpu="x64"

既然是解释器那么就会有对应的语法,接下来以windows平台为例进行.gn语法介绍。

BUILD.gn文件,截取一段进行分析如下:

1:首先import.gni文件,该文件一般为公用的某些功能定义。

2:编译器会找到对应的目标进行编译,目标的含义是我们的模块需要编译生什么,比如静态库,动态库,或者运行程序等。只有指定目标编译器才能明确的生成。主要类型有如下:

executable:生成exe程序。group:包含一个多个目标虚拟节点。shared_library:生成静态库lib或.a。loadable_module:动态库或者.so。source_set:轻量级静态库(常用)。app:用于mac/ios。android_apk:生成andorid平台apk.

3:每个目标都会进行依赖deps包含。此时就会涉及到路径的问题,本地相同路径开头为冒号:。如果是根目录则是“//”开头。

4:一些变量通过gn的args传递。

# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This is the root build file for GN. GN will start processing by loading this
# file, and recursively load all dependencies until all dependencies are either
# resolved or known not to exist (which will cause the build to fail). So if
# you add a new build file, there must be some path of dependencies from this
# file to your new one or GN won't know about it.
import("//build/config/compiler/compiler.gni")
...
if (is_android) {
  import("//build/config/android/config.gni")
}

# This file defines the following two main targets:
#
# "gn_all" is used to create explicit dependencies from the root BUILD.gn to
# each top-level component that we wish to include when building everything via
# "all". This is required since the set of targets built by "all" is determined
# automatically based on reachability from the root BUILD.gn (for details, see
# crbug.com/503241). Builders should typically use "all", or list targets
# explicitly, rather than relying on "gn_all".
#
# "gn_visibility": targets that are normally not visible to top-level targets,
# but are built anyway by "all". Since we 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值