# Copyright 2013 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.

config("wtf-config") {
  include_dirs = [ ".." ]
  if (is_win) {
    include_dirs += [ "os-win32" ]
    defines = [
      "__STD_C",
      "_CRT_SECURE_NO_DEPRECATE",
      "_SCL_SECURE_NO_DEPRECATE",
      "CRASH=__debugbreak",
    ]
#    # Chromium windows multi-dll build enables c++ exception and this
#    # causes wtf generates 4291 warning due to operator new/delete
#    # implementations. Disable the warning for chromium windows
#    # multi-dll build.
#    'msvs_disabled_warnings': [4291],
#    'direct_dependent_settings': {
#      'msvs_disabled_warnings': [4291],
#    },
  }

  if (is_linux) { # (gcc_version >= 46) {
    # Disable warnings about c++0x compatibility, as some names (such as
    # nullptr) conflict with upcoming c++0x types.
    cflags_cc = [ "-Wno-c++0x-compat" ]
  }

#  # Some warnings occur in WTF headers, so they must also be disabled
#  # in targets that use WTF.
#  'msvs_disabled_warnings': [
#    # Don't complain about calling specific versions of templatized
#    # functions (e.g. in RefPtrHashMap.h).
#    4344,
#    # Don't complain about using "this" in an initializer list
#    # (e.g. in StringImpl.h).
#    4355,
#    # Disable c4267 warnings until we fix size_t to int truncations.
#    4267,
#  ],

}

component("wtf") {
  sources = [
    "ASCIICType.h",
    "Alignment.h",
    "ArrayBuffer.cpp",
    "ArrayBuffer.h",
    "ArrayBufferContents.cpp",
    "ArrayBufferContents.h",
    "ArrayBufferDeallocationObserver.h",
    "ArrayBufferView.cpp",
    "ArrayBufferView.h",
    "Assertions.cpp",
    "Assertions.h",
    "Atomics.h",
    "AutodrainedPool.h",
    "BitArray.h",
    "BitVector.cpp",
    "BitVector.h",
    "BloomFilter.h",
    "ByteOrder.h",
    "CPU.h",
    "CheckedArithmetic.h",
    "Compiler.h",
    "Complex.h",
    "CryptographicallyRandomNumber.cpp",
    "CryptographicallyRandomNumber.h",
    "CurrentTime.cpp",
    "CurrentTime.h",
    "DataLog.cpp",
    "DataLog.h",
    "DateMath.cpp",
    "DateMath.h",
    "DecimalNumber.cpp",
    "DecimalNumber.h",
    "Deque.h",
    "DoublyLinkedList.h",
    "DynamicAnnotations.cpp",
    "DynamicAnnotations.h",
    "FastAllocBase.h",
    "FastMalloc.cpp",
    "FastMalloc.h",
    "FilePrintStream.cpp",
    "FilePrintStream.h",
    "Float32Array.h",
    "Float64Array.h",
    "Forward.h",
    "Functional.h",
    "GetPtr.h",
    "GregorianDateTime.cpp",
    "GregorianDateTime.h",
    "HashCountedSet.h",
    "HashFunctions.h",
    "HashIterators.h",
    "HashMap.h",
    "HashSet.h",
    "HashTable.cpp",
    "HashTable.h",
    "HashTableDeletedValueType.h",
    "HashTraits.h",
    "HexNumber.h",
    "Int16Array.h",
    "Int32Array.h",
    "Int8Array.h",
    "IntegralTypedArrayBase.h",
    "LeakAnnotations.h",
    "LinkedStack.h",
    "ListHashSet.h",
    "Locker.h",
    "MainThread.cpp",
    "MainThread.h",
    "MallocZoneSupport.h",
    "MathExtras.h",
    "MessageQueue.h",
    "NonCopyingSort.h",
    "Noncopyable.h",
    "NotFound.h",
    "NullPtr.cpp",
    "NullPtr.h",
    "NumberOfCores.cpp",
    "NumberOfCores.h",
    "OwnPtr.h",
    "OwnPtrCommon.h",
    "PageAllocator.cpp",
    "PageAllocator.h",
    "ParallelJobs.h",
    "ParallelJobsGeneric.cpp",
    "ParallelJobsGeneric.h",
    "ParallelJobsLibdispatch.h",
    "PartitionAlloc.cpp",
    "PartitionAlloc.h",
    "PassOwnPtr.h",
    "PassRefPtr.h",
    "PassTraits.h",
    "PrintStream.cpp",
    "PrintStream.h",
    "ProcessID.h",
    "QuantizedAllocation.cpp",
    "QuantizedAllocation.h",
    "RefCounted.h",
    "RefCountedLeakCounter.cpp",
    "RefCountedLeakCounter.h",
    "RefPtr.h",
    "RefPtrHashMap.h",
    "RetainPtr.h",
    "SHA1.cpp",
    "SHA1.h",
    "SaturatedArithmetic.h",
    "SizeLimits.cpp",
    "SpinLock.h",
    "StaticConstructors.h",
    "StdLibExtras.h",
    "StringExtras.h",
    "StringHasher.h",
    "TemporaryChange.h",
    "ThreadFunctionInvocation.h",
    "ThreadRestrictionVerifier.h",
    "ThreadSafeRefCounted.h",
    "ThreadSpecific.h",
    "Threading.cpp",
    "Threading.h",
    "ThreadingPrimitives.h",
    "TypeTraits.cpp",
    "TypeTraits.h",
    "TypedArrayBase.h",
    "Uint16Array.h",
    "Uint32Array.h",
    "Uint8Array.h",
    "UnusedParam.h",
    "VMTags.h",
    "Vector.h",
    "VectorTraits.h",
    "WTF.cpp",
    "WTF.h",
    "WTFExport.h",
    "WTFThreadData.cpp",
    "WTFThreadData.h",
    "WeakPtr.h",
    "dtoa.cpp",
    "dtoa.h",
    "dtoa/bignum-dtoa.cc",
    "dtoa/bignum-dtoa.h",
    "dtoa/bignum.cc",
    "dtoa/bignum.h",
    "dtoa/cached-powers.cc",
    "dtoa/cached-powers.h",
    "dtoa/diy-fp.cc",
    "dtoa/diy-fp.h",
    "dtoa/double-conversion.cc",
    "dtoa/double-conversion.h",
    "dtoa/double.h",
    "dtoa/fast-dtoa.cc",
    "dtoa/fast-dtoa.h",
    "dtoa/fixed-dtoa.cc",
    "dtoa/fixed-dtoa.h",
    "dtoa/strtod.cc",
    "dtoa/strtod.h",
    "dtoa/utils.h",
    "text/ASCIIFastPath.h",
    "text/AtomicString.cpp",
    "text/AtomicString.h",
    "text/AtomicStringHash.h",
    "text/Base64.cpp",
    "text/Base64.h",
    "text/CString.cpp",
    "text/CString.h",
    "text/IntegerToStringConversion.h",
    "text/StringBuffer.h",
    "text/StringBuilder.cpp",
    "text/StringBuilder.h",
    "text/StringConcatenate.h",
    "text/StringHash.h",
    "text/StringImpl.cpp",
    "text/StringImpl.h",
    "text/StringOperators.h",
    "text/StringStatics.cpp",
    "text/StringUTF8Adaptor.h",
    "text/StringView.h",
    "text/TextCodec.cpp",
    "text/TextCodecASCIIFastPath.h",
    "text/TextCodecICU.cpp",
    "text/TextCodecLatin1.cpp",
    "text/TextCodecUTF16.cpp",
    "text/TextCodecUTF8.cpp",
    "text/TextCodecUTF8.h",
    "text/TextCodecUserDefined.cpp",
    "text/TextEncoding.cpp",
    "text/TextEncodingRegistry.cpp",
    "text/TextPosition.cpp",
    "text/TextPosition.h",
    "text/WTFString.cpp",
    "text/WTFString.h",
    "unicode/CharacterNames.h",
    "unicode/Collator.h",
    "unicode/UTF8.cpp",
    "unicode/UTF8.h",
    "unicode/Unicode.h",
    "unicode/icu/CollatorICU.cpp",
    "unicode/icu/UnicodeIcu.h",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":wtf-config"
  ]

  defines = [ "WTF_IMPLEMENTATION=1" ]
  deps = [
    "//third_party/icu:icui18n",
    "//third_party/icu:icuuc",
  ]

  #  # Disable c4267 warnings until we fix size_t to int truncations.
# 'msvs_disabled_warnings': [4127, 4355, 4510, 4512, 4610, 4706, 4068, 4267],

  if (is_android) {
    ldflags += [ "-llog" ]
  }

  if (is_mac) {
#    'link_settings': {
#            'libraries': [
#              '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework',
#              '$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
#            ]
#          }
    sources += [
      # mac is the only OS that uses WebKit's copy of TCMalloc.
      "TCPackedCache.h",
      "TCPageMap.h",
      "TCSpinLock.h",
      "TCSystemAlloc.cpp",
      "TCSystemAlloc.h",

      "AutodrainedPoolMac.mm",
      "text/AtomicStringCF.cpp",
      "text/StringCF.cpp",
      "text/StringImplCF.cpp",
      "text/StringImplMac.mm",
      "text/StringMac.mm",
    ]
  }

  if (is_win) {
    sources += [
      "ThreadSpecificWin.cpp",
      "ThreadingWin.cpp",
    ]
#    include_dirs -= [
#      "<(SHARED_INTERMEDIATE_DIR)/blink',
#    ]
  } else {
    sources += [
      "ThreadIdentifierDataPthreads.cpp",
      "ThreadIdentifierDataPthreads.h",
      "ThreadingPthreads.cpp",
    ]
  }
}

static_library("run_all_tests") {
  sources = [ "testing/RunAllTests.cpp" ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":wtf-config",
  ]

  deps = [
    "//base:test_support_base",
    "//testing:gmock",
    "//testing:gtest",
    ":wtf",
  ]

  direct_dependent_configs = [ "//testing:gtest_config" ]
}

executable("wtf_unittests") {
  sources = [
    "CheckedArithmeticTest.cpp",
    "FunctionalTest.cpp",
    "HashMapTest.cpp",
    "HashSetTest.cpp",
    "ListHashSetTest.cpp",
    "MathExtrasTest.cpp",
    "PartitionAllocTest.cpp",
    "SHA1Test.cpp",
    "SaturatedArithmeticTest.cpp",
    "SpinLockTest.cpp",
    "StringExtrasTest.cpp",
    "StringHasherTest.cpp",
    "TemporaryChangeTest.cpp",
    "VectorTest.cpp",
    "testing/WTFTestHelpers.h",
    "text/CStringTest.cpp",
    "text/StringBuilderTest.cpp",
    "text/StringImplTest.cpp",
    "text/StringOperatorsTest.cpp",
    "text/WTFStringTest.cpp",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    "//third_party/icu:icu_config",
    ":wtf-config",
  ]

  deps = [ ":run_all_tests" ]

  #  # Disable c4267 warnings until we fix size_t to int truncations.
# 'msvs_disabled_warnings': [4127, 4355, 4510, 4512, 4610, 4706, 4068, 4267],

#  if (is_linux && use_tcmalloc) {
#     deps += [
#      "//base:base",
#      "//base/allocator:allocator",
#    ],
#  }
}