xref: /llvm-project/llvm/utils/gn/build/toolchain/target_flags.gni (revision 18952bdcd6f987620e6396261c2bb444e428e07e)
1import("//llvm/triples.gni")
2import("//llvm/utils/gn/build/mac_sdk.gni")
3import("//llvm/utils/gn/build/toolchain/compiler.gni")
4
5# Flags in this file are passed both to the compiler that's building
6# compiler-rt at build time (via normal gn cflags/ldflags), as well as to the
7# compiler building compiler-rt test programs at test time (via
8# COMPILER_RT_TEST_COMPILER_CFLAGS).
9
10target_flags = []
11target_cflags = []
12target_ldflags = []
13
14if (current_os == "android") {
15  target_flags += [
16    "--target=$llvm_current_triple",
17    "--sysroot=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
18    "--gcc-toolchain=$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64",
19    "-fno-emulated-tls",
20  ]
21  target_ldflags += [ "-static-libstdc++" ]
22  if (current_cpu == "arm") {
23    target_flags += [ "-march=armv7-a" ]
24  }
25} else if (current_os == "ios" || current_os == "mac") {
26  if (current_cpu == "arm64") {
27    target_flags += [
28      "-arch",
29      "arm64",
30    ]
31    target_ldflags += [
32      "-arch",
33      "arm64",
34    ]
35  } else if (current_cpu == "x64") {
36    target_flags += [
37      "-arch",
38      "x86_64",
39    ]
40    target_ldflags += [
41      "-arch",
42      "x86_64",
43    ]
44  }
45  if (current_os == "mac") {
46    target_flags += [
47      "-isysroot",
48      rebase_path(mac_sdk_path, root_build_dir),
49
50      # TODO(lgrey): We should be getting this from `compiler_defaults`. Why
51      # aren't we?
52      "-mmacos-version-min=$mac_deployment_target",
53    ]
54  }
55} else if (current_os == "baremetal") {
56  target_flags += [ "--target=$llvm_current_triple" ]
57}
58
59if (current_cpu == "x86") {
60  if (current_os == "win") {
61    target_cflags += [ "-m32" ]
62  } else {
63    target_flags += [ "-m32" ]
64  }
65}
66