Skip to content

Commit bcc5a16

Browse files
authored
[Helper] PluginManager: support loading from Non-MSVC Multi-Configuration Build (#5133)
* remove collections from searchable paths * cmake: pass config info and use it for search paths * remove typo in template parameters * add support for minsizerel * test existence of directory before browsing * just use the string
1 parent 07ce419 commit bcc5a16

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

Sofa/framework/Helper/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${ST
263263
# DiffLib (header only)
264264
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${difflib_INCLUDE_DIR}>")
265265

266+
set(is_release "$<CONFIG:RELEASE>")
267+
set(is_debug "$<CONFIG:DEBUG>")
268+
set(is_relwithdebinfo "$<CONFIG:RELWITHDEBINFO>")
269+
set(is_minsizerel "$<CONFIG:MINSIZEREL>")
270+
# set the type of build as preprocessor value
271+
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_release}:SOFA_BUILD_CONFIGURATION=Release>")
272+
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_debug}:SOFA_BUILD_CONFIGURATION=Debug>")
273+
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_relwithdebinfo}:SOFA_BUILD_CONFIGURATION=RelWithDebInfo>")
274+
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_minsizerel}:SOFA_BUILD_CONFIGURATION=MinSizeRel>")
275+
## if the type of build is something else (not supported), then SOFA_BUILD_CONFIGURATION wont be defined
276+
# it could be also useful to know if we are using a multi-config generator
277+
if(CMAKE_CONFIGURATION_TYPES)
278+
target_compile_definitions(${PROJECT_NAME} PRIVATE "SOFA_BUILD_MULTI_CONFIGURATION=1")
279+
else()
280+
target_compile_definitions(${PROJECT_NAME} PRIVATE "SOFA_BUILD_MULTI_CONFIGURATION=0")
281+
endif()
282+
266283
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Sofa.Framework) # IDE folder
267284

268285
sofa_create_package_with_targets(

Sofa/framework/Helper/src/sofa/helper/system/FileRepository.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ FileRepository PluginRepository(
8686
{
8787
Utils::getSofaPathTo("bin"),
8888
Utils::getSofaPathTo("plugins"),
89-
Utils::getSofaPathTo("collections"),
9089
Utils::getExecutableDirectory(),
9190
}
9291
);
9392
#else
9493
FileRepository PluginRepository(
9594
"SOFA_PLUGIN_PATH",
9695
{
97-
Utils::getSofaPathTo("plugins"),
98-
Utils::getSofaPathTo("collections"),
9996
Utils::getSofaPathTo("lib"),
97+
Utils::getSofaPathTo("plugins"),
10098
}
10199
);
102100
#endif

Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ using sofa::helper::system::FileSystem;
4040
#include <fstream>
4141
#include <array>
4242

43+
#ifdef SOFA_BUILD_CONFIGURATION
44+
constexpr std::string_view SOFA_BUILD_CONFIGURATION_STR = sofa_tostring(SOFA_BUILD_CONFIGURATION);
45+
#else
46+
constexpr std::string_view SOFA_BUILD_CONFIGURATION_STR = "NONE";
47+
#endif
48+
49+
constexpr std::string_view GetSofaBuildConfigurationString()
50+
{
51+
return SOFA_BUILD_CONFIGURATION_STR;
52+
}
53+
4354
namespace sofa::helper::system
4455
{
4556

@@ -469,17 +480,46 @@ std::string PluginManager::findPlugin(const std::string& pluginName, const std::
469480
}
470481
}
471482
}
472-
473-
// Second try: case-insensitive and recursive
483+
484+
// Second try: case-insensitive and non-recursive
485+
if (ignoreCase)
486+
{
487+
const std::string downcaseLibName = helper::downcaseString(libName);
488+
489+
for (const auto & dir : searchPaths)
490+
{
491+
const std::array paths =
492+
{
493+
dir, // Non-Multi-Config build, install
494+
FileSystem::append(dir, GetSofaBuildConfigurationString()) // Multi-Config build
495+
};
496+
497+
for (const auto & path : paths)
498+
{
499+
if ( fs::exists(path) )
500+
{
501+
for (auto const& dirEntry : std::filesystem::directory_iterator{path})
502+
{
503+
const std::string filename = dirEntry.path().filename().string();
504+
const std::string downcaseFilename = helper::downcaseString(filename);
505+
if (downcaseFilename == downcaseLibName)
506+
{
507+
return FileSystem::cleanPath(dirEntry.path().string());
508+
}
509+
}
510+
}
511+
}
512+
}
513+
}
514+
515+
// Last try: case-insensitive and recursive
474516
if (ignoreCase)
475517
{
476518
if(!recursive) maxRecursiveDepth = 0;
477519
const std::string downcaseLibName = helper::downcaseString(libName);
478-
479-
for (std::vector<std::string>::iterator i = searchPaths.begin(); i!=searchPaths.end(); i++)
520+
521+
for (const auto & dir : searchPaths)
480522
{
481-
const std::string& dir = *i;
482-
483523
fs::recursive_directory_iterator iter(dir);
484524
fs::recursive_directory_iterator end;
485525

0 commit comments

Comments
 (0)