From 91de9867ee779ef688a25f54805a99e9d0533f3e Mon Sep 17 00:00:00 2001 From: oneeyeman1 Date: Sat, 27 Jan 2024 12:43:34 -0600 Subject: [PATCH] Add wxStandardPaths::GetSharedLibrariesDir() This function returns the directory with the application's shared libraries, which is different from the plugins directory under Mac. Closes #24052. --- include/wx/msw/stdpaths.h | 1 + include/wx/osx/cocoa/stdpaths.h | 1 + include/wx/stdpaths.h | 4 ++++ include/wx/unix/stdpaths.h | 1 + interface/wx/stdpaths.h | 18 +++++++++++++++++- src/common/stdpbase.cpp | 4 ++++ src/msw/stdpaths.cpp | 6 ++++++ src/osx/cocoa/stdpaths.mm | 7 +++++++ src/unix/stdpaths.cpp | 5 +++++ tests/interactive/output.cpp | 1 + 10 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/stdpaths.h b/include/wx/msw/stdpaths.h index e36a2a9c5b0d..89d9c5ffd5f7 100644 --- a/include/wx/msw/stdpaths.h +++ b/include/wx/msw/stdpaths.h @@ -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 diff --git a/include/wx/osx/cocoa/stdpaths.h b/include/wx/osx/cocoa/stdpaths.h index 623277bbcf3b..e9b1af716d50 100644 --- a/include/wx/osx/cocoa/stdpaths.h +++ b/include/wx/osx/cocoa/stdpaths.h @@ -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, diff --git a/include/wx/stdpaths.h b/include/wx/stdpaths.h index 49b03331531e..934752cfbf4a 100644 --- a/include/wx/stdpaths.h +++ b/include/wx/stdpaths.h @@ -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 // @@ -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, diff --git a/include/wx/unix/stdpaths.h b/include/wx/unix/stdpaths.h index 018ed602e922..4cd4173e3afa 100644 --- a/include/wx/unix/stdpaths.h +++ b/include/wx/unix/stdpaths.h @@ -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 diff --git a/interface/wx/stdpaths.h b/interface/wx/stdpaths.h index 46e55a61d7ec..aaae7994b783 100644 --- a/interface/wx/stdpaths.h +++ b/interface/wx/stdpaths.h @@ -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. @@ -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. diff --git a/src/common/stdpbase.cpp b/src/common/stdpbase.cpp index 88ea17f70987..81ca39ebcb14 100644 --- a/src/common/stdpbase.cpp +++ b/src/common/stdpbase.cpp @@ -171,3 +171,7 @@ wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const return subdir; } +wxString wxStandardPathsBase::GetSharedLibrariesDir() const +{ + return {}; +} diff --git a/src/msw/stdpaths.cpp b/src/msw/stdpaths.cpp index 49f37a3bf35a..076789e36e7c 100644 --- a/src/msw/stdpaths.cpp +++ b/src/msw/stdpaths.cpp @@ -348,6 +348,12 @@ wxStandardPaths::MakeConfigFileName(const wxString& basename, return fn.GetFullName(); } +wxString wxStandardPaths::GetSharedLibrariesDir() const +{ + wxFileName fn( GetExecutablePath() ); + return fn.GetPath(); +} + // ============================================================================ // wxStandardPathsWin16 implementation // ============================================================================ diff --git a/src/osx/cocoa/stdpaths.mm b/src/osx/cocoa/stdpaths.mm index 584362c4bd9c..e9bb0e37c334 100644 --- a/src/osx/cocoa/stdpaths.mm +++ b/src/osx/cocoa/stdpaths.mm @@ -145,4 +145,11 @@ ConfigFileConv WXUNUSED(conv)) const return fn.GetFullName(); } +wxString wxStandardPaths::GetSharedLibrariesDir() const +{ + // Shared libraries on OSX should be stored inside the + // /Contents/Frameworks + return wxCFStringRef::AsString([NSBundle mainBundle].privateFrameworksPath); +} + #endif // wxUSE_STDPATHS diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index 8d49f4b11bd1..f752842b2ba0 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -369,4 +369,9 @@ wxStandardPaths::MakeConfigFileName(const wxString& basename, return fn.GetFullName(); } +wxString wxStandardPaths::GetSharedLibrariesDir() const +{ + return GetInstallPrefix() + "/lib"; +} + #endif // wxUSE_STDPATHS diff --git a/tests/interactive/output.cpp b/tests/interactive/output.cpp index 4fcbf7ea54c2..a0b8895817eb 100644 --- a/tests/interactive/output.cpp +++ b/tests/interactive/output.cpp @@ -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"),