def EnablePrecompile(env, target_name):
  """Enable use of precompiled headers for target_name.

  Args:
    env: The environment.
    target_name: Name of component.

  Returns:
    The pch .obj file.
  """
  if env.Bit('use_precompiled_headers'):
    # We enable all warnings on all levels. The goal is to fix the code that
    # we have written and to programmatically disable the warnings for the
    # code we do not control. This list of warnings should shrink as the code
    # gets fixed.
    env.FilterOut(CCFLAGS=['/W3'])
    env.Append(
        CCFLAGS=[
            '/W4',
            '/Wall',
            ],
        INCLUDES=[
            '$MAIN_DIR/precompile/precompile.h'
            ],
    )

    env['PCHSTOP'] = '$MAIN_DIR/precompile/precompile.h'

    pch_env = env.Clone()
    # Must manually force-include the header, as the precompilation step does
    # not evaluate $INCLUDES
    pch_env.Append(CCFLAGS=['/FI$MAIN_DIR/precompile/precompile.h'])
    # Append '_pch' to the target base name to prevent target name collisions.
    # One case where this might have occurred is when a .cc file has the same
    # base name as the target program/library.
    pch_output = pch_env.PCH(
        target=target_name.replace('.', '_') + '_pch' + '.pch',
        source='$MAIN_DIR/precompile/precompile.cc',
    )

    env['PCH'] = pch_output[0]

    # Return the pch .obj file that is created, so it can be
    # included with the inputs of a module
    return [pch_output[1]]