← Back to team overview

kicad-developers team mailing list archive

PATCH: (and update) non-ASCII characters in path names on MinGW

 

I'm confident that I can now fix all remaining non-ASCII
filename issues in KiCad *and* use the correct initialization
macro in kicad2step (wxIMPLEMENT_APP_CONSOLE).

This will require some coordination in order to avoid
breaking the automatic build for Windows.

Step A: Implement the patch attached to fix the wxWidgets
header 'wx/app.h'.

Step B: Push the *_C patch to fix UTF8 problems in kicad2step
and ensure that kicad2step and idf2vrml build with the already
patched wx header. Ignore previous related patches; this _C
patch has them all.

Once that is done, all the major filename problems in MinGW
will be fixed and I will continue to fix up the IDF tools which
seem to be rarely used but do contain UTF8 problems.

- Cirilo
diff --git a/include/wx/app.h b/include/wx/app.h
index 9a73469570..ed37dcf38d 100644
--- a/include/wx/app.h
+++ b/include/wx/app.h
@@ -790,7 +790,7 @@ public:
 // For compilers that support it, prefer to use wmain() as this ensures any
 // Unicode strings can be passed as command line parameters and not just those
 // representable in the current locale.
-#if wxUSE_UNICODE && defined(__VISUALC__)
+#if wxUSE_UNICODE && ( defined(__VISUALC__) || defined(__MINGW32__) || defined(__MINGW64__) )
     #define wxIMPLEMENT_WXWIN_MAIN_CONSOLE                                    \
         int wmain(int argc, wchar_t **argv)                                   \
         {                                                                     \
From 4826a2a82ae5c947541ff4d775d45ccb6023b4fb Mon Sep 17 00:00:00 2001
From: Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
Date: Sun, 5 Mar 2017 15:22:31 +1100
Subject: [PATCH 1/3] Fix kicad2step non-ASCII filename characters issue in
 Windows+MinGW

---
 utils/kicad2step/CMakeLists.txt      | 13 ++++++++++---
 utils/kicad2step/pcb/kicadmodule.cpp |  3 ++-
 utils/kicad2step/pcb/oce_utils.cpp   | 10 +++++-----
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/utils/kicad2step/CMakeLists.txt b/utils/kicad2step/CMakeLists.txt
index bdfff3390..a60153f42 100644
--- a/utils/kicad2step/CMakeLists.txt
+++ b/utils/kicad2step/CMakeLists.txt
@@ -1,13 +1,14 @@
 include_directories( BEFORE
-        pcb
-        ${CMAKE_CURRENT_SOURCE_DIR}
+    pcb
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_SOURCE_DIR}/include
 )
 
 include_directories( SYSTEM 
     ${OCE_INCLUDE_DIRS}
 )
 
-add_executable( kicad2step
+set( K2S_FILES
     kicad2step.cpp
     pcb/3d_resolver.cpp
     pcb/base.cpp
@@ -21,6 +22,12 @@ add_executable( kicad2step
     sexpr/sexpr_parser.cpp
 )
 
+if( MINGW )
+    list( APPEND K2S_FILES ${CMAKE_SOURCE_DIR}/common/streamwrapper.cpp )
+endif( MINGW )
+
+add_executable( kicad2step ${K2S_FILES} )
+
 target_link_libraries( kicad2step ${wxWidgets_LIBRARIES} ${LIBS_OCE} )
 
 if( APPLE )
diff --git a/utils/kicad2step/pcb/kicadmodule.cpp b/utils/kicad2step/pcb/kicadmodule.cpp
index 532b02c9c..03ffff415 100644
--- a/utils/kicad2step/pcb/kicadmodule.cpp
+++ b/utils/kicad2step/pcb/kicadmodule.cpp
@@ -360,7 +360,8 @@ bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver,
 
     for( auto i : m_models )
     {
-        std::string fname( resolver->ResolvePath( i->m_modelname.c_str() ).ToUTF8() );
+        std::string fname( resolver->ResolvePath(
+            wxString::FromUTF8Unchecked( i->m_modelname.c_str() ) ).ToUTF8() );
 
         if( aPCB->AddComponent( fname, m_refdes, LAYER_BOTTOM == m_side ? true : false,
             newpos, m_rotation, i->m_offset, i->m_rotation ) )
diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp
index 8fa45cb04..cce6d1fd2 100644
--- a/utils/kicad2step/pcb/oce_utils.cpp
+++ b/utils/kicad2step/pcb/oce_utils.cpp
@@ -31,6 +31,7 @@
 
 #include "oce_utils.h"
 #include "kicadpad.h"
+#include "streamwrapper.h"
 
 #include <IGESCAFControl_Reader.hxx>
 #include <IGESCAFControl_Writer.hxx>
@@ -153,7 +154,7 @@ enum FormatType
 
 FormatType fileType( const char* aFileName )
 {
-    wxFileName lfile( aFileName );
+    wxFileName lfile( wxString::FromUTF8Unchecked( aFileName ) );
 
     if( !lfile.FileExists() )
     {
@@ -172,16 +173,15 @@ FormatType fileType( const char* aFileName )
     else if( ext == "emn" || ext == "EMN" )
         return FMT_EMN;     // PCB assembly
 
-    std::ifstream ifile;
-    ifile.open( aFileName );
+    OPEN_ISTREAM( ifile, aFileName );
 
-    if( !ifile.is_open() )
+    if( ifile.fail() )
         return FMT_NONE;
 
     char iline[82];
     memset( iline, 0, 82 );
     ifile.getline( iline, 82 );
-    ifile.close();
+    CLOSE_STREAM( ifile );
     iline[81] = 0;  // ensure NULL termination when string is too long
 
     // check for STEP in Part 21 format
-- 
2.11.0


From 79ec96c0bc411b6970f842543344fc634f155187 Mon Sep 17 00:00:00 2001
From: Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
Date: Tue, 7 Mar 2017 14:52:17 +1100
Subject: [PATCH 2/3] Fix character mangling on kicad2step command line

---
 utils/kicad2step/kicad2step.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp
index e70caece1..d6c105d3f 100644
--- a/utils/kicad2step/kicad2step.cpp
+++ b/utils/kicad2step/kicad2step.cpp
@@ -84,7 +84,7 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
     };
 
 
-wxIMPLEMENT_APP_CONSOLE( KICAD2MCAD );
+wxIMPLEMENT_APP( KICAD2MCAD );
 
 
 bool KICAD2MCAD::OnInit()
-- 
2.11.0


From eebb70b165497dc25897e5603e64606f08a19e6a Mon Sep 17 00:00:00 2001
From: Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
Date: Thu, 9 Mar 2017 00:27:18 +1100
Subject: [PATCH 3/3] Fix kicad2step and idf2vrml to compile in MinGW with
 patched wx/app.h

---
 utils/idftools/CMakeLists.txt   | 4 ++++
 utils/kicad2step/CMakeLists.txt | 4 ++++
 utils/kicad2step/kicad2step.cpp | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/utils/idftools/CMakeLists.txt b/utils/idftools/CMakeLists.txt
index 2982d48c3..71c2f66ee 100644
--- a/utils/idftools/CMakeLists.txt
+++ b/utils/idftools/CMakeLists.txt
@@ -31,6 +31,10 @@ add_executable( idf2vrml idf2vrml.cpp )
 
 target_link_libraries( dxf2idf lib_dxf idf3 ${wxWidgets_LIBRARIES} )
 
+if( MINGW )
+    set_target_properties( idf2vrml PROPERTIES LINK_FLAGS "${LINK_FLAGS} -municode" )
+endif( MINGW )
+
 target_link_libraries( idf2vrml idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
 
 if( APPLE )
diff --git a/utils/kicad2step/CMakeLists.txt b/utils/kicad2step/CMakeLists.txt
index a60153f42..db693ff20 100644
--- a/utils/kicad2step/CMakeLists.txt
+++ b/utils/kicad2step/CMakeLists.txt
@@ -28,6 +28,10 @@ endif( MINGW )
 
 add_executable( kicad2step ${K2S_FILES} )
 
+if( MINGW )
+    set_target_properties( kicad2step PROPERTIES LINK_FLAGS "${LINK_FLAGS} -municode" )
+endif( MINGW )
+
 target_link_libraries( kicad2step ${wxWidgets_LIBRARIES} ${LIBS_OCE} )
 
 if( APPLE )
diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp
index d6c105d3f..e70caece1 100644
--- a/utils/kicad2step/kicad2step.cpp
+++ b/utils/kicad2step/kicad2step.cpp
@@ -84,7 +84,7 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
     };
 
 
-wxIMPLEMENT_APP( KICAD2MCAD );
+wxIMPLEMENT_APP_CONSOLE( KICAD2MCAD );
 
 
 bool KICAD2MCAD::OnInit()
-- 
2.11.0


Follow ups