# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Import('env')

env = env.Clone()

env.Prepend(
  CPPPATH = [
    'include',
    'include/corecg',
    'corecg',
    'sgl',
    'picture',
    '$CHROME_SRC_DIR',
  ],
)

env.Append(
  CPPDEFINES = [
    'SK_BUILD_NO_IMAGE_ENCODE',
  ],
)

if env.Bit('windows'):
  env.Append(
    CCFLAGS = [
      '/TP',

      '/wd4244',
      '/wd4267',
      '/wd4345',
      '/wd4390',
      '/wd4554',
      '/wd4800',
    ],
  )
elif env.Bit('posix'):
  env.Append(CCFLAGS = ['-Wno-unused'])

input_files = ChromeFileList([
  # TODO(sgk):
  # We're deliberately mis-indenting the MSVSFilter() calls here
  # so we don't have to re-indent the file name entries when the
  # MSVSFilter() calls go away in (favor of automated generation
  # of the heirarchy).
  MSVSFilter('Header files', [
    'include/Sk1DPathEffect.h',
    'include/Sk2DPathEffect.h',
    'include/corecg/Sk64.h',
    'include/SkAnimator.h',
    'include/SkAnimatorView.h',
    'include/SkApplication.h',
    'include/SkAvoidXfermode.h',
    'include/SkBGViewArtist.h',
    'include/SkBitmap.h',
    'include/SkBlurDrawLooper.h',
    'include/SkBlurMaskFilter.h',
    'include/SkBML_WXMLParser.h',
    'include/SkBML_XMLParser.h',
    'include/SkBorderView.h',
    'include/SkBounder.h',
    'include/corecg/SkBuffer.h',
    'include/SkCamera.h',
    'include/SkCanvas.h',
    'include/corecg/SkChunkAlloc.h',
    'include/SkColor.h',
    'include/SkColorFilter.h',
    'include/SkColorMatrix.h',
    'include/SkColorPriv.h',
    'include/SkColorShader.h',
    'include/SkCornerPathEffect.h',
    'include/SkCullPoints.h',
    'include/SkDashPathEffect.h',
    'include/SkDeque.h',
    'include/SkDescriptor.h',
    'include/SkDevice.h',
    'include/SkDiscretePathEffect.h',
    'include/SkDither.h',
    'include/SkDOM.h',
    'include/SkDraw.h',
    'include/SkDrawExtraPathEffect.h',
    'include/SkDrawFilter.h',
    'include/SkDrawLooper.h',
    'include/SkEmbossMaskFilter.h',
    'include/corecg/SkEndian.h',
    'include/SkEvent.h',
    'include/SkEventSink.h',
    'include/corecg/SkFDot6.h',
    'include/corecg/SkFixed.h',
    'include/SkFlattenable.h',
    'include/SkFlipPixelRef.h',
    'include/corecg/SkFloatBits.h',
    'include/corecg/SkFloatingPoint.h',
    'include/SkFontCodec.h',
    'include/SkFontHost.h',
    'include/SkGlobals.h',
    'include/SkGradientShader.h',
    'include/SkGraphics.h',
    'include/SkImageDecoder.h',
    'include/SkImageRef.h',
    'include/SkImageView.h',
    'include/corecg/SkInterpolator.h',
    'include/SkJS.h',
    'include/SkKernel33MaskFilter.h',
    'include/SkKey.h',
    'include/SkLayerDrawLooper.h',
    'include/SkLayerRasterizer.h',
    'include/SkMallocPixelRef.h',
    'include/SkMask.h',
    'include/SkMaskFilter.h',
    'include/corecg/SkMath.h',
    'include/corecg/SkMatrix.h',
    'include/SkMetaData.h',
    'include/SkMMapStream.h',
    'include/SkMovie.h',
    'include/SkNinePatch.h',
    'include/SkOSFile.h',
    'include/SkOSMenu.h',
    'include/SkOSSound.h',
    'include/SkOSWindow_Mac.h',
    'include/SkOSWindow_Unix.h',
    'include/SkOSWindow_Win.h',
    'include/SkOSWindow_wxwidgets.h',
    'include/SkPackBits.h',
    'include/corecg/SkPageFlipper.h',
    'include/SkPaint.h',
    'include/SkPaintFlagsDrawFilter.h',
    'include/SkParse.h',
    'include/SkParsePaint.h',
    'include/SkPath.h',
    'include/SkPathEffect.h',
    'include/SkPathMeasure.h',
    'include/corecg/SkPerspIter.h',
    'include/SkPicture.h',
    'include/SkPixelRef.h',
    'include/SkPixelXorXfermode.h',
    'include/corecg/SkPoint.h',
    'include/SkPorterDuff.h',
    'include/corecg/SkPostConfig.h',
    'include/corecg/SkPreConfig.h',
    'include/SkProgressBarView.h',
    'include/SkPtrRecorder.h',
    'include/corecg/SkRandom.h',
    'include/SkRasterizer.h',
    'include/SkReader32.h',
    'include/corecg/SkRect.h',
    'include/SkRefCnt.h',
    'include/corecg/SkRegion.h',
    'include/corecg/SkScalar.h',
    'include/corecg/SkScalarCompare.h',
    'include/SkScalerContext.h',
    'include/SkScrollBarView.h',
    'include/SkShader.h',
    'include/SkShaderExtras.h',
    'include/SkStackViewLayout.h',
    'include/SkStream.h',
    'include/SkStream_Win.h',
    'include/SkString.h',
    'include/SkStroke.h',
    'include/SkSVGAttribute.h',
    'include/SkSVGBase.h',
    'include/SkSVGPaintState.h',
    'include/SkSVGParser.h',
    'include/SkSVGTypes.h',
    'include/SkSystemEventTypes.h',
    'include/SkTDArray.h',
    'include/SkTDict.h',
    'include/SkTDStack.h',
    'include/corecg/SkTemplates.h',
    'include/SkTextBox.h',
    'include/corecg/SkThread.h',
    'include/corecg/SkThread_platform.h',
    'include/SkTime.h',
    'include/SkTransparentShader.h',
    'include/corecg/SkTSearch.h',
    'include/SkTypeface.h',
    'include/corecg/SkTypes.h',
    'include/SkUnitMapper.h',
    'include/SkUnitMappers.h',
    'include/SkUnPreMultiply.h',
    'include/corecg/SkUserConfig.h',
    'include/SkUtils.h',
    'include/SkView.h',
    'include/SkViewInflate.h',
    'include/SkWidget.h',
    'include/SkWidgetViews.h',
    'include/SkWindow.h',
    'include/SkWriter32.h',
    'include/SkXfermode.h',
    'include/SkXMLParser.h',
    'include/SkXMLWriter.h',
  ]),

  MSVSFilter('corecg', [
    'corecg/Sk64.cpp',
    'corecg/SkBuffer.cpp',
    'corecg/SkChunkAlloc.cpp',
    'corecg/SkCordic.cpp',
    'corecg/SkCordic.h',
    'corecg/SkDebug.cpp',
    'corecg/SkDebug_stdio.cpp',
    'corecg/SkFloat.cpp',
    'corecg/SkFloat.h',
    'corecg/SkFloatBits.cpp',
    'corecg/SkInterpolator.cpp',
    'corecg/SkMath.cpp',
    'corecg/SkMatrix.cpp',
    'corecg/SkMemory_stdlib.cpp',
    'corecg/SkPageFlipper.cpp',
    'corecg/SkPoint.cpp',
    'corecg/SkRect.cpp',
    'corecg/SkRegion.cpp',
    'corecg/SkRegionPriv.h',
    'corecg/SkSinTable.h',
    'corecg/SkTSort.h',
  ]),

  MSVSFilter('sgl', [
    'sgl/SkAlphaRuns.cpp',
    'sgl/SkAntiRun.h',
    'sgl/SkAutoKern.h',
    'sgl/SkBitmap.cpp',
    'sgl/SkBitmapProcShader.cpp',
    'sgl/SkBitmapProcShader.h',
    'sgl/SkBitmapProcState.cpp',
    'sgl/SkBitmapProcState.h',
    'sgl/SkBitmapProcState_matrix.h',
    'sgl/SkBitmapProcState_matrixProcs.cpp',
    'sgl/SkBitmapSampler.cpp',
    'sgl/SkBitmapSampler.h',
    'sgl/SkBitmapSamplerTemplate.h',
    'sgl/SkBitmapShader.cpp',
    'sgl/SkBitmapShader.h',
    'sgl/SkBitmapShader16BilerpTemplate.h',
    'sgl/SkBitmapShaderTemplate.h',
    'sgl/SkBlitBWMaskTemplate.h',
    'sgl/SkBlitRow.h',
    'sgl/SkBlitRow_D16.cpp',
    'sgl/SkBlitRow_D4444.cpp',
    'sgl/SkBlitter.cpp',
    'sgl/SkBlitter.h',
    'sgl/SkBlitter_4444.cpp',
    'sgl/SkBlitter_A1.cpp',
    'sgl/SkBlitter_A8.cpp',
    'sgl/SkBlitter_ARGB32.cpp',
    'sgl/SkBlitter_RGB16.cpp',
    'sgl/SkBlitter_Sprite.cpp',
    'sgl/SkCanvas.cpp',
    'sgl/SkColor.cpp',
    'sgl/SkColorFilter.cpp',
    'sgl/SkColorTable.cpp',
    'sgl/SkCoreBlitters.h',
    'sgl/SkDeque.cpp',
    'sgl/SkDevice.cpp',
    'sgl/SkDither.cpp',
    'sgl/SkDraw.cpp',
    'sgl/SkDraw.h',
    'sgl/SkEdge.cpp',
    'sgl/SkEdge.h',
    'sgl/SkFilterProc.cpp',
    'sgl/SkFilterProc.h',
    'sgl/SkFlattenable.cpp',
    'sgl/SkFP.h',
    'sgl/SkGeometry.cpp',
    'sgl/SkGeometry.h',
    'sgl/SkGlobals.cpp',
    'sgl/SkGlyphCache.cpp',
    'sgl/SkGlyphCache.h',
    'sgl/SkGraphics.cpp',
    'sgl/SkMask.cpp',
    'sgl/SkMaskFilter.cpp',
    'sgl/SkPackBits.cpp',
    'sgl/SkPaint.cpp',
    'sgl/SkPath.cpp',
    'sgl/SkPathEffect.cpp',
    'sgl/SkPathMeasure.cpp',
    'sgl/SkPixelRef.cpp',
    'sgl/SkProcSpriteBlitter.cpp',
    'sgl/SkPtrRecorder.cpp',
    'sgl/SkRasterizer.cpp',
    'sgl/SkRefCnt.cpp',
    'sgl/SkRegion_path.cpp',
    'sgl/SkScalerContext.cpp',
    'sgl/SkScan.cpp',
    'sgl/SkScan.h',
    'sgl/SkScan_Antihair.cpp',
    'sgl/SkScan_AntiPath.cpp',
    'sgl/SkScan_Hairline.cpp',
    'sgl/SkScan_Path.cpp',
    'sgl/SkScanPriv.h',
    'sgl/SkShader.cpp',
    'sgl/SkSpriteBlitter.h',
    'sgl/SkSpriteBlitter_ARGB32.cpp',
    'sgl/SkSpriteBlitter_RGB16.cpp',
    'sgl/SkSpriteBlitterTemplate.h',
    'sgl/SkString.cpp',
    'sgl/SkStroke.cpp',
    'sgl/SkStrokerPriv.cpp',
    'sgl/SkStrokerPriv.h',
    'sgl/SkTemplatesPriv.h',
    'sgl/SkTSearch.cpp',
    'sgl/SkTSort.h',
    'sgl/SkTypeface_fake.cpp',
    #'sgl/SkUnPreMultiply.cpp',
    'sgl/SkUtils.cpp',
    'sgl/SkWriter32.cpp',
    'sgl/SkXfermode.cpp',
  ]),

  MSVSFilter('ports', [
    'ports/sk_predefined_gamma.h',
    'ports/SkFontHost_none.cpp',
    'ports/SkGlobals_global.cpp',
    'ports/SkImageDecoder_Factory.cpp',
    'ports/SkOSFile_stdio.cpp',
    'ports/SkThread_win.cpp',
  ]),

  MSVSFilter('images', [
    'images/SkImageDecoder.cpp',
    'images/SkImageRef.cpp',
    'images/SkScaledBitmapSampler.h',
    'images/SkStream.cpp',
  ]),

  MSVSFilter('effects', [
    'effects/Sk1DPathEffect.cpp',
    'effects/Sk2DPathEffect.cpp',
    'effects/SkAvoidXfermode.cpp',
    'effects/SkBlurDrawLooper.cpp',
    'effects/SkBlurMask.cpp',
    'effects/SkBlurMaskFilter.cpp',
    'effects/SkCamera.cpp',
    'effects/SkColorFilters.cpp',
    'effects/SkColorMatrix.cpp',
    'effects/SkColorMatrixFilter.cpp',
    'effects/SkCornerPathEffect.cpp',
    'effects/SkCullPoints.cpp',
    'effects/SkDashPathEffect.cpp',
    'effects/SkDiscretePathEffect.cpp',
    'effects/SkEmbossMask.cpp',
    'effects/SkEmbossMaskFilter.cpp',
    'effects/SkGradientShader.cpp',
    'effects/SkKernel33MaskFilter.cpp',
    'effects/SkLayerRasterizer.cpp',
    'effects/SkPaintFlagsDrawFilter.cpp',
    'effects/SkPixelXorXfermode.cpp',
    'effects/SkRadialGradient_Table.h',
    'effects/SkShaderExtras.cpp',
    'effects/SkTransparentShader.cpp',
    'effects/SkUnitMappers.cpp',
  ]),

  MSVSFilter('animator', [
    'animator/SkTime.cpp',
  ]),

  MSVSFilter('picture', [
    'picture/SkPathHeap.cpp',
    'picture/SkPathHeap.h',
    'picture/SkPicture.cpp',
    'picture/SkPictureFlat.cpp',
    'picture/SkPictureFlat.h',
    'picture/SkPicturePlayback.cpp',
    'picture/SkPicturePlayback.h',
    'picture/SkPictureRecord.cpp',
    'picture/SkPictureRecord.h',
  ]),

  MSVSFilter('ext', [
    'ext/bitmap_platform_device.h',
    'ext/bitmap_platform_device_win.cc',
    'ext/bitmap_platform_device_win.h',
    'ext/convolver.cc',
    'ext/convolver.h',
    'ext/google_logging.cc',
    'ext/image_operations.cc',
    'ext/image_operations.h',
    'ext/platform_canvas.h',
    'ext/platform_canvas_win.cc',
    'ext/platform_canvas_win.h',
    'ext/platform_device.h',
    'ext/platform_device_win.cc',
    'ext/platform_device_win.h',
    'ext/skia_utils.cc',
    'ext/skia_utils.h',
    'ext/skia_utils_win.cc',
    'ext/skia_utils_win.h',
    'ext/vector_canvas.cc',
    'ext/vector_canvas.h',
    'ext/vector_device.cc',
    'ext/vector_device.h',
  ]),

    'precompiled.cc',
])

if env.Bit('linux'):
  input_files.append('ext/bitmap_platform_device_linux.cc')
  input_files.append('ext/platform_canvas_linux.cc')
  input_files.append('ext/platform_device_linux.cc')
  input_files.append('ext/GdkSkia.cc')

  # On Linux we use Skia to render fonts with FreeType and fontconfig
  input_files.Remove('sgl/SkTypeface_fake.cpp')
  input_files.Remove('ports/SkFontHost_none.cpp')
  input_files.append('sgl/SkTypeface.cpp')
  input_files.append('ports/SkFontHost_FreeType.cpp')
  input_files.append('ports/SkFontHost_TrueType_Tables.cpp')
  input_files.append('ports/SkFontHost_gamma_none.cpp')
  input_files.append('ports/SkFontHost_fontconfig.cpp')
  input_files.append('images/SkMMapStream.cpp')

  env.Append(CCFLAGS = ['-Wno-unused-function'])

if not env['COMPONENT_STATIC']:
  # SkUnPreMultiply is commented out in the sgl list above, but we need to link
  # it into the shared library.
  input_files.append('sgl/SkUnPreMultiply.cpp')

if env.Bit('posix'):
  input_files.append('ports/SkThread_pthread.cpp')
  input_files.append('ports/SkTime_Unix.cpp')

if env.Bit('mac'):
  input_files.append('ext/bitmap_platform_device_mac.cc')
  input_files.append('ext/platform_canvas_mac.cc')
  input_files.append('ext/platform_device_mac.cc')

if not env.Bit('windows'):
  input_files.Remove(
      'ext/bitmap_platform_device_win.cc',
      'ext/bitmap_platform_device_win.h',
      'ext/platform_canvas_win.cc',
      'ext/platform_canvas_win.h',
      'ext/platform_device_win.cc',
      'ext/platform_device_win.h',
      'ext/skia_utils_win.cc',
      'ext/skia_utils_win.h',
      'ext/vector_canvas.cc',
      'ext/vector_canvas.h',
      'ext/vector_device.cc',
      'ext/vector_device.h',

      'ports/SkThread_win.cpp',
  )

if env.Bit('windows'):
  env_p = env.Clone(
    PCHSTOP = 'SkTypes.h',
    PDB = 'vc80.pdb',
  )

  # TODO(rspangler): This step forces -Zi, but doesn't actually use it.  Need to
  # fix so it doesn't override our -Z7.  -Zi also causes vc80.pdb to be created
  # in the skia directory.
  # TODO(bradnelson): This step creates a skia.pch.ib_tag file to be created. 
  # It's a 0-length file so likely harmless.  Is this a side effect of having
  # IncrediBuild installed on the build machine?
  pch, obj = env_p.PCH(['skia.pch', 'precompiled.obj'], 'precompiled.cc')
  env_p['PCH'] = pch
  input_files.Replace('precompiled.cc', obj)

env.ChromeLibrary('skia', input_files)

p = env.ChromeMSVSProject('skia.vcproj',
                          dest='$CHROME_SRC_DIR/skia/skia.vcproj',
                          guid='{CD9CA56E-4E94-444C-87D4-58CA1E6F300D}',
                          keyword='Win32Proj',
                          files=input_files,
                          relative_path_prefix=r'./',
                          tools = [
                              'VCPreBuildEventTool',
                              'VCCustomBuildTool',
                              'VCXMLDataGeneratorTool',
                              'VCWebServiceProxyGeneratorTool',
                              'VCMIDLTool',
                              'VCCLCompilerTool',
                              'VCManagedResourceCompilerTool',
                              'VCResourceCompilerTool',
                              'VCPreLinkEventTool',
                              'VCLibrarianTool',
                              'VCALinkTool',
                              'VCXDCMakeTool',
                              'VCBscMakeTool',
                              'VCFxCopTool',
                              'VCPostBuildEventTool',
                          ])

p.AddConfig('Debug|Win32',
            ConfigurationType = '4',
            InheritedPropertySheets = [
                '$(SolutionDir)../build/debug.vsprops',
                './skia.vsprops',
                './precompiled.vsprops',
            ])

p.AddConfig('Release|Win32',
            ConfigurationType = '4',
            InheritedPropertySheets = [
                '$(SolutionDir)../build/release.vsprops',
                './skia.vsprops',
            ])

p.AddFileConfig(
    'precompiled.cc',
    'Debug|Win32',
    tools=[
        MSVSTool('VCCLCompilerTool', UsePrecompiledHeader='1'),
    ])

p.AddFileConfig(
    'precompiled.cc',
    'Release|Win32',
    ExcludedFromBuild='true',
    tools=[
        MSVSTool('VCCLCompilerTool'),
    ])