Add helpers to identify the documents directory
This commit is contained in:
parent
8881c369f3
commit
a34ac38aec
4 changed files with 93 additions and 2 deletions
|
|
@ -18,14 +18,20 @@ set(VSTPLUGIN_SOURCES
|
|||
SfizzVstEditor.cpp
|
||||
SfizzVstState.cpp
|
||||
VstPluginFactory.cpp
|
||||
X11RunLoop.cpp)
|
||||
X11RunLoop.cpp
|
||||
NativeHelpers.cpp)
|
||||
|
||||
set(VSTPLUGIN_HEADERS
|
||||
SfizzVstProcessor.h
|
||||
SfizzVstController.h
|
||||
SfizzVstEditor.h
|
||||
SfizzVstState.h
|
||||
X11RunLoop.h)
|
||||
X11RunLoop.h
|
||||
NativeHelpers.h)
|
||||
|
||||
if(APPLE)
|
||||
list(APPEND VSTPLUGIN_SOURCES NativeHelpers.mm)
|
||||
endif()
|
||||
|
||||
add_library(${VSTPLUGIN_PRJ_NAME} MODULE
|
||||
${VSTPLUGIN_HEADERS}
|
||||
|
|
@ -65,6 +71,16 @@ if (MINGW)
|
|||
set_target_properties (${VSTPLUGIN_PRJ_NAME} PROPERTIES LINK_FLAGS "-static")
|
||||
endif()
|
||||
|
||||
# Link system dependencies
|
||||
if(WIN32)
|
||||
elseif(APPLE)
|
||||
target_link_libraries(${VSTPLUGIN_PRJ_NAME} PRIVATE ${APPLE_FOUNDATION_LIBRARY})
|
||||
else()
|
||||
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||
target_include_directories(${VSTPLUGIN_PRJ_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||
target_link_libraries(${VSTPLUGIN_PRJ_NAME} PRIVATE ${GLIB_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# Create the bundle (see "VST 3 Locations / Format")
|
||||
execute_process (
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/${VSTPLUGIN_BUNDLE_NAME}/Contents/Resources")
|
||||
|
|
|
|||
39
vst/NativeHelpers.cpp
Normal file
39
vst/NativeHelpers.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#include "NativeHelpers.h"
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
const fs::path& getUserDocumentsDirectory()
|
||||
{
|
||||
static const fs::path directory = []() -> fs::path {
|
||||
std::unique_ptr<WCHAR[]> path(new WCHAR[32768]);
|
||||
if (SHGetFolderPathW(nullptr, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path.get()) != S_OK)
|
||||
throw std::runtime_error("Cannot get the document directory.");
|
||||
return fs::path(path.get());
|
||||
}();
|
||||
return directory;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
// implemented in NativeHelpers.mm
|
||||
#else
|
||||
#include <glib.h>
|
||||
|
||||
const fs::path& getUserDocumentsDirectory()
|
||||
{
|
||||
static const fs::path directory = []() -> fs::path {
|
||||
const gchar *path = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
|
||||
if (!path)
|
||||
throw std::runtime_error("Cannot get the document directory.");
|
||||
return fs::path(path);
|
||||
}();
|
||||
return directory;
|
||||
}
|
||||
#endif
|
||||
10
vst/NativeHelpers.h
Normal file
10
vst/NativeHelpers.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#pragma once
|
||||
#include <ghc/fs_std.hpp>
|
||||
|
||||
const fs::path& getUserDocumentsDirectory();
|
||||
26
vst/NativeHelpers.mm
Normal file
26
vst/NativeHelpers.mm
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#include "NativeHelpers.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
const fs::path& getUserDocumentsDirectory()
|
||||
{
|
||||
static const fs::path directory = []() -> fs::path {
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSArray<NSURL *> *urls = [fm URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
|
||||
for (NSUInteger i = 0, n = [urls count]; i < n; ++i) {
|
||||
NSURL *url = [urls objectAtIndex:i];
|
||||
if ([url isFileURL])
|
||||
return fs::path([url path].UTF8String);
|
||||
}
|
||||
throw std::runtime_error("Cannot get the document directory.");
|
||||
}();
|
||||
return directory;
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue