From: Leonardo Florez Valencia Date: Sun, 9 Oct 2016 20:51:16 +0000 (-0500) Subject: Windows compilation 3/3 X-Git-Tag: v0.1~92 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1f5c3516bf4240bcdd91979ac303298ef1f75fc3;p=cpPlugins.git Windows compilation 3/3 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fb53f6..82cc483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ SET(prj_SHORT_VERSION "${prj_MAJOR_VERSION}") ## == Functions, packages and options == ## ===================================== -INCLUDE(cmake/DetectOS.cmake) INCLUDE(cmake/Restrictions.cmake) INCLUDE(cmake/Options.cmake) INCLUDE(cmake/Functions.cmake) diff --git a/appli/bash/Utility.h.in b/appli/bash/Utility.h.in index 95c8be0..7dda46f 100644 --- a/appli/bash/Utility.h.in +++ b/appli/bash/Utility.h.in @@ -6,14 +6,14 @@ #include // ------------------------------------------------------------------------- -#define @prj_NAME_OS@ -#ifdef @prj_NAME_OS@ -# define cpExtensions_STRTOK( A, B, N ) strtok_s( A, B, N ) -# define cpExtensions_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O ); -#else // @prj_NAME_OS@ -# define cpExtensions_STRTOK( A, B, N ) std::strtok( A, B ) -# define cpExtensions_SPRINTF( B, S, O ) std::sprintf( B, "%s", O ); -#endif // @prj_NAME_OS@ +#define cpPlugins_bash_OS_@CMAKE_SYSTEM_NAME@ +#ifdef cpPlugins_bash_OS_Windows +# define cpPlugins_bash_STRTOK( A, B, N ) strtok_s( A, B, N ) +# define cpPlugins_bash_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O ); +#else // cpPlugins_bash_OS_Windows +# define cpPlugins_bash_STRTOK( A, B, N ) std::strtok( A, B ) +# define cpPlugins_bash_SPRINTF( B, S, O ) std::sprintf( B, "%s", O ); +#endif // cpPlugins_bash_OS_Windows // ------------------------------------------------------------------------- namespace cpPlugins_bash @@ -33,11 +33,11 @@ namespace cpPlugins_bash buffer[ i ] = str[ i ]; buffer[ ssize ] = '\0'; char* next; - char* it = cpExtensions_STRTOK( buffer, delims.c_str( ), &next ); + char* it = cpPlugins_bash_STRTOK( buffer, delims.c_str( ), &next ); while( it != NULL ) { tokens.push_back( std::string( it ) ); - it = cpExtensions_STRTOK( NULL, delims.c_str( ), &next ); + it = cpPlugins_bash_STRTOK( NULL, delims.c_str( ), &next ); } // elihw delete [] buffer; diff --git a/appli/examples/plugins/GuessPlugins.cxx b/appli/examples/plugins/GuessPlugins.cxx index cf18784..6704b9b 100644 --- a/appli/examples/plugins/GuessPlugins.cxx +++ b/appli/examples/plugins/GuessPlugins.cxx @@ -4,8 +4,8 @@ int main( int argc, char* argv[] ) { // Create interface and load library - cpPlugins::Interface::Plugins::Pointer interface = - cpPlugins::Interface::Plugins::New( ); + typedef cpPlugins::Interface::Plugins TPlugins; + TPlugins::Pointer interface = TPlugins::New( ); try { interface->LoadEnvironments( ); diff --git a/appli/examples/plugins/LoadDirectory.cxx b/appli/examples/plugins/LoadDirectory.cxx index a51cef3..17930a3 100644 --- a/appli/examples/plugins/LoadDirectory.cxx +++ b/appli/examples/plugins/LoadDirectory.cxx @@ -13,8 +13,8 @@ int main( int argc, char* argv[] ) std::string directory = argv[ 1 ]; // Create interface and load library - cpPlugins::Interface::Plugins::Pointer interface = - cpPlugins::Interface::Plugins::New( ); + typedef cpPlugins::Interface::Plugins TPlugins; + TPlugins::Pointer interface = TPlugins::New( ); try { interface->LoadEnvironments( ); diff --git a/appli/examples/plugins/LoadFile.cxx b/appli/examples/plugins/LoadFile.cxx index c625e55..c433881 100644 --- a/appli/examples/plugins/LoadFile.cxx +++ b/appli/examples/plugins/LoadFile.cxx @@ -13,8 +13,8 @@ int main( int argc, char* argv[] ) std::string library_file = argv[ 1 ]; // Create interface and load library - cpPlugins::Interface::Plugins::Pointer interface = - cpPlugins::Interface::Plugins::New( ); + typedef cpPlugins::Interface::Plugins TPlugins; + TPlugins::Pointer interface = TPlugins::New( ); try { interface->LoadEnvironments( ); diff --git a/appli/examples/plugins/LoadPlugin.cxx b/appli/examples/plugins/LoadPlugin.cxx index 71c5502..3c007f1 100644 --- a/appli/examples/plugins/LoadPlugin.cxx +++ b/appli/examples/plugins/LoadPlugin.cxx @@ -13,8 +13,8 @@ int main( int argc, char* argv[] ) std::string plugin = argv[ 1 ]; // Create interface and load library - cpPlugins::Interface::Plugins::Pointer interface = - cpPlugins::Interface::Plugins::New( ); + typedef cpPlugins::Interface::Plugins TPlugins; + TPlugins::Pointer interface = TPlugins::New( ); try { interface->LoadEnvironments( ); diff --git a/cmake/DetectOS.cmake b/cmake/DetectOS.cmake deleted file mode 100644 index 6f8abc6..0000000 --- a/cmake/DetectOS.cmake +++ /dev/null @@ -1,23 +0,0 @@ -## ===================== -## == OS-based values == -## ===================== - -SET(prj_NAME_OS "${prj_NAME}_OS_${CMAKE_SYSTEM_NAME}") -IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - SET(prj_NAME_LIB_PREFIX "lib") - SET(prj_NAME_LIB_EXT ".so") - SET(prj_NAME_ENV_SEPARATOR ":") - SET(prj_NAME_PATH_SEPARATOR "/") -ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") - SET(prj_NAME_LIB_PREFIX "lib") - SET(prj_NAME_LIB_EXT ".dylib") - SET(prj_NAME_ENV_SEPARATOR ":") - SET(prj_NAME_PATH_SEPARATOR "/") -ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - SET(prj_NAME_LIB_PREFIX "") - SET(prj_NAME_LIB_EXT ".dll") - SET(prj_NAME_ENV_SEPARATOR ";") - SET(prj_NAME_PATH_SEPARATOR "\\\\\\\\") -ENDIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - -## eof - $RCSfile$ diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake index f5a90f3..d3d5500 100644 --- a/cmake/Functions.cmake +++ b/cmake/Functions.cmake @@ -61,6 +61,7 @@ ENDFUNCTION() FUNCTION( CreateLib lib_name + lib_dir lib_type lib_source_files lib_header_files @@ -94,7 +95,7 @@ ENDIF(Qt4_FOUND) ## -- Ok, compile library IF(_sources) NormPaths(_cur_binary_dir ${CMAKE_CURRENT_BINARY_DIR}) - ADD_LIBRARY(${lib_name} SHARED ${_sources} ${_headers}) + ADD_LIBRARY(${lib_name} ${lib_type} ${_sources} ${_headers}) SET_TARGET_PROPERTIES( ${lib_name} PROPERTIES @@ -117,6 +118,7 @@ ENDFUNCTION() FUNCTION( LibFromDir lib_name + lib_dir lib_type lib_source_dir lib_version @@ -200,7 +202,7 @@ ENDIF(ARGN) ## -- Create library CreateLib( - ${lib_name} ${lib_type} + ${lib_name} ${lib_dir} ${lib_type} "${_sources}" "${_headers}" "${_qt_uis}" "${lib_version}" "${lib_short_version}" ) @@ -211,6 +213,7 @@ ENDFUNCTION() FUNCTION( CompileInstances out_lib_name + lib_dir def_file number_of_files prefix @@ -251,7 +254,7 @@ ADD_CUSTOM_COMMAND( ## -- Create library CreateLib( - "${_lib_name}" SHARED + "${_lib_name}" ${lib_dir} SHARED "${_all_out_code}" "${_out_header}" "" "${version}" "${short_version}" ) @@ -311,7 +314,7 @@ ENDIF(_hdr_to_wrap) ## -- Ok, build library IF(_all_src) CreateLib( - ${_lib_name} SHARED + ${_lib_name} leo SHARED "${_all_src}" "${_all_hdr}" "${_qt_ui}" "${version}" "${short_version}" ${ARGN} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 06182ce..4caae27 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -9,12 +9,12 @@ SET(_ver "${prj_VERSION}" "${prj_SHORT_VERSION}") ## == Third party libraries == ## =========================== -LibFromDir(cpPlugins_tinyxml2 SHARED ${_dir}/tinyxml2 ${_ver}) +LibFromDir(cpPlugins_tinyxml2 ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/tinyxml2 ${_ver}) IF(Qt4_FOUND) - LibFromDir(cpPlugins_QCustomPlot SHARED ${_dir}/QCustomPlot ${_ver}) + LibFromDir(cpPlugins_QCustomPlot ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/QCustomPlot ${_ver}) TARGET_LINK_LIBRARIES(cpPlugins_QCustomPlot ${QT_LIBRARIES}) ENDIF(Qt4_FOUND) -LibFromDir(cpExtensions SHARED ${_dir}/cpExtensions ${_ver}) +LibFromDir(cpExtensions ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpExtensions ${_ver}) TARGET_LINK_LIBRARIES(cpExtensions ${ITK_LIBRARIES} ${VTK_LIBRARIES} ${QT_LIBRARIES}) ## ===================== @@ -34,7 +34,7 @@ ADD_CUSTOM_COMMAND( COMMAND ${cpPlugins_bash_BuildDemangleHeader_APP} "${_demangle_dir}/DemangleBase.h" DEPENDS ${cpPlugins_bash_BuildDemangleHeader_APP} ) -LibFromDir(cpPlugins SHARED ${_dir}/cpPlugins ${_ver} "${_demangle_dir}/DemangleBase.h") +LibFromDir(cpPlugins ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpPlugins ${_ver} ${_demangle_dir}/DemangleBase.h) TARGET_LINK_LIBRARIES(cpPlugins cpPlugins_tinyxml2 cpExtensions ${cpPlugins_Instances}) ## ====================== @@ -42,7 +42,7 @@ TARGET_LINK_LIBRARIES(cpPlugins cpPlugins_tinyxml2 cpExtensions ${cpPlugins_Inst ## ====================== IF(Qt4_FOUND) - LibFromDir(cpBaseQtApplication SHARED ${_dir}/cpBaseQtApplication ${_ver}) + LibFromDir(cpBaseQtApplication ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpBaseQtApplication ${_ver}) TARGET_LINK_LIBRARIES(cpBaseQtApplication ${cpPlugins_LIB}) ENDIF(Qt4_FOUND) @@ -50,21 +50,20 @@ ENDIF(Qt4_FOUND) ## == Libraries to dynamically load == ## =================================== -SET( - cpPlugins_DynLibs - local@cpExtensions - ) +SET(cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/bin|cpExtensions") +LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/lib|cpExtensions") +LIST(APPEND cpPlugins_DynLibs "${LIBRARY_OUTPUT_PATH}|cpExtensions") FOREACH(_lib ${cpPlugins_Instances}) - LIST(APPEND cpPlugins_DynLibs local@${_lib}) -ENDFOREACH(_lib) -FOREACH(_lib ${VTK_LIBRARIES}) - GET_TARGET_PROPERTY(_lib_${_lib} ${_lib} LOCATION) - LIST(APPEND cpPlugins_DynLibs global@${_lib_${_lib}}) -ENDFOREACH(_lib) -FOREACH(_lib ${ITK_LIBRARIES}) - GET_TARGET_PROPERTY(_lib_${_lib} ${_lib} LOCATION) - LIST(APPEND cpPlugins_DynLibs global@${_lib_${_lib}}) + LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/bin|${_lib}") + LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/lib|${_lib}") + LIST(APPEND cpPlugins_DynLibs "${LIBRARY_OUTPUT_PATH}|${_lib}") ENDFOREACH(_lib) +LIST(APPEND cpPlugins_DynLibs "${VTK_INSTALL_PREFIX}/bin|vtk*") +LIST(APPEND cpPlugins_DynLibs "${VTK_INSTALL_PREFIX}/lib|vtk*") +LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/bin|itk*") +LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/lib|itk*") +LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/bin|ITK*") +LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/lib|ITK*") FILE(WRITE ${PROJECT_BINARY_DIR}/cpPlugins_Libraries.config "") FOREACH(_lib ${cpPlugins_DynLibs}) FILE(APPEND ${PROJECT_BINARY_DIR}/cpPlugins_Libraries.config "${_lib}\n") diff --git a/lib/Instances/CMakeLists.txt b/lib/Instances/CMakeLists.txt index a32d683..bf7d665 100644 --- a/lib/Instances/CMakeLists.txt +++ b/lib/Instances/CMakeLists.txt @@ -7,6 +7,7 @@ SET(_all_instances) FOREACH(_instance ${_instances}) CompileInstances( _lib_name + ${PROJECT_BINARY_DIR}/lib ${_instance} ${cpPlugins_NUMBER_OF_FILES} "" "${prj_VERSION}" "${prj_SHORT_VERSION}" ) diff --git a/lib/cpBaseQtApplication/MainWindow.cxx b/lib/cpBaseQtApplication/MainWindow.cxx index 8e1abab..f8ac71a 100644 --- a/lib/cpBaseQtApplication/MainWindow.cxx +++ b/lib/cpBaseQtApplication/MainWindow.cxx @@ -70,9 +70,9 @@ MainWindow( int argc, char* argv[], QApplication* app, QWidget* parent ) // Get the plugins interface this->m_Plugins = TPlugins::New( ); - try { this->m_Plugins->OpenEnvironments( env.str( ) ); } catch( ... ) { } - try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { } + try { this->m_Plugins->AddEnvironments( env.str( ) ); } catch( ... ) { } this->updateEnvironment( ); + try { this->m_Plugins->SavePaths( this->m_RunPath ); } catch( ... ) { } // Create local workspace this->m_Workspace = TWorkspace::New( ); @@ -347,7 +347,7 @@ void cpBaseQtApplication::MainWindow:: _addEnvironmentPaths( const std::string& envs ) { try { this->m_Plugins->AddEnvironments( envs ); } catch( ... ) { } - try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { } + try { this->m_Plugins->SavePaths( this->m_RunPath ); } catch( ... ) { } this->updateEnvironment( ); this->_updatePlugins( ); } diff --git a/lib/cpExtensions/Config.h.in b/lib/cpExtensions/Config.h.in index 075c7eb..23c93da 100644 --- a/lib/cpExtensions/Config.h.in +++ b/lib/cpExtensions/Config.h.in @@ -8,20 +8,31 @@ * Identify OS * ========================================================================= */ -#define @prj_NAME_OS@ -#define cpExtensions_LIB_PREFIX "@prj_NAME_LIB_PREFIX@" -#define cpExtensions_LIB_EXT "@prj_NAME_LIB_EXT@" -#define cpExtensions_ENV_SEPARATOR "@prj_NAME_ENV_SEPARATOR@" -#define cpExtensions_PATH_SEPARATOR '@prj_NAME_PATH_SEPARATOR@' +#define cpExtensions_OS_@CMAKE_SYSTEM_NAME@ +#ifdef cpExtensions_OS_Windows +# define cpExtensions_LIB_PREFIX "" +# define cpExtensions_ENV_SEPARATOR ";" +# define cpExtensions_PATH_SEPARATOR '\\' +# define cpExtensions_LIB_EXT ".dll" +#else // cpExtensions_OS_Windows +# define cpExtensions_LIB_PREFIX "lib" +# define cpExtensions_ENV_SEPARATOR ":" +# define cpExtensions_PATH_SEPARATOR '/' +# ifdef cpExtensions_OS_Linux +# define cpExtensions_LIB_EXT ".so" +# else // cpExtensions_OS_Linux +# define cpExtensions_LIB_EXT ".dylib" +# endif // cpExtensions_OS_Linux +#endif // cpExtensions_OS_Windows -#ifdef cpPlugins_OS_Windows +#ifdef cpExtensions_OS_Windows # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN -# endif +# endif // WIN32_LEAN_AND_MEAN # define NOMINMAX # include # include -#endif +#endif // cpExtensions_OS_Windows /* * ========================================================================= diff --git a/lib/cpExtensions/Utility.h b/lib/cpExtensions/Utility.h index 065dadf..2867786 100644 --- a/lib/cpExtensions/Utility.h +++ b/lib/cpExtensions/Utility.h @@ -8,13 +8,13 @@ #include // ------------------------------------------------------------------------- -#ifdef cpPlugins_OS_Windows +#ifdef cpExtensions_OS_Windows # define cpExtensions_STRTOK( A, B, N ) strtok_s( A, B, N ) # define cpExtensions_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O ); -#else // cpPlugins_OS_Windows +#else // cpExtensions_OS_Windows # define cpExtensions_STRTOK( A, B, N ) std::strtok( A, B ) # define cpExtensions_SPRINTF( B, S, O ) std::sprintf( B, "%s", O ); -#endif // cpPlugins_OS_Windows +#endif // cpExtensions_OS_Windows // ------------------------------------------------------------------------- #define cpExtensions_CHRONO \ @@ -28,11 +28,11 @@ namespace cpExtensions // ----------------------------------------------------------------------- inline bool IsPathSeparator( char c ) { -#ifdef cpPlugins_Windows - return( c == '\\' || c == cpExtensions_PATH_SEPARATOR ); -#else // cpPlugins_Windows +#ifdef cpExtensions_OS_Windows + return( c == '/' || c == cpExtensions_PATH_SEPARATOR ); +#else // cpExtensions_OS_Windows return( c == cpExtensions_PATH_SEPARATOR ); -#endif // cpPlugins_Windows +#endif // cpExtensions_OS_Windows } // ----------------------------------------------------------------------- @@ -112,12 +112,12 @@ namespace cpExtensions inline std::string CanonicalPath( const std::string& path ) { std::string ret = ""; -#ifdef cpPlugins_OS_Windows +#ifdef cpExtensions_OS_Windows TCHAR buffer[ 4096 ] = TEXT( "" ); TCHAR** lppPart = { NULL }; GetFullPathName( path.c_str( ), 4096, buffer, lppPart ); ret = std::string( buffer ); -#else // cpPlugins_OS_Windows +#else // cpExtensions_OS_Windows char* canonical_path = realpath( path.c_str( ), NULL ); if( canonical_path != NULL ) { @@ -125,7 +125,7 @@ namespace cpExtensions free( canonical_path ); } // fi -#endif // cpPlugins_OS_Windows +#endif // cpExtensions_OS_Windows return( ret ); } diff --git a/lib/cpPlugins/Config.h.in b/lib/cpPlugins/Config.h.in index 1c0f106..a57be19 100644 --- a/lib/cpPlugins/Config.h.in +++ b/lib/cpPlugins/Config.h.in @@ -1,5 +1,5 @@ -#ifndef __@prj_NAME@__h__ -#define __@prj_NAME@__h__ +#ifndef __@prj_NAME@__Config__h__ +#define __@prj_NAME@__Config__h__ #define ITK_MANUAL_INSTANTIATION #include <@prj_NAME@_Export.h> @@ -10,16 +10,27 @@ * Identify OS * ========================================================================= */ -#define @prj_NAME_OS@ -#define @prj_NAME@_LIB_PREFIX "@prj_NAME_LIB_PREFIX@" -#define @prj_NAME@_LIB_EXT "@prj_NAME_LIB_EXT@" -#define @prj_NAME@_ENV_SEPARATOR "@prj_NAME_ENV_SEPARATOR@" -#define @prj_NAME@_PATH_SEPARATOR "@prj_NAME_PATH_SEPARATOR@" +#define @prj_NAME@_OS_@CMAKE_SYSTEM_NAME@ +#ifdef @prj_NAME@_OS_Windows +# define @prj_NAME@_LIB_PREFIX "" +# define @prj_NAME@_ENV_SEPARATOR ";" +# define @prj_NAME@_PATH_SEPARATOR '\\' +# define @prj_NAME@_LIB_EXT ".dll" +#else // @prj_NAME@_OS_Windows +# define @prj_NAME@_LIB_PREFIX "lib" +# define @prj_NAME@_ENV_SEPARATOR ":" +# define @prj_NAME@_PATH_SEPARATOR '/' +# ifdef @prj_NAME@_OS_Linux +# define @prj_NAME@_LIB_EXT ".so" +# else // @prj_NAME@_OS_Linux +# define @prj_NAME@_LIB_EXT ".dylib" +# endif // @prj_NAME@_OS_Linux +#endif // @prj_NAME@_OS_Windows #ifdef @prj_NAME@_OS_Windows # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN -# endif +# endif // WIN32_LEAN_AND_MEAN # define NOMINMAX # include # include @@ -118,6 +129,6 @@ return( dynamic_cast< const Self* >( other ) != NULL ); \ } -#endif // __@prj_NAME@__h__ +#endif // __@prj_NAME@__Config__h__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 42ab2cc..260172e 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -2,6 +2,7 @@ #include #include #include +#include // ------------------------------------------------------------------------- cpPlugins::Interface::Plugins:: @@ -82,55 +83,78 @@ GetFilters( const std::string& category ) const // ------------------------------------------------------------------------- void cpPlugins::Interface::Plugins:: -AddEnvironments( const std::string& new_environment ) +AddEnvironments( const std::string& env ) { - std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, new_environment, cpPlugins_ENV_SEPARATOR ); - for( auto i = tokens.begin( ); i != tokens.end( ); ++i ) - { - std::stringstream dir; - dir << cpExtensions::CanonicalPath( *i ); - if( dir.str( ) != "" ) - this->m_Paths.insert( dir.str( ) ); - - } // rof + std::vector< std::string > directories; + cpExtensions::Tokenize( directories, env, cpPlugins_ENV_SEPARATOR ); + for( auto dir = directories.begin( ); dir != directories.end( ); ++dir ) + this->m_Paths.insert( cpExtensions::CanonicalPath( *dir ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Plugins:: LoadEnvironments( ) { - std::stringstream all_errors; + std::set< std::string > libs; for( auto d = this->m_Paths.begin( ); d != this->m_Paths.end( ); ++d ) { - std::stringstream name; - name << *d << cpPlugins_CONFIG; + std::stringstream fname; + fname << *d << cpPlugins_PATH_SEPARATOR << cpPlugins_CONFIG; std::string buffer; - if( cpExtensions::Read( buffer, name.str( ) ) ) + if( cpExtensions::Read( buffer, fname.str( ) ) ) { std::istringstream input( buffer ); for( std::string line; std::getline( input, line ); ) { std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, line, "@" ); - std::string library_file = ""; - if( tokens[ 0 ] == "local" ) - library_file = - cpExtensions::CanonicalPath( - *d + std::string( cpPlugins_LIB_PREFIX ) + - tokens[ 1 ] + std::string( cpPlugins_LIB_EXT ) - ); - else if( tokens[ 0 ] == "global" ) - library_file = tokens[ 1 ]; - - if( library_file != "" ) + cpExtensions::Tokenize( tokens, line, "|" ); + if( tokens.size( ) == 2 ) { - std::string error = ""; - void* hnd = cpPlugins::OS::DLLManager::Load( library_file, error ); - if( hnd != NULL ) - this->m_Libraries[ library_file ] = hnd; + std::string pth = tokens[ 0 ]; + std::string lib = tokens[ 1 ]; + if( lib.find( "*" ) != std::string::npos ) + { + std::string ext( cpPlugins_LIB_EXT ); + DIR* dir; + struct dirent* ent; + if( ( dir = opendir( pth.c_str( ) ) ) != NULL ) + { + while( ( ent = readdir( dir ) ) != NULL ) + { + std::string fname( ent->d_name ); + long pos = long( fname.size( ) ) - long( ext.size( ) ); + if( pos > 0 ) + { + if( fname.substr( pos ) == ext ) + { + std::regex re( lib ); +std::smatch match; +if( std::regex_search( fname, match, re ) && match.size( ) >= 1 ) + { + std::stringstream str; + str + << pth << cpPlugins_PATH_SEPARATOR << fname; + libs.insert( str.str( ) ); + } // fi + + } // fi + + } // fi + + } // elihw + closedir( dir ); + + } // fi + } else - all_errors << " ; " << error; + { + std::stringstream str; + str + << pth << cpPlugins_PATH_SEPARATOR << cpPlugins_LIB_PREFIX + << lib << cpPlugins_LIB_EXT; + libs.insert( str.str( ) ); + + } // fi } // fi @@ -139,72 +163,61 @@ LoadEnvironments( ) } // fi } // rof + for( auto l = libs.begin( ); l != libs.end( ); ++l ) + { + std::string lib = cpExtensions::CanonicalPath( *l ); + if( lib != "" ) + { + if( this->m_Libraries.find( lib ) == this->m_Libraries.end( ) ) +{ + std::string error = ""; + void* hnd = cpPlugins::OS::DLLManager::Load( lib, error ); + if( hnd != NULL ) + this->m_Libraries[ lib ] = hnd; - // Throw errors - if( all_errors.str( ) != "" ) - throw std::runtime_error( - std::string( "Loading environment libraries errors: " ) + - all_errors.str( ) - ); +} // fi + + } // fi + + } // rof } // ------------------------------------------------------------------------- void cpPlugins::Interface::Plugins:: -SaveEnvironments( const std::string& dir ) const +LoadPaths( const std::string& dir ) { - std::stringstream buffer; - for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i ) - buffer << *i << std::endl; - - std::stringstream fname; + std::stringstream fname, envs; fname << dir; if( !cpExtensions::IsPathSeparator( dir.back( ) ) ) fname << cpExtensions_PATH_SEPARATOR; fname << cpPlugins_PATHS; - if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) ) - throw std::runtime_error( "Error writing environment file." ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::Plugins:: -OpenEnvironments( const std::string& dir ) -{ - std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, dir, cpPlugins_ENV_SEPARATOR ); - for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt ) - { - std::stringstream fname; - fname << *tIt; - if( !cpExtensions::IsPathSeparator( dir.back( ) ) ) - fname << cpExtensions_PATH_SEPARATOR; - fname << cpPlugins_PATHS; std::string buffer; if( cpExtensions::Read( buffer, fname.str( ) ) ) { std::istringstream input( buffer ); - std::stringstream paths; for( std::string line; std::getline( input, line ); ) - paths << line << cpPlugins_ENV_SEPARATOR; - this->AddEnvironments( paths.str( ) ); - } - else - { - bool success = true; - try - { - this->LoadDirectory( dir ); - } - catch( ... ) - { - success = false; - - } // yrt - if( success ) - this->AddEnvironments( dir ); + envs << line << cpPlugins_ENV_SEPARATOR; } // fi + if( envs.str( ).size( ) > 0 ) + this->AddEnvironments( envs.str( ) ); +} - } // rof +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +SavePaths( const std::string& dir ) const +{ + std::stringstream buffer; + for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i ) + buffer << *i << std::endl; + + std::stringstream fname; + fname << dir; + if( !cpExtensions::IsPathSeparator( dir.back( ) ) ) + fname << cpExtensions_PATH_SEPARATOR; + fname << cpPlugins_PATHS; + if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) ) + throw std::runtime_error( "Error writing environment file." ); } // ------------------------------------------------------------------------- @@ -435,22 +448,7 @@ Plugins( ) if( p != NULL ) str << p << cpPlugins_ENV_SEPARATOR; str << "."; - this->OpenEnvironments( str.str( ) ); - - // Try to read locally defined paths - /* TODO - std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR ); - for( auto t = tokens.begin( ); t != tokens.end( ); ++t ) - { - try - { - this->OpenEnvironments( *t ); - } - catch( ... ) { } - - } // rof - */ + this->AddEnvironments( str.str( ) ); } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/Plugins.h b/lib/cpPlugins/Interface/Plugins.h index 7b5d9be..6ce6344 100644 --- a/lib/cpPlugins/Interface/Plugins.h +++ b/lib/cpPlugins/Interface/Plugins.h @@ -48,10 +48,10 @@ namespace cpPlugins TStrings GetCategories( ) const; TStrings GetFilters( const std::string& category ) const; - void AddEnvironments( const std::string& new_environment ); + void AddEnvironments( const std::string& env ); void LoadEnvironments( ); - void SaveEnvironments( const std::string& dir ) const; - void OpenEnvironments( const std::string& dir ); + void LoadPaths( const std::string& dir ); + void SavePaths( const std::string& dir ) const; void LoadFile( const std::string& fname ); void LoadPlugin( const std::string& pname ); diff --git a/lib/cpPlugins/OS/DLLManager.cxx b/lib/cpPlugins/OS/DLLManager.cxx index ab3cf56..727ba18 100644 --- a/lib/cpPlugins/OS/DLLManager.cxx +++ b/lib/cpPlugins/OS/DLLManager.cxx @@ -12,7 +12,12 @@ Load( const std::string& fname, std::string& error ) { void* hnd = NULL; #ifdef cpPlugins_OS_Windows + UINT old = ::SetErrorMode( SEM_FAILCRITICALERRORS ); + ::SetErrorMode( old | SEM_FAILCRITICALERRORS ); hnd = ::LoadLibraryA( fname.c_str( ) ); + ::SetErrorMode( old ); + if( hnd == NULL ) + error = "Could not load library."; #else // cpPlugins_OS_Windows hnd = dlopen( fname.c_str( ), RTLD_LAZY | RTLD_GLOBAL ); if( hnd == NULL ) diff --git a/plugins/ImageMeshFilters/RasterMeshFilter.cxx b/plugins/ImageMeshFilters/RasterMeshFilter.cxx index 8452f2d..e9faaa7 100644 --- a/plugins/ImageMeshFilters/RasterMeshFilter.cxx +++ b/plugins/ImageMeshFilters/RasterMeshFilter.cxx @@ -83,7 +83,7 @@ _GD0_2D( _TMesh* mesh ) auto filter = this->_CreateITK< _TFilter >( ); filter->ClearPoints( ); double pnt[ 3 ]; - for( unsigned long i = 0; i < mesh->GetNumberOfPoints( ); ++i ) + for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i ) { mesh->GetPoint( i, pnt ); filter->AddPoint( pnt[ 0 ], pnt[ 1 ] );