| 1 |
# Copyright 2022 Google LLC |
| 2 |
# |
| 3 |
# Use of this source code is governed by a ISC-License license that can be |
| 4 |
# found in the LICENSE file. |
| 5 |
|
| 6 |
import("../third_party.gni") |
| 7 |
|
| 8 |
declare_args() { |
| 9 |
UNICODE_VERSION = "15.0.0" |
| 10 |
} |
| 11 |
|
| 12 |
config("c99") { |
| 13 |
cflags_c = [] |
| 14 |
if (is_win) { |
| 15 |
cflags_c += [ "-std:c11" ] |
| 16 |
} else { |
| 17 |
cflags_c += [ "-std=c99" ] |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
# Header generation only happens on the host. |
| 22 |
# Ensure it will not be built for non-host even when implicitly building all targets. |
| 23 |
if (current_toolchain == "//gn/toolchain:$host_toolchain") { |
| 24 |
copy("copy_unicode_data") { |
| 25 |
unicode_tools_dir = |
| 26 |
"../externals/unicodetools/unicodetools/data/ucd/$UNICODE_VERSION" |
| 27 |
sources = [ |
| 28 |
"$unicode_tools_dir/BidiBrackets.txt", |
| 29 |
"$unicode_tools_dir/BidiCharacterTest.txt", |
| 30 |
"$unicode_tools_dir/BidiMirroring.txt", |
| 31 |
"$unicode_tools_dir/BidiTest.txt", |
| 32 |
"$unicode_tools_dir/DerivedCoreProperties.txt", |
| 33 |
"$unicode_tools_dir/EastAsianWidth.txt", |
| 34 |
"$unicode_tools_dir/LineBreak.txt", |
| 35 |
"$unicode_tools_dir/SpecialCasing.txt", |
| 36 |
"$unicode_tools_dir/UnicodeData.txt", |
| 37 |
"$unicode_tools_dir/auxiliary/GraphemeBreakProperty.txt", |
| 38 |
"$unicode_tools_dir/auxiliary/GraphemeBreakTest.txt", |
| 39 |
"$unicode_tools_dir/auxiliary/LineBreakTest.txt", |
| 40 |
"$unicode_tools_dir/auxiliary/SentenceBreakProperty.txt", |
| 41 |
"$unicode_tools_dir/auxiliary/SentenceBreakTest.txt", |
| 42 |
"$unicode_tools_dir/auxiliary/WordBreakProperty.txt", |
| 43 |
"$unicode_tools_dir/auxiliary/WordBreakTest.txt", |
| 44 |
"$unicode_tools_dir/emoji/emoji-data.txt", |
| 45 |
"$unicode_tools_dir/extracted/DerivedBidiClass.txt", |
| 46 |
] |
| 47 |
outputs = |
| 48 |
[ "$root_gen_dir/third_party/libgrapheme/data/{{source_file_part}}" ] |
| 49 |
} |
| 50 |
|
| 51 |
template("compile_tool") { |
| 52 |
executable(target_name) { |
| 53 |
forward_variables_from(invoker, "*", [ "deps" ]) |
| 54 |
if (defined(invoker.deps)) { |
| 55 |
deps += invoker.deps |
| 56 |
} |
| 57 |
configs += [ ":c99" ] |
| 58 |
sources += [ "../externals/libgrapheme/gen/util.c" ] |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
compile_tool("bidirectional") { |
| 63 |
sources = [ "../externals/libgrapheme/gen/bidirectional.c" ] |
| 64 |
} |
| 65 |
|
| 66 |
compile_tool("case") { |
| 67 |
sources = [ "../externals/libgrapheme/gen/case.c" ] |
| 68 |
} |
| 69 |
|
| 70 |
compile_tool("character") { |
| 71 |
sources = [ "../externals/libgrapheme/gen/character.c" ] |
| 72 |
} |
| 73 |
|
| 74 |
compile_tool("line") { |
| 75 |
sources = [ "../externals/libgrapheme/gen/line.c" ] |
| 76 |
} |
| 77 |
|
| 78 |
compile_tool("sentence") { |
| 79 |
sources = [ "../externals/libgrapheme/gen/sentence.c" ] |
| 80 |
} |
| 81 |
|
| 82 |
compile_tool("word") { |
| 83 |
sources = [ "../externals/libgrapheme/gen/word.c" ] |
| 84 |
} |
| 85 |
|
| 86 |
# Run an executable that will produce a header |
| 87 |
action_foreach("generate_headers") { |
| 88 |
script = "generate_headers.py" |
| 89 |
cmd_dir = rebase_path(root_out_dir) |
| 90 |
args = [ |
| 91 |
"$cmd_dir/{{source_name_part}}", |
| 92 |
rebase_path( |
| 93 |
"$root_gen_dir/third_party/libgrapheme/gen/{{source_name_part}}.h", |
| 94 |
root_build_dir), |
| 95 |
rebase_path("$root_gen_dir/third_party/libgrapheme", root_build_dir), |
| 96 |
] |
| 97 |
_src = "../externals/libgrapheme/gen" |
| 98 |
sources = [ |
| 99 |
"$_src/bidirectional.c", |
| 100 |
"$_src/case.c", |
| 101 |
"$_src/character.c", |
| 102 |
"$_src/line.c", |
| 103 |
"$_src/sentence.c", |
| 104 |
"$_src/word.c", |
| 105 |
] |
| 106 |
outputs = |
| 107 |
[ "$root_gen_dir/third_party/libgrapheme/gen/{{source_name_part}}.h" ] |
| 108 |
deps = [ |
| 109 |
":bidirectional", |
| 110 |
":case", |
| 111 |
":character", |
| 112 |
":copy_unicode_data", |
| 113 |
":line", |
| 114 |
":sentence", |
| 115 |
":word", |
| 116 |
] |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
# libgrapheme is built for the target and so must be able to always see headers and headers_config. |
| 121 |
config("headers_config") { |
| 122 |
if (current_toolchain == "//gn/toolchain:$host_toolchain") { |
| 123 |
include_dirs = [ "$root_gen_dir/third_party/libgrapheme/gen" ] |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
source_set("headers") { |
| 128 |
if (current_toolchain == "//gn/toolchain:$host_toolchain") { |
| 129 |
# Prevent :generate_headers from being run when building all targets. |
| 130 |
sources = get_target_outputs(":generate_headers") |
| 131 |
|
| 132 |
#get_target_outputs does not actually depend on the outputs |
| 133 |
deps = [ ":generate_headers" ] |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
third_party("libgrapheme") { |
| 138 |
public_include_dirs = [ "../externals/libgrapheme" ] |
| 139 |
_src = "../externals/libgrapheme/src" |
| 140 |
|
| 141 |
configs = [ |
| 142 |
":c99", |
| 143 |
":headers_config(//gn/toolchain:$host_toolchain)", |
| 144 |
] |
| 145 |
|
| 146 |
sources = [ |
| 147 |
"$_src/bidirectional.c", |
| 148 |
"$_src/case.c", |
| 149 |
"$_src/character.c", |
| 150 |
"$_src/line.c", |
| 151 |
"$_src/sentence.c", |
| 152 |
"$_src/utf8.c", |
| 153 |
"$_src/util.c", |
| 154 |
"$_src/word.c", |
| 155 |
] |
| 156 |
|
| 157 |
deps = [ ":headers(//gn/toolchain:$host_toolchain)" ] |
| 158 |
} |