2
votes

I have a project using autoconf and automake with following structure:

  • /
    • src/
      • class.h
      • class.cpp
    • test/
      • class_unittest.cpp

In class_unittest.cpp I include class.h in the source file and on compile also the class.cpp file. In automake config for test I add ../src as a new include path in AM_CPPFLAGS = -I../src/ definition and refer to the class.cpp relatively in SOURCES definition.

It works great when I'm building the software from the root directory, but if I try to do a VPATH build by creating a dir foo in root and in the dir call ../configure && make I will get missing header class.h errors when trying to compile class_unittest.cpp.

So how do I share the header for testing to avoid this problem?

1

1 Answers

4
votes

You can use the srcdir variable to refer to the equivalent source directory in a VPATH build.

AM_CPPFLAGS = -I$(srcdir)/../src