Make use of ctpp2 optional.

This commit is contained in:
Matthieu Gautier 2017-02-22 12:05:44 +01:00
parent 7b76d432a7
commit 84796abb4c
7 changed files with 107 additions and 58 deletions

View File

@ -23,8 +23,10 @@ install_headers(
subdir:'kiwix/common' subdir:'kiwix/common'
) )
if has_ctpp2_dep
install_headers( install_headers(
'ctpp2/CTPP2VMStringLoader.hpp', 'ctpp2/CTPP2VMStringLoader.hpp',
subdir:'kiwix/ctpp2' subdir:'kiwix/ctpp2'
) )
endif

View File

@ -31,15 +31,7 @@
#include "common/pathTools.h" #include "common/pathTools.h"
#include "common/stringTools.h" #include "common/stringTools.h"
#include <unicode/putil.h> #include <unicode/putil.h>
#include "kiwix_config.h"
#ifndef __ANDROID__
#include <ctpp2/CDT.hpp>
#include <ctpp2/CTPP2FileLogger.hpp>
#include <ctpp2/CTPP2SimpleVM.hpp>
#include "ctpp2/CTPP2VMStringLoader.hpp"
using namespace CTPP;
#endif
using namespace std; using namespace std;
@ -70,7 +62,7 @@ namespace kiwix {
void reset(); void reset();
void setContentHumanReadableId(const string &contentHumanReadableId); void setContentHumanReadableId(const string &contentHumanReadableId);
#ifndef __ANDROID__ #ifdef ENABLE_CTPP2
string getHtml(); string getHtml();
#endif #endif

10
kiwix.pc.in Normal file
View File

@ -0,0 +1,10 @@
prefix=@prefix@
libdir=${prefix}/lib64
includedir=${prefix}/include
Name: libkiwix
Description: A library that contains a lot of things used by used by other kiwix programs
Version: 1.0
Requires: @requires@
Libs: -L${libdir} -lkiwix @extra_libs@
Cflags: -I${includedir}/ @extra_cflags@

View File

@ -3,74 +3,98 @@ project('kiwixlib', 'cpp',
license : 'GPL') license : 'GPL')
compiler = meson.get_compiler('cpp') compiler = meson.get_compiler('cpp')
find_library_in_compiler = meson.version().version_compare('>=0.31.0')
thread_dep = dependency('threads') thread_dep = dependency('threads')
libicu_dep = dependency('icu-i18n') libicu_dep = dependency('icu-i18n')
libzim_dep = dependency('libzim') libzim_dep = dependency('libzim')
pugixml_dep = dependency('pugixml') pugixml_dep = dependency('pugixml')
find_library_in_compiler = meson.version().version_compare('>=0.31.0')
has_ctpp2_dep = false
ctpp2_prefix_install = get_option('ctpp2-install-prefix') ctpp2_prefix_install = get_option('ctpp2-install-prefix')
ctpp2_link_args = []
if ctpp2_prefix_install == '' if ctpp2_prefix_install == ''
if not compiler.has_header('ctpp2/CTPP2Logger.hpp') if compiler.has_header('ctpp2/CTPP2Logger.hpp')
error('ctpp2/CTPP2Logger.hppnot found')
endif
if find_library_in_compiler if find_library_in_compiler
ctpp2_lib = compiler.find_library('ctpp2') ctpp2_lib = compiler.find_library('ctpp2')
else else
ctpp2_lib = find_library('ctpp2') ctpp2_lib = find_library('ctpp2')
endif endif
link_args = ['-lctpp2']
# if meson.is_cross_build() # if meson.is_cross_build()
# if host_machine.system() == 'windows' # if host_machine.system() == 'windows'
# link_args += ['-liconv'] # link_args += ['-liconv']
# endif # endif
# endif # endif
ctpp2_dep = declare_dependency(link_args:link_args) ctpp2_link_args = ['-lctpp2']
has_ctpp2_dep = true
ctpp2_dep = declare_dependency(link_args:ctpp2_link_args)
else
message('ctpp2/CTPP2Logger.hpp not found. Compiling without CTPP2 support')
endif
else else
if not find_library_in_compiler if not find_library_in_compiler
error('For custom ctpp2_prefix_install you need a meson version >=0.31.0') error('For custom ctpp2_prefix_install you need a meson version >=0.31.0')
endif endif
ctpp2_include_path = ctpp2_prefix_install + '/include' ctpp2_include_path = ctpp2_prefix_install + '/include'
ctpp2_include_args = ['-I'+ctpp2_include_path] ctpp2_include_args = ['-I'+ctpp2_include_path]
if not compiler.has_header('ctpp2/CTPP2Logger.hpp', args:ctpp2_include_args) if compiler.has_header('ctpp2/CTPP2Logger.hpp', args:ctpp2_include_args)
error('ctpp2/CTPP2Logger.hpp not found') ctpp2_include_dir = include_directories(ctpp2_include_path, is_system:true)
endif
ctpp2_include_path = include_directories(ctpp2_include_path, is_system:true)
ctpp2_lib_path = ctpp2_prefix_install+'/lib' ctpp2_lib_path = ctpp2_prefix_install+'/lib'
ctpp2_lib = compiler.find_library('ctpp2', dirs:ctpp2_lib_path) ctpp2_lib = compiler.find_library('ctpp2', dirs:ctpp2_lib_path)
link_args = ['-L'+ctpp2_lib_path, '-lctpp2']
# if meson.is_cross_build() # if meson.is_cross_build()
# if host_machine.system() == 'windows' # if host_machine.system() == 'windows'
# link_args += ['-liconv'] # link_args += ['-liconv']
# endif # endif
# endif # endif
ctpp2_dep = declare_dependency(include_directories:ctpp2_include_path, link_args:link_args) ctpp2_link_args = ['-L'+ctpp2_lib_path, '-lctpp2']
endif has_ctpp2_dep = true
ctpp2_dep = declare_dependency(include_directories:ctpp2_include_dir, link_args:ctpp2_link_args)
pkg_requires = ['libzim', 'icu-i18n', 'pugixml']
xapian_dep = dependency('xapian-core', required:false)
if xapian_dep.found()
pkg_requires += ['xapian-core']
message('xapian_dep found')
else else
message('xapian_dep not found') message('ctpp2/CTPP2Logger.hpp not found. Compiling without CTPP2 support')
endif
endif endif
all_deps = [thread_dep, libicu_dep, libzim_dep, ctpp2_dep, xapian_dep, pugixml_dep] xapian_dep = dependency('xapian-core', required:false)
all_deps = [thread_dep, libicu_dep, libzim_dep, xapian_dep, pugixml_dep]
if has_ctpp2_dep
all_deps += [ctpp2_dep]
endif
inc = include_directories('include') inc = include_directories('include')
conf = configuration_data()
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
conf.set('ENABLE_CTPP2', has_ctpp2_dep)
subdir('include') subdir('include')
subdir('scripts') subdir('scripts')
subdir('static') subdir('static')
subdir('src') subdir('src')
pkg_mod = import('pkgconfig') pkg_requires = ['libzim', 'icu-i18n', 'pugixml']
pkg_mod.generate(libraries : kiwixlib, if xapian_dep.found()
version : '1.0', pkg_requires += ['xapian-core']
name : 'libkiwix', endif
filebase : 'kiwix',
description : 'A library that contains a lot of things used by used by other kiwix programs', extra_libs = []
requires: pkg_requires) extra_cflags = ''
if has_ctpp2_dep
extra_libs += ctpp2_link_args
if ctpp2_include_path != ''
extra_cflags = '-I'+ctpp2_include_path
endif
endif
pkg_conf = configuration_data()
pkg_conf.set('prefix', get_option('prefix'))
pkg_conf.set('requires', ' '.join(pkg_requires))
pkg_conf.set('extra_libs', ' '.join(extra_libs))
pkg_conf.set('extra_cflags', extra_cflags)
configure_file(output : 'kiwix.pc',
configuration : pkg_conf,
input : 'kiwix.pc.in',
install_dir: get_option('libdir')+'/pkgconfig'
)

4
src/config.h.in Normal file
View File

@ -0,0 +1,4 @@
#mesondefine VERSION
#mesondefine ENABLE_CTPP2

View File

@ -10,7 +10,6 @@ kiwix_sources = [
'common/stringTools.cpp', 'common/stringTools.cpp',
'common/networkTools.cpp', 'common/networkTools.cpp',
'common/otherTools.cpp', 'common/otherTools.cpp',
'ctpp2/CTPP2VMStringLoader.cpp',
'xapian/htmlparse.cc', 'xapian/htmlparse.cc',
'xapian/myhtmlparse.cc' 'xapian/myhtmlparse.cc'
] ]
@ -20,6 +19,15 @@ if xapian_dep.found()
kiwix_sources += ['xapianIndexer.cpp', 'xapianSearcher.cpp'] kiwix_sources += ['xapianIndexer.cpp', 'xapianSearcher.cpp']
endif endif
if has_ctpp2_dep
kiwix_sources += ['ctpp2/CTPP2VMStringLoader.cpp']
endif
config_h = configure_file(output : 'kiwix_config.h',
configuration : conf,
input : 'config.h.in')
install_headers(config_h, subdir:'kiwix')
kiwixlib = library('kiwix', kiwixlib = library('kiwix',
kiwix_sources, kiwix_sources,
include_directories : inc, include_directories : inc,

View File

@ -20,6 +20,15 @@
#include "searcher.h" #include "searcher.h"
#include "kiwixlib-resources.h" #include "kiwixlib-resources.h"
#ifdef ENABLE_CTPP2
#include <ctpp2/CDT.hpp>
#include <ctpp2/CTPP2FileLogger.hpp>
#include <ctpp2/CTPP2SimpleVM.hpp>
#include "ctpp2/CTPP2VMStringLoader.hpp"
using namespace CTPP;
#endif
namespace kiwix { namespace kiwix {
@ -130,7 +139,7 @@ namespace kiwix {
this->contentHumanReadableId = contentHumanReadableId; this->contentHumanReadableId = contentHumanReadableId;
} }
#ifndef __ANDROID__ #ifdef ENABLE_CTPP2
string Searcher::getHtml() { string Searcher::getHtml() {