Skip to content

Commit

Permalink
Add wxStandardPaths::GetSharedLibrariesDir()
Browse files Browse the repository at this point in the history
This function returns the directory with the application's shared
libraries, which is different from the plugins directory under Mac.

Closes #24052.
  • Loading branch information
oneeyeman1 authored and vadz committed Jan 28, 2024
1 parent f82ccc1 commit 91de986
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/wx/msw/stdpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
virtual wxString GetUserDataDir() const override;
virtual wxString GetUserLocalDataDir() const override;
virtual wxString GetPluginsDir() const override;
virtual wxString GetSharedLibrariesDir() const override;
virtual wxString GetUserDir(Dir userDir) const override;
virtual wxString MakeConfigFileName(const wxString& basename,
ConfigFileConv conv = ConfigFileConv_Ext
Expand Down
1 change: 1 addition & 0 deletions include/wx/osx/cocoa/stdpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
virtual wxString GetLocalDataDir() const override;
virtual wxString GetUserDataDir() const override;
virtual wxString GetPluginsDir() const override;
virtual wxString GetSharedLibrariesDir() const override;
virtual wxString GetResourcesDir() const override;
virtual wxString
GetLocalizedResourcesDir(const wxString& lang,
Expand Down
4 changes: 4 additions & 0 deletions include/wx/stdpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class WXDLLIMPEXP_BASE wxStandardPathsBase
// Contents/Plugins app bundle subdirectory under Mac
virtual wxString GetPluginsDir() const = 0;

// return the directory where the shared libraries live
virtual wxString GetSharedLibrariesDir() const;

// get resources directory: resources are auxiliary files used by the
// application and include things like image and sound files
//
Expand Down Expand Up @@ -252,6 +255,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
virtual wxString GetLocalDataDir() const { return m_prefix; }
virtual wxString GetUserDataDir() const { return m_prefix; }
virtual wxString GetPluginsDir() const { return m_prefix; }
virtual wxString GetSharedLibrariesDir() const override { return m_prefix; }
virtual wxString GetUserDir(Dir WXUNUSED(userDir)) const { return m_prefix; }
virtual wxString
MakeConfigFileName(const wxString& basename,
Expand Down
1 change: 1 addition & 0 deletions include/wx/unix/stdpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
virtual wxString GetPluginsDir() const override;
virtual wxString GetLocalizedResourcesDir(const wxString& lang,
ResourceCat category) const override;
virtual wxString GetSharedLibrariesDir() const override;
#ifndef __VMS
virtual wxString GetUserDir(Dir userDir) const override;
#endif
Expand Down
18 changes: 17 additions & 1 deletion interface/wx/stdpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class wxStandardPaths
/**
Return the program installation prefix, e.g.\ @c /usr, @c /opt or @c /home/zeitlin.
If the prefix had been previously by SetInstallPrefix(), returns that
If the prefix had been previously set by SetInstallPrefix(), returns that
value, otherwise tries to determine it automatically (Linux only right now)
and finally returns the default @c /usr/local value if it failed.
Expand Down Expand Up @@ -441,6 +441,22 @@ class wxStandardPaths
*/
virtual wxString GetUserLocalDataDir() const;

/**
Return OS specific directory where project shared liraries are.
The function does the same thing as GetPluginsDir() under non-Mac platforms
but differs from it under Mac, where plugins (shared libraries loaded by the
application dynamically while it's running) and shared libraries (that the
application is statically linked with) are stored in different directories.
- Windows: returns the folder where the application binary is located
- Unix: returns the libraries installation path, i.e. /usr/lib
- Mac: returns `Contents/Frameworks` bundle subdirectory
@since 3.3.0
*/
virtual wxString GetSharedLibrariesDir() const;

/**
MSW-specific function to customize application directory detection.
Expand Down
4 changes: 4 additions & 0 deletions src/common/stdpbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const
return subdir;
}

wxString wxStandardPathsBase::GetSharedLibrariesDir() const
{
return {};
}
6 changes: 6 additions & 0 deletions src/msw/stdpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ wxStandardPaths::MakeConfigFileName(const wxString& basename,
return fn.GetFullName();
}

wxString wxStandardPaths::GetSharedLibrariesDir() const
{
wxFileName fn( GetExecutablePath() );
return fn.GetPath();
}

// ============================================================================
// wxStandardPathsWin16 implementation
// ============================================================================
Expand Down
7 changes: 7 additions & 0 deletions src/osx/cocoa/stdpaths.mm
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,11 @@ ConfigFileConv WXUNUSED(conv)) const
return fn.GetFullName();
}

wxString wxStandardPaths::GetSharedLibrariesDir() const
{
// Shared libraries on OSX should be stored inside the
// <Bundle.app>/Contents/Frameworks
return wxCFStringRef::AsString([NSBundle mainBundle].privateFrameworksPath);
}

#endif // wxUSE_STDPATHS
5 changes: 5 additions & 0 deletions src/unix/stdpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,9 @@ wxStandardPaths::MakeConfigFileName(const wxString& basename,
return fn.GetFullName();
}

wxString wxStandardPaths::GetSharedLibrariesDir() const
{
return GetInstallPrefix() + "/lib";
}

#endif // wxUSE_STDPATHS
1 change: 1 addition & 0 deletions tests/interactive/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ void InteractiveOutputTestCase::TestStandardPaths()
wxPrintf(wxT("Executable path:\t%s\n"), stdp.GetExecutablePath());
wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir());
wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp.GetResourcesDir());
wxPrintf( "Shared Libraries dir:\t\t%s\n", stdp.GetSharedLibrariesDir() );
wxPrintf(wxT("Localized res. dir:\t%s\n"),
stdp.GetLocalizedResourcesDir(wxT("fr")));
wxPrintf(wxT("Message catalogs dir:\t%s\n"),
Expand Down

0 comments on commit 91de986

Please sign in to comment.