We are migrating a CMake project to Bazel. We have several header only libraries that are tagged SYSTEM in CMake project to suppress some warnings. When migrating these to Bazel, the way we are able to make this work is by using the below
cc_library(
name = "lib",
srcs = ["include/header1.h", ...],
includes = ["include"],
)
This works but as per Bazel C++ documentation, it is not recommended to have interface/public headers in srcs. Those should be part of hdrs. Adding these to headers doesn't work because it uses the regular -I based inclusion instead of -isystem.
Is our way of doing this fine, although not recommended by bazel? If not, what would be the correct way of doing it?
EDIT:
After some digging, found the textual_hdrs attribute on cc_library and using that it seems to work too. And this seems to be a cleaner approach than adding the public headers to srcs. Now the rule looks like this
cc_library(
name = "lib",
textual_hdrs = ["include/header1.h", ...],
includes = ["include"],
)
This looks like a good solution for us, except that the documentation on textual_hdrs isn't clear enough to indicate that this is what it is meant for.
PS: It is really not possible for us to refactor the code to fix the warnings as there are numerous libraries like this and just completely outside the scope of this migration effort.