32 #include <boost/filesystem.hpp>
33 #include <boost/range/iterator_range.hpp>
41 namespace pluginhost {
43 using boost::filesystem::directory_iterator;
44 using boost::make_iterator_range;
45 namespace fs = boost::filesystem;
50 OSVR_DEV_VERBOSE(
"Binary location: " << exeLocation);
54 auto binDir = exeLocation.parent_path();
56 #if defined(_MSC_VER) && defined(CMAKE_INTDIR)
57 if (binDir.filename() == CMAKE_INTDIR) {
63 binDir = binDir.parent_path();
73 auto addUniquePath = [&paths](fs::path
const &path) {
75 auto pathString = path.generic_string();
76 if (std::find(begin(paths), end(paths), pathString) == end(paths)) {
78 paths.emplace_back(std::move(pathString));
82 #ifdef OSVR_PLUGINS_UNDER_BINDIR
85 addUniquePath(binDir / OSVR_PLUGIN_SUBDIR);
91 auto root = binDir.parent_path();
92 std::vector<fs::path> rootDirCandidates;
94 auto compiledBinDir = fs::path{OSVR_BINDIR};
96 rootDirCandidates.push_back(root);
97 root = root.parent_path();
98 compiledBinDir = compiledBinDir.parent_path();
99 }
while (!compiledBinDir.empty() && !root.empty());
104 auto currentWorkingDirectory = boost::filesystem::current_path();
105 if (currentWorkingDirectory != root) {
106 addUniquePath(currentWorkingDirectory / OSVR_PLUGIN_DIR);
111 for (
auto const &possibleRoot : rootDirCandidates) {
113 #if defined(_MSC_VER) && defined(CMAKE_INTDIR)
114 addUniquePath(possibleRoot / OSVR_PLUGIN_DIR / CMAKE_INTDIR);
116 addUniquePath(possibleRoot / OSVR_PLUGIN_DIR);
125 const std::string &ext) {
128 for (
const auto &path : dirPath) {
129 fs::path directoryPath(path);
132 if (!fs::exists(directoryPath)) {
137 for (
const auto &pathName : make_iterator_range(
138 directory_iterator(directoryPath), directory_iterator())) {
139 if (!fs::is_regular_file(pathName) ||
140 pathName.path().extension() != ext) {
144 filesPaths.push_back(pathName.path().generic_string());
152 const std::string &pluginName) {
153 for (
const auto &searchPath : searchPaths) {
154 if (!fs::exists(searchPath)) {
158 for (
const auto &pluginPathName : make_iterator_range(
159 directory_iterator(searchPath), directory_iterator())) {
162 if (!fs::is_regular_file(pluginPathName)) {
166 const auto pluginCandidate = fs::path(pluginPathName);
169 if (pluginCandidate.extension().generic_string() !=
170 OSVR_PLUGIN_EXTENSION) {
173 const auto pluginBaseName =
174 pluginCandidate.filename().stem().generic_string();
177 if ((pluginBaseName == pluginName) ||
179 pluginName + OSVR_PLUGIN_IGNORE_SUFFIX)) {
180 return pluginPathName.path().generic_string();
185 return std::string();
FileList getAllFilesWithExt(SearchPath const &dirPath, const std::string &ext)
Get list of files inside the directory with given extension.
SearchPath getPluginSearchPath()
Find a place where to look for plugins.
std::string getBinaryLocation()
Internal, configured header file for verbosity macros.
std::string findPlugin(SearchPath const &searchPaths, const std::string &pluginName)
Given the name of a plugin, find the full path to the plugin library.
Auto-generated configuration header - do not edit!