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

BUILD.gn (5038B)


      1 # Each toolchain must define "stamp" and "copy" tools,
      2 # but they are always the same in every toolchain.
      3 stamp_command = "touch {{output}}"
      4 stamp_description = "STAMP {{output}}"
      5 
      6 # We use link instead of copy; the way "copy" tool is being used is
      7 # compatible with links since Ninja is tracking changes to the source.
      8 copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
      9 copy_description = "COPY {{source}} {{output}}"
     10 
     11 toolchain("clang") {
     12   cc = "clang"
     13   cxx = "clang++"
     14   ld = cxx
     15   ar = "ar"
     16 
     17   tool("cc") {
     18     depfile = "{{output}}.d"
     19     command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
     20     depsformat = "gcc"
     21     description = "CC {{output}}"
     22     outputs = [
     23       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
     24     ]
     25   }
     26 
     27   tool("cxx") {
     28     depfile = "{{output}}.d"
     29     command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
     30     depsformat = "gcc"
     31     description = "CXX {{output}}"
     32     outputs = [
     33       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
     34     ]
     35   }
     36 
     37   tool("asm") {
     38     depfile = "{{output}}.d"
     39     command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
     40     depsformat = "gcc"
     41     description = "ASM {{output}}"
     42     outputs = [
     43       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
     44     ]
     45   }
     46 
     47   tool("objc") {
     48     depfile = "{{output}}.d"
     49     command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
     50     depsformat = "gcc"
     51     description = "OBJC {{output}}"
     52     outputs = [
     53       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
     54     ]
     55   }
     56 
     57   tool("objcxx") {
     58     depfile = "{{output}}.d"
     59     command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objcc}} -c {{source}} -o {{output}}"
     60     depsformat = "gcc"
     61     description = "OBJCXX {{output}}"
     62     outputs = [
     63       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
     64     ]
     65   }
     66 
     67   tool("alink") {
     68     rspfile = "{{output}}.rsp"
     69     command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
     70     description = "AR {{output}}"
     71     rspfile_content = "{{inputs}}"
     72     outputs = [
     73       "{{output_dir}}/{{target_output_name}}{{output_extension}}",
     74     ]
     75     default_output_dir = "{{target_out_dir}}"
     76     default_output_extension = ".a"
     77     output_prefix = "lib"
     78   }
     79 
     80   tool("solink") {
     81     outname = "{{target_output_name}}{{output_extension}}"
     82     outfile = "{{output_dir}}/$outname"
     83     rspfile = "$outfile.rsp"
     84     unstripped_outfile = outfile
     85     if (use_strip) {
     86       unstripped_outfile = "{{output_dir}}/lib.unstripped/{{target_output_name}}{{output_extension}}"
     87     }
     88     if (target_os == "mac") {
     89       command = "$ld -shared {{ldflags}} -Wl,-install_name,@rpath/\"{{target_output_name}}{{output_extension}}\" -o \"$unstripped_outfile\" -Wl,-filelist,\"$rspfile\" {{libs}} {{solibs}}"
     90       rspfile_content = "{{inputs_newline}}"
     91       default_output_extension = ".dylib"
     92     } else {
     93       command = "$ld -shared {{ldflags}} -o \"$unstripped_outfile\" -Wl,--Map=\"$unstripped_outfile.map\" -Wl,-soname=\"$outname\" @\"$rspfile\""
     94       rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
     95       default_output_extension = ".so"
     96     }
     97     if (use_strip) {
     98       command += " && strip --strip-all \"$unstripped_outfile\" \"$outfile\""
     99     }
    100     description = "SOLINK $outfile"
    101     default_output_dir = "{{root_out_dir}}"
    102     output_prefix = "lib"
    103     outputs = [
    104       outfile,
    105     ]
    106     if (outfile != unstripped_outfile) {
    107       outputs += [ unstripped_outfile ]
    108     }
    109   }
    110 
    111   tool("link") {
    112     outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
    113     rspfile = "$outfile.rsp"
    114     unstripped_outfile = outfile
    115     if (use_strip) {
    116       unstripped_outfile = "{{root_out_dir}}/exe.unstripped/{{target_output_name}}{{output_extension}}"
    117     }
    118     if (target_os == "mac") {
    119       command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,-filelist,\"$rspfile\" {{frameworks}} {{solibs}} {{libs}}"
    120       rspfile_content = "{{inputs_newline}}"
    121     } else {
    122       command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,--Map=\"$unstripped_outfile.map\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group {{libs}}"
    123       rspfile_content = "{{inputs}}"
    124     }
    125     if (use_strip) {
    126       command += " && strip --strip-sections \"$unstripped_outfile\" \"$outfile\""
    127     }
    128     description = "LINK $outfile"
    129     default_output_dir = "{{root_out_dir}}"
    130     outputs = [
    131       outfile,
    132     ]
    133     if (outfile != unstripped_outfile) {
    134       outputs += [ unstripped_outfile ]
    135     }
    136   }
    137 
    138   tool("stamp") {
    139     command = stamp_command
    140     description = stamp_description
    141   }
    142 
    143   tool("copy") {
    144     command = copy_command
    145     description = copy_description
    146   }
    147 }