diff --git a/common/kiway.cpp b/common/kiway.cpp index dd9185da13..0b2cf3b041 100644 --- a/common/kiway.cpp +++ b/common/kiway.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -199,6 +200,19 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) { wxString dname = dso_search_path( aFaceId ); + // Insert DLL search path for kicad_3dsg from build dir + if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) + { + wxFileName myPath = wxStandardPaths::Get().GetExecutablePath(); + + if( !myPath.GetPath().EndsWith( wxT( "pcbnew" ) ) ) + { + myPath.RemoveLastDir(); + myPath.AppendDir( wxT( "pcbnew" ) ); + KIPLATFORM::APP::AddDynamicLibrarySearchPath( myPath.GetPath() ); + } + } + wxDynamicLibrary dso; void* addr = NULL; diff --git a/libs/kiplatform/gtk/app.cpp b/libs/kiplatform/gtk/app.cpp index b51d88e26b..870a8c5cf2 100644 --- a/libs/kiplatform/gtk/app.cpp +++ b/libs/kiplatform/gtk/app.cpp @@ -102,3 +102,8 @@ void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() { } + + +void KIPLATFORM::APP::AddDynamicLibrarySearchPath( const wxString& aPath ) +{ +} diff --git a/libs/kiplatform/include/kiplatform/app.h b/libs/kiplatform/include/kiplatform/app.h index 315ac78424..6898fa69d8 100644 --- a/libs/kiplatform/include/kiplatform/app.h +++ b/libs/kiplatform/include/kiplatform/app.h @@ -82,6 +82,15 @@ namespace KIPLATFORM * Call as needed in an application to ensure timers are dispatched */ void ForceTimerMessagesToBeCreatedIfNecessary(); + + /** + * Inserts a search path for loading dynamic libraries. The exact place this new path ends + * up in the dynamic library search order is platform-dependent, but generally this can be + * used to make sure dynamic libraries are found in non-standard runtime situations. + * + * @param aPath is the full path to insert + */ + void AddDynamicLibrarySearchPath( const wxString& aPath ); } } diff --git a/libs/kiplatform/msw/app.cpp b/libs/kiplatform/msw/app.cpp index c4251a1028..d10b566d22 100644 --- a/libs/kiplatform/msw/app.cpp +++ b/libs/kiplatform/msw/app.cpp @@ -111,3 +111,9 @@ void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() MSG msg; PeekMessage( &msg, nullptr, WM_TIMER, WM_TIMER, PM_NOREMOVE ); } + + +void KIPLATFORM::APP::AddDynamicLibrarySearchPath( const wxString& aPath ) +{ + SetDllDirectoryA( aPath.c_str() ); +} diff --git a/libs/kiplatform/osx/app.mm b/libs/kiplatform/osx/app.mm index 2641f0f06b..27b78b9cc6 100644 --- a/libs/kiplatform/osx/app.mm +++ b/libs/kiplatform/osx/app.mm @@ -63,3 +63,8 @@ void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary() { } + + +void KIPLATFORM::APP::AddDynamicLibrarySearchPath( const wxString& aPath ) +{ +}