views:

84

answers:

2

I'm working on a relatively big project that is using automake build system.

Now the problem is that I need to link the project with a library from another project (this works fine), but I also need to include a header from the other project source tree (api.h).

INCLUDES = -I@REMOTE_PROJECT_DIR@

in Makefile.am doesn't work, because there are .h files with coliding names in the remote source directory. How can I add just the api.h?

I used a symlink into the include directory in the project, but now I need to push the sources into a public repo and everyone working with it has the other project in a different directory, so I need to use the configure param.

A: 

If you have headers with same names, you could put at least one of them into directory with different name and include it using directory name.

Here's a sample directory structure:

mylibrary/include/myblirary/api.h

myproject/api.h 
myproject/main.cpp 

In main.cpp:

#include "api.h"
#include "mylibrary/api.h"

#include <boost/regex.hpp>

When compiling:

g++ -I mylibrary/include

Dmitry Yudakov
A: 

You do not want to tweak you Makefile.am or your configure.ac in any way. If api.h is installed in a standard location (eg /usr/include), then all you need is AC_CHECK_HEADERS([api.h]) in configure.ac. If api.h is installed in a non-standard location (eg /home/joe/include), the way to pick it up in your project is determined at configure time. When you run configure, you add the argument CPPFLAGS=-I/home/joe/include to the invocation of configure. You do not indicate the non-standard location in the build files themselves.

Another alternative is to use pkg-config, but the non-standard location of your header file will still be dealt with when you run configure. (This time by setting PKG_CONFIG_PATH rather than CPPFLAGS)

William Pursell
Yes, its in nonstandard location. But how do I compile the files against the header? I need to have the include path during compilation as well, otherwise it won't work.
Let_Me_Be
When you add CPPFLAGS=-I/path/to/include, you are telling the build system where it needs to look for header files. All invocations of make that invoke the preprocessor will have -I/path/to/include passed as an argument to $CPP
William Pursell
@WilliamPursel I know, but thats exactly what my question is about. How do I do it without adding the include path. Because that is what I can't do.
Let_Me_Be
You can't, except by mangling your project. If you want to avoid having to type it, you can put it in your environment or use a CONFIG_SITE. The non-standard location in which you have installed the dependency on your machine is *not* an inherent part of your project, and therefore your project's build files should not know anything about it.
William Pursell