]> Creatis software - cpPlugins.git/commitdiff
Windows compilation 3/3
authorLeonardo Florez Valencia <florez-l@javeriana.edu.co>
Sun, 9 Oct 2016 20:51:16 +0000 (15:51 -0500)
committerLeonardo Florez Valencia <florez-l@javeriana.edu.co>
Sun, 9 Oct 2016 20:51:16 +0000 (15:51 -0500)
18 files changed:
CMakeLists.txt
appli/bash/Utility.h.in
appli/examples/plugins/GuessPlugins.cxx
appli/examples/plugins/LoadDirectory.cxx
appli/examples/plugins/LoadFile.cxx
appli/examples/plugins/LoadPlugin.cxx
cmake/DetectOS.cmake [deleted file]
cmake/Functions.cmake
lib/CMakeLists.txt
lib/Instances/CMakeLists.txt
lib/cpBaseQtApplication/MainWindow.cxx
lib/cpExtensions/Config.h.in
lib/cpExtensions/Utility.h
lib/cpPlugins/Config.h.in
lib/cpPlugins/Interface/Plugins.cxx
lib/cpPlugins/Interface/Plugins.h
lib/cpPlugins/OS/DLLManager.cxx
plugins/ImageMeshFilters/RasterMeshFilter.cxx

index 8fb53f6c4ee6fed45b598d5d650dcba9ceca975c..82cc483b450d28c8d0aadc64ea7dc611fb3b86b1 100644 (file)
@@ -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)
index 95c8be0f97292d329922b9bc7b76d6b39f93df04..7dda46f53caf64db1d9591bbc007f0d4cf77ab33 100644 (file)
@@ -6,14 +6,14 @@
 #include <string>
 
 // -------------------------------------------------------------------------
-#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;
index cf18784667a966cc737f4ce6fde371bd00b3a504..6704b9b400189c3fcb4291c4aa976f5fc8d208a5 100644 (file)
@@ -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( );
index a51cef3038f1c0c215689795efe748609b81af36..17930a397581632c648777c43e32ed9250ca43aa 100644 (file)
@@ -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( );
index c625e55b927a2952290d781a9b390b6d7c6903dc..c4338813984f47e54eb1c3dbc6ca8da7bce46f6d 100644 (file)
@@ -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( );
index 71c550285670d15ecc54d357120c259c1ac85d1d..3c007f113835d46bc75f423b350d136041e7ca2c 100644 (file)
@@ -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 (file)
index 6f8abc6..0000000
+++ /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$
index f5a90f3326c0895761db6d84473d604961df8631..d3d5500f28b3d806d214f9f0e54236a4cf67bfcf 100644 (file)
@@ -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}
index 06182ced53e7e48bdcda074845aedfd3139d7b13..4caae27003d6959d58e79016c4bc7201a627748d 100644 (file)
@@ -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")
index a32d683216358fdfc48805cfea27a474645d4733..bf7d66505243d96188cc31d2d63d7e77d90b9ede 100644 (file)
@@ -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}"
     )
index 8e1abab90018474c27aec881ea7ae4888c7018b3..f8ac71ad118762a584da6459736ac0587d0a94db 100644 (file)
@@ -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( );
 }
index 075c7eb650c3e83d2934be6586b0d0d63770bb08..23c93da087c923e6983ecf934fecf3f27dd8dcff 100644 (file)
@@ -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 <windows.h>
 #  include <tchar.h>
-#endif
+#endif // cpExtensions_OS_Windows
 
 /*
  * =========================================================================
index 065dadf92fbee7f63f48b6cc2ff11f6180f0d572..28677864b915423b9e43931556b56780eae9b817 100644 (file)
@@ -8,13 +8,13 @@
 #include <cpExtensions/Config.h>
 
 // -------------------------------------------------------------------------
-#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 );
   }
 
index 1c0f1066d1a4716fa70ad353ac2e8cf14909175c..a57be19f860d4467931360056654d86d9920973f 100644 (file)
@@ -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>
  * 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 <windows.h>
 #  include <tchar.h>
   return( dynamic_cast< const Self* >( other ) != NULL );               \
   }
 
-#endif // __@prj_NAME@__h__
+#endif // __@prj_NAME@__Config__h__
 
 // eof - $RCSfile$
index 42ab2cc77ded0fd88249a1c6a8bf9f6b8b1b70d5..260172e467c41e1b0d93ca5a1d0d6d419189aaa7 100644 (file)
@@ -2,6 +2,7 @@
 #include <cpPlugins/OS/DLLManager.h>
 #include <cpPlugins/Interface/Dirent.h>
 #include <cpExtensions/Utility.h>
+#include <regex>
 
 // -------------------------------------------------------------------------
 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( ) );
 }
 
 // -------------------------------------------------------------------------
index 7b5d9beb72d5db028b6978e763b6d0f2ca6df104..6ce634424f25231679ab3885f7e1db244b9de91a 100644 (file)
@@ -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 );
index ab3cf56d2e742f67b51a186b3eba612d3f932651..727ba18786d834a81acf0e4e941e051ada1204ca 100644 (file)
@@ -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 )
index 8452f2d6568847c0ba6643cadbccfa4115917755..e9faaa741dbac93e47a4de26a44132d581380cce 100644 (file)
@@ -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 ] );