0
votes

I'm new to Autotools and I'm trying to add gtest Unit Tests to a project that is using Autotools.

I have a simple directories structure:
. - main
./src - sources
./tests - tests
./paths - git submodule with paths

In tests directory I have one cpp file per tested class and my Makefile.am looks like so:

AUTOMAKE_OPTIONS = serial-tests

AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/paths  -DUNIT_TEST
AM_LDFLAGS = -pthread
LDADD = -lgtest -lgtest_main

TESTS = test_networkconfig test_dummy   ### depending on content of this variable
check_PROGRAMS = $(TESTS)

test_networkconfig_SOURCES = test_networkconfig.cpp             ### generate this
test_networkconfig_LDADD = $(top_srcdir)/src/networkconfig.o \
                           -lgtest \
                           -lgtest_main

test_networkconfig_CPPFLAGS = $(somelibrary_CFLAGS)

test_dummy_SOURCES = test_dummy.cpp                         ### and this variable

I would like to automatically generate:

test_networkconfig_SOURCES = test_networkconfig.cpp
test_dummy_SOURCES = test_dummy.cpp

Is there a way to create a variable <some_name>_SOURCES = <some_name>.cpp for each value that is held by TESTS variable?

1

1 Answers

1
votes

In Automake you can only do this in a limited way. In particular, for a program P, if P_SOURCES is not defined, then Automake will compute a default using the program name and the value of AM_DEFAULT_SOURCE_EXT (defaults to .c).

So in your case:

AM_DEFAULT_SOURCE_EXT = .cpp

should do the trick.