Import cmocka library in Bazel Build

133 views Asked by At

I'm using cmocka with Bazel and I want to import cmocka library in my test files (for c embedded code) like <cmocka.h> but I'm always getting: cmocka.h: No such file or directory.

my Build is:

cc_library(
    name = "mock",
    srcs = ["mock_i2c.c"],
    deps = [":src"],
    visibility = ["//visibility:public"],
    linkstatic = True,
    copts = ["-I test/cmocka/include"],
)
1

There are 1 answers

5
slsy On

There is a includes attribute for that case, also you need to add your headers to hdrs attribute:

cc_library(
    name = "mock",
    srcs = ["mock_i2c.c"],
    deps = [":src"],
    hdrs = glob(["test/cmocka/include/**/*.h"]),
    visibility = ["//visibility:public"],
    linkstatic = True,
    includes= ["test/cmocka/include"],
)