【问题标题】:How to ignore a build directory if Boost is not present如果 Boost 不存在,如何忽略构建目录
【发布时间】:2021-06-30 07:58:27
【问题描述】:

我的项目的顶层目录有一个 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

我有一个包含 Makefile.am 的子目录 boost_test,其内容如下:

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 目录应该被忽略。

【问题讨论】:

    标签: c++ boost makefile configure


    【解决方案1】:

    您可以使用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
    

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 2015-02-27
      • 1970-01-01
      • 2012-03-28
      • 2011-10-03
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多