1 year ago
#272755
Kaytoo
How to add conditional configuration in configure.ac based on presence of a compilation flag?
In my autotools project, a config flag is used, CONFIG_ABC in abc.mk as below
#abc.mk
if CONFIG_ABC
src_CPPFLAGS += $(XML_CFLAGS)
src_CPPFLAGS += -I$(top_srcdir)/src/abc -I$(top_srcdir)/src/def
src_LDADD = $(ABC_LIBS)
src_LDADD += $(XML_LIBS)
endif
In configure.ac, I want below lines to be performed only if CONFIG_ABC is defined.
$PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
PKG_CHECK_MODULES(XML, libxml-2.0 >= 2.6)
AC_CHECK_LIB([xml2], [xmlCleanupParser], [XML_LIBS=" -lxml2 -lz -lm"],
[AC_MSG_ERROR([Cannot find xmlCleanupParser in xml2.])])
LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs libxml-2.0`"
CFLAGS="$CFLAGS `$PKG_CONFIG --cflags libxml-2.0`"
AC_CHECK_HEADERS([libxml/parser.h], [], [AC_MSG_ERROR([cannot find libxml/parser.h])])
Reason I need to do it: Build goes through for my project. But because it is shared in bigger projects, the other projects' build fails as it cannot find libxml. Those projects don't need libxml anyway. So I want the libxml to be included in build only for project ABC.
How do I do that?
Below are my failed attempts in configure.ac
1) AM_COND_IF([CONFIG_ABC],
AC_CHECK_LIB([xml2], [xmlCleanupParser], [XML_LIBS=" -lxml2 -lz -lm"])
AC_SUBST(XML_LIBS)
,)
2) Check if libxml is present (with_libxml), do PKG_CHECK_MODULES()
I need to put this in case because build error occurs for syntax for PKG_CHECK_MODULES.
AS_CASE(
["$with_libxml"],
[yes], [PKG_CHECK_MODULES(XML, [libxml-2.0 >= 2.6], [HAVE_LIBXML_PARSER_H=1],
[AC_MSG_ERROR("libxml-2.0 >= 2.6 is not installed")])],
[no], [HAVE_LIBXML_PARSER_H=0],
[PKG_CHECK_MODULES(XML, libxml-2.0 >= 2.6, [HAVE_LIBXML_PARSER_H=1],[HAVE_LIBXML_PARSER_H=0])])
3) AS_IF([test "x$CONFIG_ABC" != ""],
[PKG_CHECK_MODULES(XML, libxml-2.0 >= 2.6)],
[AC_MSG_ERROR([CONFIG_ABC is blank])])
I picked up the name "HAVE_LIBXML_PARSER_H" from the build.
Can someone please help me understand what I am doing wrong? Will using if test----fi help here?
configure
libxml2
autotools
autoconf
0 Answers
Your Answer