From 3cf58b5f5b0cb8884a24ffdb3319ac4d4e85f6f1 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 3 Aug 2018 16:24:43 +0200 Subject: [PATCH 1/3] Make libaria2 an optional dependency. We don't compile libaria2 on Windows. --- include/downloader.h | 11 +++++++---- meson.build | 8 ++++++-- src/config.h.in | 2 ++ src/downloader.cpp | 9 ++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index 347fb1f19..a8b373cd6 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -21,7 +21,9 @@ #define KIWIX_DOWNLOADER_H #include -#include +#ifdef ENABLE_LIBARIA2 +# include +#endif #include namespace kiwix @@ -56,14 +58,15 @@ class Downloader private: static pthread_mutex_t globalLock; - aria2::Session* session; - DownloadedFile* fileHandle; std::string tmpDir; - +#ifdef ENABLE_LIBARIA2 + DownloadedFile* fileHandle; + aria2::Session* session; static int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event, aria2::A2Gid gid, void* userData); +#endif }; } diff --git a/meson.build b/meson.build index 50ae99ffe..ec51e6ef2 100644 --- a/meson.build +++ b/meson.build @@ -17,7 +17,7 @@ thread_dep = dependency('threads') libicu_dep = dependency('icu-i18n', static:static_deps) libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps) pugixml_dep = dependency('pugixml', static:static_deps) -libaria2_dep = dependency('libaria2', static:static_deps) +libaria2_dep = dependency('libaria2', static:static_deps, required:false) ctpp2_include_path = '' has_ctpp2_dep = false @@ -88,6 +88,7 @@ inc = include_directories('include') conf = configuration_data() conf.set('VERSION', '"@0@"'.format(meson.project_version())) conf.set('ENABLE_CTPP2', has_ctpp2_dep) +conf.set('ENABLE_LIBARIA2', libaria2_dep.found()) subdir('include') subdir('scripts') @@ -95,7 +96,10 @@ subdir('static') subdir('src') subdir('test') -pkg_requires = ['libzim', 'icu-i18n', 'pugixml', 'libaria2'] +pkg_requires = ['libzim', 'icu-i18n', 'pugixml'] +if libaria2_dep.found() + pkg_requires += ['libaria2'] +endif if xapian_dep.found() pkg_requires += ['xapian-core'] endif diff --git a/src/config.h.in b/src/config.h.in index 713be9c12..c6162d720 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -2,3 +2,5 @@ #mesondefine VERSION #mesondefine ENABLE_CTPP2 + +#mesondefine ENABLE_LIBARIA2 diff --git a/src/downloader.cpp b/src/downloader.cpp index b22429008..26b007bc4 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -32,6 +32,7 @@ pthread_mutex_t Downloader::globalLock = PTHREAD_MUTEX_INITIALIZER; /* Constructor */ Downloader::Downloader() { +#ifdef ENABLE_LIBARIA2 aria2::SessionConfig config; config.downloadEventCallback = Downloader::downloadEventCallback; config.userData = this; @@ -39,17 +40,20 @@ Downloader::Downloader() aria2::KeyVals options; options.push_back(std::pair("dir", tmpDir)); session = aria2::sessionNew(options, config); +#endif } /* Destructor */ Downloader::~Downloader() { +#ifdef ENABLE_LIBARIA2 aria2::sessionFinal(session); +#endif rmdir(tmpDir.c_str()); } - +#ifdef ENABLE_LIBARIA2 int Downloader::downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event, aria2::A2Gid gid, @@ -85,10 +89,12 @@ int Downloader::downloadEventCallback(aria2::Session* session, aria2::deleteDownloadHandle(dh); return 0; } +#endif DownloadedFile Downloader::download(const std::string& url) { pthread_mutex_lock(&globalLock); DownloadedFile fileHandle; +#ifdef ENABLE_LIBARIA2 try { std::vector uris = {url}; aria2::KeyVals options; @@ -106,6 +112,7 @@ DownloadedFile Downloader::download(const std::string& url) { } catch (...) {}; this->fileHandle = nullptr; pthread_mutex_unlock(&globalLock); +#endif return fileHandle; } From fd9b6569af335e91c1e09d1baed70943de626d82 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 3 Aug 2018 16:25:05 +0200 Subject: [PATCH 2/3] Include unistd.h only on unix platform. --- src/downloader.cpp | 4 +++- src/xapianSearcher.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/downloader.cpp b/src/downloader.cpp index 26b007bc4..e5a565b71 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -20,7 +20,9 @@ #include "downloader.h" #include "common/pathTools.h" -#include +#ifndef _WIN32 +# include +#endif #include namespace kiwix diff --git a/src/xapianSearcher.cpp b/src/xapianSearcher.cpp index e3102b49d..3040edebf 100644 --- a/src/xapianSearcher.cpp +++ b/src/xapianSearcher.cpp @@ -20,7 +20,9 @@ #include "xapianSearcher.h" #include #include -#include +#ifndef _WIN32 +# include +#endif #include #include #include From bf2188af14712cdea298f021374b831236806055 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 3 Aug 2018 17:55:01 +0200 Subject: [PATCH 3/3] [Windows] Add extra link arguments to build test on windows. --- meson.build | 6 ++++++ test/meson.build | 1 + 2 files changed, 7 insertions(+) diff --git a/meson.build b/meson.build index ec51e6ef2..43f87846b 100644 --- a/meson.build +++ b/meson.build @@ -90,6 +90,12 @@ conf.set('VERSION', '"@0@"'.format(meson.project_version())) conf.set('ENABLE_CTPP2', has_ctpp2_dep) conf.set('ENABLE_LIBARIA2', libaria2_dep.found()) +if build_machine.system() == 'windows' + extra_link_args = ['-lshlwapi', '-lwinmm'] +else + extra_link_args = [] +endif + subdir('include') subdir('scripts') subdir('static') diff --git a/test/meson.build b/test/meson.build index 9accb6562..9d29177fe 100644 --- a/test/meson.build +++ b/test/meson.build @@ -10,6 +10,7 @@ gtest_dep = dependency('gtest', fallback: ['gtest', 'gtest_dep']) foreach test_name : tests test_exe = executable(test_name, [test_name+'.cpp'], link_with : kiwixlib, + link_args: extra_link_args, dependencies : all_deps + [gtest_dep], build_rpath : '$ORIGIN') test(test_name, test_exe)