GN & ninja 工程化构建例程

请添加图片描述


1. 前言✨

本文通过一个简单的C语言工程构建实例,主要描述通过GN和ninjia如何构建、编译。

各位小伙伴,如果你是刚接触GN、ninja构建,这个实例工程非常适合你参考、学习,该实例包括静态库、动态库的编译、链接,还有对编译工具链的配置,编译输出的配置等,如果对你有帮助,请点赞👍👍👍、转发,评论&交流😊。💐💐💐🎉🎉🎉


2. 工程实例🚩

2.1 工程目录结构

.
├── BUILD.gn
├── README.md
├── build
│   ├── BUILD.gn
│   ├── BUILDCONFIG.gn
│   └── toolchains
│       └── BUILD.gn
├── include
│   └── utils.h
├── lib
│   ├── shared
│   │   ├── BUILD.gn
│   │   └── dlib.c
│   └── static
│       ├── BUILD.gn
│       └── slib.c
├── out
│   └── Default
│       ├── args.gn
│       ├── build.ninja
│       ├── build.ninja.d
│       ├── build.ninja.stamp
│       ├── libshared.so
│       ├── main
│       ├── obj
│       └── toolchain.ninja
├── src
│   └── main
│       ├── BUILD.gn
│       └── main.c
└── third_party

13 directories, 19 files

2.2 工程顶层.gn文件

BUILD.gn

# 顶层group定义
group("all") {
   
  deps = [
    "//lib/static",
    "//lib/shared",
    "//src/main"
  ]
}

2.3 工具链配置.gn文件

build/toolchains/BUILD.gn

# Copyright 2014 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.

toolchain("gcc") {
   
  tool("cc") {
   
    depfile = "{
   {output}}.d"
    command = "gcc -MMD -MF $depfile {
   {defines}} {
   {include_dirs}} {
   {cflags}} {
   {cflags_c}} -c {
   {source}} -o {
   {output}}"
    depsformat = "gcc"
    description = "CC {
   {output}}"
    outputs = [
      "{
   {source_out_dir}}/{
   {target_output_name}}.{
   {source_name_part}}.o",
    ]
  }

  tool("cxx") {
   
    depfile = "{
   {output}}.d"
    command = "g++ -MMD -MF $depfile {
   {defines}} {
   {include_dirs}} {
   {cflags}} {
   {cflags_cc}} -c {
   {source}} -o {
   {output}}"
    depsformat = "gcc"
    description = "CXX {
   {output}}"
    outputs = [
      "{
   {source_out_dir}}/{
   {target_output_name}}.{
   {source_name_part}}.o",
    ]
  }

  tool("alink") {
   
    rspfile = "{
   {output}}.rsp"
    command =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智驾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值