BUILD.gn (2224B)
1 # Default language standards. 2 config("compiler_std") { 3 cflags_c = [ "-std=c11" ] 4 cflags_cc = [ "-std=c++17" ] 5 cflags_objcc = [ "-std=c++17" ] 6 } 7 8 config("posix_env") { 9 defines = [ 10 "_POSIX_C_SOURCE=200809L", 11 "_XOPEN_SOURCE=700", 12 ] 13 14 if (target_os == "linux") { 15 defines += [ "_DEFAULT_SOURCE" ] 16 } else if (target_os == "mac") { 17 defines += [ "_DARWIN_C_SOURCE" ] 18 } 19 } 20 21 # Default compiler warnings. 22 config("compiler_warnings") { 23 cflags = [ 24 "-Wall", 25 "-Wextra", 26 "-Werror", 27 ] 28 cflags_cc = [] 29 cflags_objcc = [] 30 } 31 32 config("strict_prototypes") { 33 cflags = [ 34 "-Wmissing-prototypes", 35 "-Wstrict-prototypes", 36 ] 37 } 38 39 # Test-specific warnings (relaxed for test fixtures). 40 config("test_warnings") { 41 cflags = [ 42 "-Wno-unused-parameter", 43 ] 44 } 45 46 # Debug mode build. 47 config("debug") { 48 defines = [ "_DEBUG" ] 49 } 50 51 # Release mode build. 52 config("release") { 53 defines = [ "NDEBUG" ] 54 } 55 56 # Disable optimisations. 57 config("no_optimize") { 58 cflags = [ "-O0" ] 59 } 60 61 # Optimise for time performance. 62 config("optimize") { 63 cflags = [ "-O2" ] 64 } 65 66 # Optimise for size. 67 config("optimize_size") { 68 cflags = [ "-Os" ] 69 70 if (current_os == "mac" || current_os == "ios") { 71 ldflags = [ 72 "-Wl,-dead_strip", # Mac equivalent of --gc-sections 73 "-Wl,-S", # Strip debug symbols 74 "-Wl,-x", # Strip local symbols 75 ] 76 } else { 77 # OpenBSD / Linux / etc. 78 cflags += [ 79 "-ffunction-sections", 80 "-fdata-sections", 81 ] 82 ldflags = [ 83 "-Wl,--gc-sections", 84 "-s", 85 ] 86 } 87 } 88 89 # Enable link-time-optimisation. 90 config("lto") { 91 cflags = [ "-flto" ] 92 ldflags = [ "-flto" ] 93 } 94 95 # Disable exceptions. 96 config("no_exceptions") { 97 cflags = [ "-fno-exceptions" ] 98 ldflags = [ "-fno-exceptions" ] 99 } 100 101 # Disable runttime type information. 102 config("no_rtti") { 103 cflags = [ "-fno-rtti" ] 104 ldflags = [ "-fno-rtti" ] 105 } 106 107 # Regular build with symbols. 108 config("symbols") { 109 cflags = [ "-g2" ] 110 } 111 112 # Minimal symbols, typically just enough for backtraces. 113 config("min_symbols") { 114 cflags = [ "-g1" ] 115 } 116 117 # No symbols. 118 config("no_symbols") { 119 cflags = [ "-g0" ] 120 } 121 122 # Address Sanitizer 123 config("asan") { 124 cflags = [ "-fsanitize=address" ] 125 ldflags = [ "-fsanitize=address" ] 126 }