support building without dlopen support

Conflicts:
	SConstruct
This commit is contained in:
Dane Springmeyer 2014-12-16 16:03:51 -05:00
parent 0c8c55031a
commit f8bedf4f65
2 changed files with 44 additions and 2 deletions

View file

@ -443,6 +443,7 @@ pickle_store = [# Scons internal variables
'PYTHON_SYS_PREFIX', 'PYTHON_SYS_PREFIX',
'COLOR_PRINT', 'COLOR_PRINT',
'HAS_CAIRO', 'HAS_CAIRO',
'MAPNIK_HAS_DLFCN',
'HAS_PYCAIRO', 'HAS_PYCAIRO',
'HAS_LIBXML2', 'HAS_LIBXML2',
'PYTHON_IS_64BIT', 'PYTHON_IS_64BIT',
@ -829,6 +830,24 @@ int main()
rm_path(item,'CPPPATH',context.env) rm_path(item,'CPPPATH',context.env)
return ret return ret
def CheckHasDlfcn(context, silent=False):
if not silent:
context.Message('Checking for dlfcn.h support ... ')
ret = context.TryCompile("""
#include <dlfcn.h>
int main()
{
return 0;
}
""", '.cpp')
if silent:
context.did_show_result=1
context.Result(ret)
return ret
def GetBoostLibVersion(context): def GetBoostLibVersion(context):
ret = context.TryRun(""" ret = context.TryRun("""
@ -989,6 +1008,7 @@ conf_tests = { 'prioritize_paths' : prioritize_paths,
'FindBoost' : FindBoost, 'FindBoost' : FindBoost,
'CheckBoost' : CheckBoost, 'CheckBoost' : CheckBoost,
'CheckCairoHasFreetype' : CheckCairoHasFreetype, 'CheckCairoHasFreetype' : CheckCairoHasFreetype,
'CheckHasDlfcn' : CheckHasDlfcn,
'GetBoostLibVersion' : GetBoostLibVersion, 'GetBoostLibVersion' : GetBoostLibVersion,
'parse_config' : parse_config, 'parse_config' : parse_config,
'parse_pg_config' : parse_pg_config, 'parse_pg_config' : parse_pg_config,
@ -1199,6 +1219,11 @@ if not preconfigured:
['harfbuzz', 'harfbuzz/hb.h',True,'C++'] ['harfbuzz', 'harfbuzz/hb.h',True,'C++']
] ]
if conf.CheckHasDlfcn():
env.Append(CPPDEFINES = '-DMAPNIK_HAS_DLCFN')
else:
env['SKIPPED_DEPS'].extend(['dlfcn'])
OPTIONAL_LIBSHEADERS = [] OPTIONAL_LIBSHEADERS = []
if env['JPEG']: if env['JPEG']:

View file

@ -31,7 +31,9 @@
#define dlclose FreeLibrary #define dlclose FreeLibrary
#define dlerror GetLastError #define dlerror GetLastError
#else #else
#ifdef MAPNIK_HAS_DLCFN
#include <dlfcn.h> #include <dlfcn.h>
#endif
#define handle void * #define handle void *
#endif #endif
@ -52,29 +54,44 @@ PluginInfo::PluginInfo(std::string const& filename,
{ {
#ifdef _WINDOWS #ifdef _WINDOWS
if (module_) module_->dl = LoadLibraryA(filename.c_str()); if (module_) module_->dl = LoadLibraryA(filename.c_str());
if (module_ && module_->dl)
{
name_func* name = reinterpret_cast<name_func*>(dlsym(module_->dl, library_name.c_str()));
if (name) name_ = name();
}
#else #else
#ifdef MAPNIK_HAS_DLCFN
if (module_) module_->dl = dlopen(filename.c_str(),RTLD_LAZY); if (module_) module_->dl = dlopen(filename.c_str(),RTLD_LAZY);
#endif
if (module_ && module_->dl) if (module_ && module_->dl)
{ {
name_func name = reinterpret_cast<name_func>(dlsym(module_->dl, library_name.c_str())); name_func name = reinterpret_cast<name_func>(dlsym(module_->dl, library_name.c_str()));
if (name) name_ = name(); if (name) name_ = name();
} }
#else
throw std::runtime_error("no support for loading dynamic objects (Mapnik not compiled with -DMAPNIK_HAS_DLCFN)");
#endif
#endif
} }
PluginInfo::~PluginInfo() PluginInfo::~PluginInfo()
{ {
if (module_) if (module_)
{ {
#ifdef MAPNIK_HAS_DLCFN
if (module_->dl) dlclose(module_->dl),module_->dl=0; if (module_->dl) dlclose(module_->dl),module_->dl=0;
delete module_; delete module_;
#endif
} }
} }
void * PluginInfo::get_symbol(std::string const& sym_name) const void * PluginInfo::get_symbol(std::string const& sym_name) const
{ {
#ifdef MAPNIK_HAS_DLCFN
return static_cast<void *>(dlsym(module_->dl, sym_name.c_str())); return static_cast<void *>(dlsym(module_->dl, sym_name.c_str()));
#else
return NULL;
#endif
} }
std::string const& PluginInfo::name() const std::string const& PluginInfo::name() const