cc_project_template_gn

A gn, ninja, and googletest-based C++ project template
git clone https://git.bracken.jp/cc_project_template_gn.git
Log | Files | Refs | Submodules | README | LICENSE

BUILDCONFIG.gn (4377B)


      1 # =============================================================================
      2 # PLATFORM SELECTION
      3 # =============================================================================
      4 #
      5 # There are two main things to set: "os" and "cpu". The "toolchain" is the name
      6 # of the GN thing that encodes combinations of these things.
      7 #
      8 # Users typically only set the variables "target_os" and "target_cpu" in "gn
      9 # args", the rest are set up by our build and internal to GN.
     10 #
     11 # There are three different types of each of these things: The "host"
     12 # represents the computer doing the compile and never changes. The "target"
     13 # represents the main thing we're trying to build. The "current" represents
     14 # which configuration is currently being defined, which can be either the
     15 # host, the target, or something completely different (like nacl). GN will
     16 # run the same build file multiple times for the different required
     17 # configuration in the same build.
     18 #
     19 # This gives the following variables:
     20 #  - host_os, host_cpu, host_toolchain
     21 #  - target_os, target_cpu, default_toolchain
     22 #  - current_os, current_cpu, current_toolchain.
     23 #
     24 # Note the default_toolchain isn't symmetrical (you would expect
     25 # target_toolchain). This is because the "default" toolchain is a GN built-in
     26 # concept, and "target" is something our build sets up that's symmetrical with
     27 # its GYP counterpart. Potentially the built-in default_toolchain variable
     28 # could be renamed in the future.
     29 #
     30 # When writing build files, to do something only for the host:
     31 #   if (current_toolchain == host_toolchain) { ...
     32 
     33 if (target_os == "") {
     34   target_os = host_os
     35 }
     36 if (target_cpu == "") {
     37   target_cpu = host_cpu
     38 }
     39 if (current_cpu == "") {
     40   current_cpu = target_cpu
     41 }
     42 if (current_os == "") {
     43   current_os = target_os
     44 }
     45 
     46 # =============================================================================
     47 # PLATFORM SELECTION
     48 # =============================================================================
     49 #
     50 # There are two main things to set: "os" and "cpu". The "toolchain" is the name
     51 # of the GN thing that encodes combinations of these things.
     52 #
     53 # Users typically only set the variables "target_os" and "target_cpu" in "gn
     54 # args", the rest are set up by our build and internal to GN.
     55 #
     56 # There are three different types of each of these things: The "host"
     57 # represents the computer doing the compile and never changes. The "target"
     58 # represents the main thing we're trying to build. The "current" represents
     59 # which configuration is currently being defined, which can be either the
     60 # host, the target, or something completely different (like nacl). GN will
     61 # run the same build file multiple times for the different required
     62 # configuration in the same build.
     63 #
     64 # This gives the following variables:
     65 #  - host_os, host_cpu, host_toolchain
     66 #  - target_os, target_cpu, default_toolchain
     67 #  - current_os, current_cpu, current_toolchain.
     68 #
     69 # Note the default_toolchain isn't symmetrical (you would expect
     70 # target_toolchain). This is because the "default" toolchain is a GN built-in
     71 # concept, and "target" is something our build sets up that's symmetrical with
     72 # its GYP counterpart. Potentially the built-in default_toolchain variable
     73 # could be renamed in the future.
     74 #
     75 # When writing build files, to do something only for the host:
     76 #   if (current_toolchain == host_toolchain) { ...
     77 
     78 declare_args() {
     79   is_debug = true
     80 }
     81 
     82 # Options
     83 use_strip = false
     84 
     85 # All binary targets will get this list of configs by default.
     86 _shared_binary_target_configs = [
     87   "//build:compiler_std",
     88   "//build:compiler_warnings",
     89 ]
     90 
     91 # Optimisations and debug/release mode.
     92 if (is_debug) {
     93   _shared_binary_target_configs += [ "//build:debug" ]
     94   _shared_binary_target_configs += [ "//build:no_optimize" ]
     95   _shared_binary_target_configs += [ "//build:symbols" ]
     96 } else {
     97   _shared_binary_target_configs += [ "//build:release" ]
     98   _shared_binary_target_configs += [ "//build:optimize" ]
     99   _shared_binary_target_configs += [ "//build:no_symbols" ]
    100 }
    101 
    102 # Apply that default list to the binary target types.
    103 set_defaults("executable") {
    104   configs = _shared_binary_target_configs
    105 }
    106 set_defaults("static_library") {
    107   configs = _shared_binary_target_configs
    108 }
    109 set_defaults("shared_library") {
    110   configs = _shared_binary_target_configs
    111 }
    112 set_defaults("source_set") {
    113   configs = _shared_binary_target_configs
    114 }
    115 
    116 set_default_toolchain("//build/toolchain:clang")