فهرست منبع

feat: 添加 gn demo (编译不过)

nicetry12138 1 سال پیش
والد
کامیت
31f1bde453

+ 1 - 0
构建项目/GN/Demo/.gn

@@ -0,0 +1 @@
+buildconfig = "//build/BUILDCONFIG.gn"

+ 7 - 0
构建项目/GN/Demo/BUILD.gn

@@ -0,0 +1,7 @@
+# BUILD.gn
+group("default") {
+  deps = [
+    "//dll:mylib",
+    # "//exe:my_app"
+  ]
+}

+ 3 - 0
构建项目/GN/Demo/build/BUILDCONFIG.gn

@@ -0,0 +1,3 @@
+set_default_toolchain("//build/toolchains:gcc")
+
+cflags_cc = [ "-std=c++11" ]

+ 86 - 0
构建项目/GN/Demo/build/toolchains/BUILD.gn

@@ -0,0 +1,86 @@
+# 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 = "rm -f {{output}} && ar rcs {{output}} @$rspfile"
+    description = "AR {{target_output_name}}{{output_extension}}"
+    rspfile_content = "{{inputs}}"
+    outputs = [
+      "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
+    ]
+    default_output_extension = ".a"
+    output_prefix = "lib"
+  }
+
+  tool("solink") {
+    soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
+    sofile = "{{output_dir}}/$soname"
+    rspfile = soname + ".rsp"
+
+    command = "g++ -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile"
+    rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
+
+    description = "SOLINK $soname"
+
+    # Use this for {{output_extension}} expansions unless a target manually
+    # overrides it (in which case {{output_extension}} will be what the target
+    # specifies).
+    default_output_extension = ".so"
+
+    # Use this for {{output_dir}} expansions unless a target manually overrides
+    # it (in which case {{output_dir}} will be what the target specifies).
+    default_output_dir = "{{root_out_dir}}"
+
+    outputs = [
+      sofile,
+    ]
+    link_output = sofile
+    depend_output = sofile
+    output_prefix = "lib"
+  }
+
+  tool("link") {
+    outfile = "{{target_output_name}}{{output_extension}}"
+    rspfile = "$outfile.rsp"
+    command = "g++ {{ldflags}} -o $outfile @$rspfile {{solibs}} {{libs}}"
+    description = "LINK $outfile"
+    default_output_dir = "{{root_out_dir}}"
+    rspfile_content = "{{inputs}}"
+    outputs = [
+      outfile,
+    ]
+  }
+
+  tool("stamp") {
+    command = "touch {{output}}"
+    description = "STAMP {{output}}"
+  }
+
+  tool("copy") {
+    command = "cp -af {{source}} {{output}}"
+    description = "COPY {{source}} {{output}}"
+  }
+}

+ 13 - 0
构建项目/GN/Demo/configs/BUILD.gn

@@ -0,0 +1,13 @@
+# configs/BUILD.gn
+config("common_config") {
+  include_dirs = [
+    "//src",
+    "//dll"
+  ]
+
+  cflags = [
+    "-std=c++17"
+  ]
+
+  ldflags = []
+}

+ 21 - 0
构建项目/GN/Demo/dll/BUILD.gn

@@ -0,0 +1,21 @@
+config("dll_config") {
+
+  cflags = [
+    "-std=c++17"
+  ]
+
+  include_dirs = [
+    "//src",
+    "//dll"
+  ]
+}
+
+
+shared_library("mylib") {
+  configs -= [ ":dll_config" ]
+
+  sources = [
+    "mylib.cpp",
+  ]
+
+}

+ 6 - 0
构建项目/GN/Demo/dll/mylib.cpp

@@ -0,0 +1,6 @@
+#include "mylib.h"
+#include <iostream>
+
+void mylib_function() {
+    std::cout << "Function in mylib" << std::endl;
+}

+ 3 - 0
构建项目/GN/Demo/dll/mylib.h

@@ -0,0 +1,3 @@
+#pragma once
+
+void mylib_function();

+ 12 - 0
构建项目/GN/Demo/exe/BUILD.gn

@@ -0,0 +1,12 @@
+# exe/BUILD.gn
+executable("my_app") {
+  sources = [
+    "//src/main.cpp",
+    "//src/app.cpp",
+    "//src/utils/utils.cpp"
+  ]
+
+  deps = [ "//dll:mylib" ]
+
+  configs += [ "//configs:common_config" ]
+}

+ 1 - 0
构建项目/GN/Demo/out/default/args.gn

@@ -0,0 +1 @@
+# Set build arguments here. See `gn help buildargs`.

+ 8 - 0
构建项目/GN/Demo/src/app.cpp

@@ -0,0 +1,8 @@
+#include "app.h"
+#include "utils/utils.h"
+#include <iostream>
+
+void App::run() {
+    std::cout << "App running" << std::endl;
+    Utils::doSomething();
+}

+ 6 - 0
构建项目/GN/Demo/src/app.h

@@ -0,0 +1,6 @@
+#pragma once
+
+class App {
+public:
+    void run();
+};

+ 8 - 0
构建项目/GN/Demo/src/main.cpp

@@ -0,0 +1,8 @@
+#include "app.h"
+#include "utils/utils.h"
+
+int main() {
+    App app;
+    app.run();
+    return 0;
+}

+ 6 - 0
构建项目/GN/Demo/src/utils/utils.cpp

@@ -0,0 +1,6 @@
+#include "utils/utils.h"
+#include <iostream>
+
+void Utils::doSomething() {
+    std::cout << "Utils doing something" << std::endl;
+}

+ 5 - 0
构建项目/GN/Demo/src/utils/utils.h

@@ -0,0 +1,5 @@
+#pragma once
+
+namespace Utils {
+    void doSomething();
+}