| 1 | <h2>Full example</h2> |
| 2 | <pre><code># Source: https://gn.googlesource.com/gn/+/main/docs/cross_compiles.md |
| 3 | |
| 4 | declare_args() { |
| 5 | # Applies only to toolchains targeting target_cpu. |
| 6 | sysroot = "" |
| 7 | } |
| 8 | |
| 9 | config("my_config") { |
| 10 | # Uses current_cpu because compile flags are toolchain-dependent. |
| 11 | if (current_cpu == "arm") { |
| 12 | defines = [ "CPU_IS_32_BIT" ] |
| 13 | } else { |
| 14 | defines = [ "CPU_IS_64_BIT" ] |
| 15 | } |
| 16 | # Compares current_cpu with target_cpu to see whether current_toolchain |
| 17 | # has the same architecture as target_toolchain. |
| 18 | if (sysroot != "" && current_cpu == target_cpu) { |
| 19 | cflags = [ |
| 20 | "-isysroot", |
| 21 | sysroot, |
| 22 | ] |
| 23 | } |
| 24 | }</code></pre> |