diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index ec32c27e9d..078f67156e 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -241,63 +242,31 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, std::list< wxString >& aPluginList ) { - // list potential plugins given a search paths - // note on typical plugin names: - // Linux: *.so, *.so.* (note: *.so.* will not be supported) - // MSWin: *.dll - // OSX: *.dylib, *.bundle + // list potential plugins given a search path - std::list< wxString > nameFilter; // filter to apply to files + wxString nameFilter; // filter for user-loadable libraries (aka modules) wxString lName; // stores name of enumerated files wxString fName; // full name of file - -#ifdef __linux - - nameFilter.push_back( wxString::FromUTF8Unchecked( "*.so" ) ); - -#elif defined _WIN32 - - nameFilter.push_back( wxString::FromUTF8Unchecked( "*.dll" ) ); - -#elif defined __APPLE__ - - nameFilter.push_back( wxString::FromUTF8Unchecked( "*.dylib" ) ); - nameFilter.push_back( wxString::FromUTF8Unchecked( "*.bundle" ) ); - -#else - - // note: we need to positively identify a supported OS here - // and add suffixes which may be used for 3D model plugins - // on the specific OS - #warning NOT IMPLEMENTED - -#endif - wxDir wd; wd.Open( aPath ); if( !wd.IsOpened() ) return; + nameFilter = wxT( "*" ); + nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) ); wxString lp = wd.GetNameWithSep(); - std::list< wxString >::iterator sExt = nameFilter.begin(); - std::list< wxString >::iterator eExt = nameFilter.end(); - while( sExt != eExt ) + if( wd.GetFirst( &lName, nameFilter, wxDIR_FILES ) ) { - if( wd.GetFirst( &lName, *sExt, wxDIR_FILES ) ) + fName = lp + lName; + checkPluginName( fName, aPluginList ); + + while( wd.GetNext( &lName ) ) { fName = lp + lName; checkPluginName( fName, aPluginList ); - - while( wd.GetNext( &lName ) ) - { - fName = lp + lName; - checkPluginName( fName, aPluginList ); - } } - - ++sExt; } wd.Close(); diff --git a/3d-viewer/CMakeLists.txt b/3d-viewer/CMakeLists.txt index 326343ed87..99d5393422 100644 --- a/3d-viewer/CMakeLists.txt +++ b/3d-viewer/CMakeLists.txt @@ -146,10 +146,6 @@ elseif(NOT GLM_ENABLE_FAST_MATH) endif() endif() -if( WIN32 ) - target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg ) -else() - target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg dl ) -endif() +target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg ) add_subdirectory( 3d_cache ) diff --git a/plugins/ldr/pluginldr.cpp b/plugins/ldr/pluginldr.cpp index 2d54ced08c..c9c308e859 100644 --- a/plugins/ldr/pluginldr.cpp +++ b/plugins/ldr/pluginldr.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "pluginldr.h" @@ -35,7 +36,6 @@ KICAD_PLUGIN_LDR::KICAD_PLUGIN_LDR() m_checkClassVersion = NULL; m_getPluginName = NULL; m_getVersion = NULL; - m_dlHandle = NULL; return; } @@ -60,18 +60,9 @@ bool KICAD_PLUGIN_LDR::open( const wxString& aFullFileName, const char* aPluginC m_fileName.clear(); -#ifdef _WIN32 - // NOTE: MSWin uses UTF-16 encoding - #if defined( UNICODE ) || defined( _UNICODE ) - m_dlHandle = LoadLibrary( aFullFileName.wc_str() ); - #else - m_dlHandle = LoadLibrary( aFullFileName.ToUTF8() ); - #endif -#else - m_dlHandle = dlopen( aFullFileName.ToUTF8(), RTLD_LAZY | RTLD_LOCAL ); -#endif + m_PluginLoader.Load( aFullFileName, wxDL_LAZY ); - if( NULL == m_dlHandle ) + if( !m_PluginLoader.IsLoaded() ) { #ifdef DEBUG std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; @@ -238,18 +229,7 @@ void KICAD_PLUGIN_LDR::close( void ) m_checkClassVersion = NULL; m_getPluginName = NULL; m_getVersion = NULL; - - if( NULL != m_dlHandle ) - { - -#ifdef _WIN32 - FreeLibrary( m_dlHandle ); -#else - dlclose( m_dlHandle ); -#endif - - m_dlHandle = NULL; - } + m_PluginLoader.Unload(); return; } diff --git a/plugins/ldr/pluginldr.h b/plugins/ldr/pluginldr.h index 3ae1fdc7df..33e6ce7e1e 100644 --- a/plugins/ldr/pluginldr.h +++ b/plugins/ldr/pluginldr.h @@ -32,22 +32,11 @@ #include #include +#include -// helper functions to link functions -#ifdef _WIN32 - -#include +// helper function to link functions in the plugin #define LINK_ITEM( funcPtr, funcType, funcName ) \ - funcPtr = (funcType) GetProcAddress( m_dlHandle, funcName ); - -#else - -#include -#define LINK_ITEM( funcPtr, funcType, funcName ) \ - *(void**) (&funcPtr) = dlsym( m_dlHandle, funcName ); - -#endif - + funcPtr = (funcType) m_PluginLoader.GetSymbol( wxT( funcName ) ) // typedefs of the functions exported by the 3D Plugin Class typedef char const* (*GET_PLUGIN_CLASS) ( void ); @@ -99,12 +88,8 @@ protected: */ bool reopen( void ); - // handle to the opened plugin - #ifdef _WIN32 - HMODULE m_dlHandle; - #else - void* m_dlHandle; - #endif + // the plugin loader + wxPluginManager m_PluginLoader; public: KICAD_PLUGIN_LDR();