automake 中的通用 SOURCES 定义取决于其他变量
Generic SOURCES definition in automake depending on other variable
我是 Autotools 的新手,我正在尝试将 gtest 单元测试添加到使用 Autotools 的项目中。
我有一个简单的目录结构:
.
- 主要
./src
- 来源
./tests
- 测试
./paths
- git 具有路径的子模块
在 tests
目录中,每个测试有一个 cpp 文件 class,我的 Makefile.am
看起来像这样:
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
我要自动生成:
test_networkconfig_SOURCES = test_networkconfig.cpp
test_dummy_SOURCES = test_dummy.cpp
有没有办法为 TESTS
变量保存的每个值创建一个变量 <some_name>_SOURCES = <some_name>.cpp
?
在 Automake 中,您只能以有限的方式执行此操作。特别是,对于程序 P
,如果未定义 P_SOURCES
,则 Automake 将使用程序名称和 AM_DEFAULT_SOURCE_EXT
的值(默认为 .c
)计算默认值.
所以在你的情况下:
AM_DEFAULT_SOURCE_EXT = .cpp
应该可以解决问题。
我是 Autotools 的新手,我正在尝试将 gtest 单元测试添加到使用 Autotools 的项目中。
我有一个简单的目录结构:
.
- 主要
./src
- 来源
./tests
- 测试
./paths
- git 具有路径的子模块
在 tests
目录中,每个测试有一个 cpp 文件 class,我的 Makefile.am
看起来像这样:
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
我要自动生成:
test_networkconfig_SOURCES = test_networkconfig.cpp
test_dummy_SOURCES = test_dummy.cpp
有没有办法为 TESTS
变量保存的每个值创建一个变量 <some_name>_SOURCES = <some_name>.cpp
?
在 Automake 中,您只能以有限的方式执行此操作。特别是,对于程序 P
,如果未定义 P_SOURCES
,则 Automake 将使用程序名称和 AM_DEFAULT_SOURCE_EXT
的值(默认为 .c
)计算默认值.
所以在你的情况下:
AM_DEFAULT_SOURCE_EXT = .cpp
应该可以解决问题。