[Libosinfo] [libosinfo PATCH 2/3] build: make curl optional, and only for tests

Pino Toscano ptoscano at redhat.com
Tue Oct 17 15:23:32 UTC 2017


Look for curl only when the tests are enabled, and as optional build
dependency.  If curl is missing, then the two network tests are not
built.  Also, limit the use of curl CFLAGS/LIBS only for the tests that
really need it.

As side result, it is possible to drop the curl BuildRequires from the
mingw spec, as it builds with --enable-tests=no.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 README                  |  2 +-
 configure.ac            |  9 +++++----
 mingw-libosinfo.spec.in |  2 --
 tests/Makefile.am       | 21 +++++++++++++--------
 4 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/README b/README
index 1d1f47a..1a0fa2e 100644
--- a/README
+++ b/README
@@ -21,12 +21,12 @@ Dependencies
 - Required:
   - gobject-2.0
   - gio-2.0
-  - libcurl
   - libxml-2.0
   - libxslt-1.0
 
 - Optional:
   - gobject-introspection
+  - libcurl (for tests only)
   - Vala (build-time only)
 
 Patch submissions
diff --git a/configure.ac b/configure.ac
index cba5268..99abe94 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,10 +49,6 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MAX_ALLOWED=$GLIB_ENCODED_VERSION"
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
-PKG_CHECK_MODULES([CURL], [libcurl])
-AC_SUBST(CURL_CFLAGS)
-AC_SUBST(CURL_LIBS)
-
 GTK_DOC_CHECK([1.10],[--flavour no-tmpl])
 
 AC_ARG_ENABLE([tests],
@@ -60,7 +56,12 @@ AC_ARG_ENABLE([tests],
         [], [enable_tests=yes])
 
 if test "x$enable_tests" != "xno" ; then
+  have_curl=no
   PKG_CHECK_MODULES([CHECK], [check])
+  PKG_CHECK_MODULES([CURL], [libcurl], [have_curl=yes], [:])
+  AC_SUBST(CURL_CFLAGS)
+  AC_SUBST(CURL_LIBS)
+  AM_CONDITIONAL([HAVE_CURL],[test "x$have_curl" = "xyes"])
 fi
 
 AM_CONDITIONAL([ENABLE_TESTS],[test "x$enable_tests" = "xyes"])
diff --git a/mingw-libosinfo.spec.in b/mingw-libosinfo.spec.in
index 0653282..526d65a 100644
--- a/mingw-libosinfo.spec.in
+++ b/mingw-libosinfo.spec.in
@@ -26,8 +26,6 @@ BuildRequires: mingw32-libxml2
 BuildRequires: mingw64-libxml2
 BuildRequires: mingw32-libxslt
 BuildRequires: mingw64-libxslt
-BuildRequires: mingw32-libcurl
-BuildRequires: mingw64-libcurl
 
 BuildRequires: pkgconfig
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e3df06b..9315e04 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,16 +16,20 @@ check_PROGRAMS = \
 	test-db \
 	test-loader \
 	test-isodetect \
-	test-mediauris \
-	test-treeuris \
 	test-install-script \
         $(NULL)
 
+if HAVE_CURL
+check_PROGRAMS += \
+	test-mediauris \
+	test-treeuris \
+	$(NULL)
+endif
+
 COMMON_LDADD = \
 	$(COVERAGE_LDFLAGS) \
 	$(GLIB_LIBS) \
 	$(GOBJECT_LIBS) \
-	$(CURL_LIBS) \
 	$(CHECK_LIBS) \
 	../osinfo/libosinfo-1.0.la
 COMMON_CFLAGS = \
@@ -33,7 +37,6 @@ COMMON_CFLAGS = \
 	$(COVERAGE_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(GOBJECT_CFLAGS) \
-	$(CURL_CFLAGS) \
 	-I$(top_srcdir) \
 	-DSRCDIR="\"$(abs_top_srcdir)\"" \
 	-DBUILDDIR="\"$(abs_top_builddir)\"" \
@@ -95,13 +98,15 @@ test_isodetect_LDADD = $(COMMON_LDADD)
 test_isodetect_CFLAGS = $(COMMON_CFLAGS)
 test_isodetect_SOURCES = test-isodetect.c
 
-test_mediauris_LDADD = $(COMMON_LDADD)
-test_mediauris_CFLAGS = $(COMMON_CFLAGS)
+if HAVE_CURL
+test_mediauris_LDADD = $(COMMON_LDADD) $(CURL_LIBS)
+test_mediauris_CFLAGS = $(COMMON_CFLAGS) $(CURL_CFLAGS)
 test_mediauris_SOURCES = test-mediauris.c
 
-test_treeuris_LDADD = $(COMMON_LDADD)
-test_treeuris_CFLAGS = $(COMMON_CFLAGS)
+test_treeuris_LDADD = $(COMMON_LDADD) $(CURL_LIBS)
+test_treeuris_CFLAGS = $(COMMON_CFLAGS) $(CURL_CFLAGS)
 test_treeuris_SOURCES = test-treeuris.c
+endif
 
 test_install_script_LDADD = $(COMMON_LDADD)
 test_install_script_CFLAGS = $(COMMON_CFLAGS)
-- 
2.13.6




More information about the Libosinfo mailing list