einpoklum
einpoklum

Reputation: 132128

How to best handle different possible locations of uuid.h?

I'm building a library which uses a header named uuid.h. Unfortunately, on some GNU/Linux distributions, this header is located at /usr/include/uuid/uuid.h and on others it's located at /usr/include/linux/uuid.h.

Now, I do not want to add both of these subdirectories to the include search, i.e. I do want linux/whatever.h includes to need the linux/ prefix. But I do want to be able to build with both possible locations of the file.

I'm using CMake as my build system generator.

Hw can get I get my build to work, while keeping the source file verbosity for this situation to a minimum?

I was struggling particularly with the desire to introduce a preprocessor-varaible-value-based component into an include directory - which I don't believe can be done, i.e. I can't do

#include <UUID_SUBDIR/uuid.h>

and replace UUID_SUBDIR.

Upvotes: 0

Views: 18

Answers (1)

einpoklum
einpoklum

Reputation: 132128

One possibility is, in fact, to force a single location.

You see, /usr/include/uuid/uuid.h belongs to the libuuid library, while /usr/include/linux/uuid.h belongs to the Linux kernel headers.

You could, for example, demand the first one just be installed, like so:

find_package(PkgConfig REQUIRED)
pkg_check_modules(uuid IMPORTED_TARGET GLOBAL REQUIRED uuid)

... and thus also get a target named PkgConfig::uuid.

Upvotes: 0

Related Questions