morxa
morxa

Reputation: 3364

Project-wide copts and linkopts in Bazel

In my BUILD file, I have several libraries:

cc_library(
    name = "foo",
    srcs = [ "foo.cpp" ],
    hdrs = [ "foo.h" ],
    copts = [ "-Wall" ],
)
cc_library(
    name = "bar",
    srcs = [ "bar.cpp" ],
    hdrs = [ "bar.h" ],
    copts = [ "-Wall" ],
)

As you can see, both libraries share the same copts. Similarly, I have multiple binaries with the same linkopts. How can I define these compiler flags once in my BUILD such that I don't need to add it to every library and binary separately?

Upvotes: 3

Views: 1738

Answers (1)

Damien Martin-Guillerez
Damien Martin-Guillerez

Reputation: 2370

The correct way would be to configure your cc flags to your CROSSTOOL file, it is now auto-generated though so you will have to create a custom one.

The easiest way would be to define them using the --copt flag and putting it a bazelrc file in tools/bazel.rc

Upvotes: 2

Related Questions