On 9/10/2021 03:40, Peter Dimov wrote:
John Maddock wrote:
I have a regex bug report relating to linking to ICU when using CMake: https://github.com/boostorg/regex/issues/143
Is there a correct way to specify in the CMake file that if you use header X, then you should also link to library Y, but otherwise not?
I don't see how. CMake doesn't know whether someone will include header X or not.
Provided that you can assume that the config (in the form of a #define) is visible to every compilation unit (or at least those that consume the library in some fashion), then you could make the header file itself define and do nothing (or perhaps raise a #error) if not enabled in the configuration. This way, attempts to use the header will fail unless enabled in the config, which would allow you to add dependencies as required. I'm not sure how straightforward it is to do this in CMake, although I thought "building everything with the same settings" is explicitly one of its goals.