# craftr.lib.googlebenchmark

from craftr.loaders import external_archive

if not options.directory:
  options.directory = external_archive(
    "https://github.com/google/benchmark/archive/{}.zip".format(options.version)
  )

googlebenchmark = Framework(
  include = [path.join(options.directory, 'include')],
  libs = [],
  std = 'c++11'
)

if platform.name == 'win':
  googlebenchmark['libs'].append('Shlwapi')
else:
  googlebenchmark['libs'].append('pthread')

load('craftr.lang.cxx.*')

defines = []
if options.regex_backend == 'std':
  defines.append('HAVE_STD_REGEX')
elif options.regex_backend == 'gnu':
  defines.append('HAVE_GNU_POSIX_REGEX')
elif options.regex_backend == 'posix':
  defines.append('HAVE_POSIX_REGEX')
else:
  error('invalid value for {}.regex_backend="{}"'.format(__name__, options.regex_backend))

library = cxx_library(
  link_style = 'static',
  inputs = cpp_compile(
    sources = glob(['src/*.cc'], parent = options.directory),
    frameworks = [googlebenchmark],
    defines = defines
  ),
  output = 'gbenchmark'
)

cxx_extend_framework(googlebenchmark, library)
