I'm trying to write bazel rules for a 3rd party library that specify different pre-processor define values per file i.e.
c++ ... -DVALUE=file1.cpp -c file1.cpp
c++ ... -DVALUE=file2.cpp -c file2.cpp
c++ ... -DVALUE=file3.cpp -c file3.cpp
This is basically set_property() on the file to add COMPILE_DEFINITIONS in CMake.
Using copts or local_defines for cc_library() doesn't seem to support this use case as they are common for all source files in the library.
The terrible ways to do this that I can think of:
- have a private library per file and consolidate all of them to one library.
- Patch the library or inject a header file using
-includeto add the definition.
Is there a better way to achieve this? Thanks!
__FILE__to your disposal.__FILE__is the right thing to do but note that these are 3rd party libs and we try to avoid modifications when we can. I think the question is still valid when you have to deal with 3rd party libs..cppfiles that define the macros and then#includethe original ones.