Pulling in an include path from within a C++ project's source

20 hours ago 5
ARTICLE AD BOX

I have the following directory structure for a C++ project:

external eigen-5.0.1 Eigen source <source files>

When compiling, I add both external/eigen-5.0.1 and source to the -I include search path.

However, I have now modified the library to provide a header-only option, which is the default. To make life a bit easier for users, I want them to just have to add source to their -I include path. However, I'd like to meet the following constraints:

I do not want to move the Eigen directory into source because I like the logical separation of the external library with my source code.

I do not want to have to write #include "../external/eigen-5.0.1/Eigen/.. instead of the current #include "Eigen/...", (a) because it's unwieldy, and (b) because I'd have to go hunt down each occurrence if I change the Eigen version.

Is there a way that when a user adds source to their -I during compilation, the directory external/eigen-5.0.1 is automagically "pulled in", say with some kind of config file which specifies external/eigen-5.0.1?

The closest option seems this question, where I can define the path to Eigen as a macro in a single place and then use it as #include PATH "Eigen/.." in the code. But is there a better way?

Read Entire Article