您应该指定一个build target,它指向您存储库中 gtest 库的位置。例如,您可以将它放在third-party/cxx/google-test 中,并且您在该目录中的BUCK 文件看起来像这样:
导入操作系统
def subdir_glob(glob_specs):
"""
给定一个元组列表,(relative-sub-directory, glob-pattern) 的形式,
将子目录相对路径的字典返回到完整路径。对...有用
为 C/C++ 库定义头映射,它应该是相对于给定的
子目录。
"""
结果 = {}
对于 dirpath,glob_specs 中的 glob_pattern:
文件 = glob([os.path.join(dirpath, glob_pattern)])
对于文件中的 f:
如果目录路径:
结果[f[len(dirpath) + 1:]] = f
别的:
结果[f] = f
返回结果
cxx_图书馆(
名称 = '谷歌测试',
srcs = glob(['src/**/*.cc'], excludes=['src/gtest-all.cc']),
# 不是所有的编译器都支持 ,所以让 gtest 使用它
# 内部实现。
导出的预处理器标志 = [
'-DGTEST_USE_OWN_TR1_TUPLE=1',
],
header_namespace = '',
导出的_headers = subdir_glob([
('', 'src/**/*.h'),
('包括', '**/*.h'),
]),
部门= [
':pthread',
],
能见度 = [
'上市',
],
)
# libpthread 隐式包含在 android 运行时中,因此,在构建时
# 在安卓平台上,我们什么都不做。
prebuilt_cxx_library(
名称 = 'pthread',
header_only = 真,
platform_linker_flags = [
('安卓', []),
('', ['-lpthread']),
],
能见度 = [
'上市',
],
)
然后在您的.buckconfig 中,您将拥有这个:
[cxx]
gtest_dep = //第三方/cxx/google-test:google-test
注意 subdir glob 是 Buck 未来可能提供的东西。