MCPcopy Create free account
hub / github.com/MITK/MITK / AutoLoadModulesFromPath

Function AutoLoadModulesFromPath

Modules/CppMicroServices/src/usUtils.cpp:100–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98namespace us {
99
100std::vector<std::string> AutoLoadModulesFromPath(const std::string& absoluteBasePath, const std::string& subDir)
101{
102 std::vector<std::string> loadedModules;
103
104 namespace fs = std::filesystem;
105
106 fs::path loadPath = fs::path(absoluteBasePath) / subDir;
107
108#ifdef CMAKE_INTDIR
109 // Try intermediate output directories
110 if (!fs::is_directory(loadPath))
111 {
112 fs::path basePath(absoluteBasePath);
113 std::string intermediateDir = basePath.filename().string();
114 bool equalSubDir = intermediateDir.size() == std::strlen(CMAKE_INTDIR);
115 for (std::size_t i = 0; equalSubDir && i < intermediateDir.size(); ++i)
116 {
117 if (std::tolower(intermediateDir[i]) != std::tolower(CMAKE_INTDIR[i]))
118 {
119 equalSubDir = false;
120 }
121 }
122 if (equalSubDir)
123 {
124 loadPath = basePath.parent_path() / subDir / CMAKE_INTDIR;
125 }
126 }
127#endif
128
129 std::error_code ec;
130 for (const auto& entry : fs::directory_iterator(loadPath, ec))
131 {
132 if (!entry.is_regular_file(ec))
133 continue;
134
135 std::string entryFileName = entry.path().filename().string();
136
137 // On Linux, library file names can have version numbers appended. On other platforms, we
138 // check the file ending. This could be refined for Linux in the future.
139#if !defined(US_PLATFORM_LINUX)
140 if (entryFileName.rfind(library_suffix()) != (entryFileName.size() - library_suffix().size()))
141 {
142 continue;
143 }
144#endif
145
146 std::string libPath = entry.path().string();
147
148 if (!load_impl(libPath))
149 {
150 MITK_WARN << "Auto-loading of module " << libPath << " failed.";
151 }
152 else
153 {
154 loadedModules.push_back(libPath);
155 }
156 }
157 return loadedModules;

Callers 1

AutoLoadModulesFunction · 0.85

Calls 3

library_suffixFunction · 0.85
load_implFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected