如果不存在 Boost,如何忽略构建目录
How to ignore a build directory if Boost is not present
我的项目的顶层目录有一个 configure.ac 文件,为了包含 Boost Test 库,我为其添加了以下行:
BOOST_REQUIRE([1.48])
BOOST_TEST
我正在使用 boost.m4 宏。
configure.ac 文件还包含以下代码:
AC_OUTPUT([
Makefile
include/Makefile
extra/Makefile
comm/Makefile
log/Makefile
strings/Makefile
app1/Makefile
app2/Makefile
app3/Makefile
http/Makefile
locks/Makefile
lib/Makefile
test/Makefile
boost_test/Makefile
])
我的顶级目录有一个 Makefile.am 文件,其内容如下:
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = include extra comm log strings app1 app2 app3 http locks lib test boost_test
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = metrutil.pc
我有一个子目录 boost_test,其中包含一个 Makefile.am,内容如下:
AM_CXXFLAGS = @CXXFLAGS@ -I$(top_srcdir)/include $(BOOST_CPPFLAGS) -g -Wall
AM_CFLAGS = @CFLAGS@ -I$(top_srcdir)/include -g -Wall
AM_LDFLAGS = -static $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
LDADD = ../lib/libmetrutil.la $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
bin_PROGRAMS = \
tests
tests_SOURCES = \
main.cpp \
test1.cpp \
test2.cpp \
test3.cpp
我的问题是我们项目中的很多工程师都不知道 Boost,因此他们的系统中没有安装 Boost。我应该如何修改 configure.ac 和 Makefile.am 文件,以便如果系统中存在 Boost,则生成并执行 boost_test Makefile?如果系统没有安装 Boost,那么应该忽略 boost_test 目录。
您可以使用AM_CONDITIONAL
检查boost库是否存在。然后在Makefile.am中可以使用if endif
。这是一个例子
在configure.ac中,我假设你已经完成了boost check宏并将结果存储在变量$enable_boost
中
AM_CONDITIONAL([BOOST_ENABLED], test "$enable_boost" = yes)
在Makefile.am
if BOOST_ENABLED
SUBDIRS += boost_test
endif
我的项目的顶层目录有一个 configure.ac 文件,为了包含 Boost Test 库,我为其添加了以下行:
BOOST_REQUIRE([1.48])
BOOST_TEST
我正在使用 boost.m4 宏。
configure.ac 文件还包含以下代码:
AC_OUTPUT([
Makefile
include/Makefile
extra/Makefile
comm/Makefile
log/Makefile
strings/Makefile
app1/Makefile
app2/Makefile
app3/Makefile
http/Makefile
locks/Makefile
lib/Makefile
test/Makefile
boost_test/Makefile
])
我的顶级目录有一个 Makefile.am 文件,其内容如下:
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = include extra comm log strings app1 app2 app3 http locks lib test boost_test
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = metrutil.pc
我有一个子目录 boost_test,其中包含一个 Makefile.am,内容如下:
AM_CXXFLAGS = @CXXFLAGS@ -I$(top_srcdir)/include $(BOOST_CPPFLAGS) -g -Wall
AM_CFLAGS = @CFLAGS@ -I$(top_srcdir)/include -g -Wall
AM_LDFLAGS = -static $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
LDADD = ../lib/libmetrutil.la $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
bin_PROGRAMS = \
tests
tests_SOURCES = \
main.cpp \
test1.cpp \
test2.cpp \
test3.cpp
我的问题是我们项目中的很多工程师都不知道 Boost,因此他们的系统中没有安装 Boost。我应该如何修改 configure.ac 和 Makefile.am 文件,以便如果系统中存在 Boost,则生成并执行 boost_test Makefile?如果系统没有安装 Boost,那么应该忽略 boost_test 目录。
您可以使用AM_CONDITIONAL
检查boost库是否存在。然后在Makefile.am中可以使用if endif
。这是一个例子
在configure.ac中,我假设你已经完成了boost check宏并将结果存储在变量$enable_boost
AM_CONDITIONAL([BOOST_ENABLED], test "$enable_boost" = yes)
在Makefile.am
if BOOST_ENABLED
SUBDIRS += boost_test
endif