Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Helper] PluginManager: support loading from Non-MSVC Multi-Configuration Build #5133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Sofa/framework/Helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${ST
# DiffLib (header only)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${difflib_INCLUDE_DIR}>")

set(is_release "$<CONFIG:RELEASE>")
set(is_debug "$<CONFIG:DEBUG>")
set(is_relwithdebinfo "$<CONFIG:RELWITHDEBINFO>")
set(is_minsizerel "$<CONFIG:MINSIZEREL>")
# set the type of build as preprocessor value
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_release}:SOFA_BUILD_CONFIGURATION=Release>")
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_debug}:SOFA_BUILD_CONFIGURATION=Debug>")
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_relwithdebinfo}:SOFA_BUILD_CONFIGURATION=RelWithDebInfo>")
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<${is_minsizerel}:SOFA_BUILD_CONFIGURATION=MinSizeRel>")
## if the type of build is something else (not supported), then SOFA_BUILD_CONFIGURATION wont be defined
# it could be also useful to know if we are using a multi-config generator
if(CMAKE_CONFIGURATION_TYPES)
target_compile_definitions(${PROJECT_NAME} PRIVATE "SOFA_BUILD_MULTI_CONFIGURATION=1")
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE "SOFA_BUILD_MULTI_CONFIGURATION=0")
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Sofa.Framework) # IDE folder

sofa_create_package_with_targets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,15 @@ FileRepository PluginRepository(
{
Utils::getSofaPathTo("bin"),
Utils::getSofaPathTo("plugins"),
Utils::getSofaPathTo("collections"),
Utils::getExecutableDirectory(),
}
);
#else
FileRepository PluginRepository(
"SOFA_PLUGIN_PATH",
{
Utils::getSofaPathTo("plugins"),
Utils::getSofaPathTo("collections"),
Utils::getSofaPathTo("lib"),
Utils::getSofaPathTo("plugins"),
}
);
#endif
Expand Down
52 changes: 46 additions & 6 deletions Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ using sofa::helper::system::FileSystem;
#include <fstream>
#include <array>

#ifdef SOFA_BUILD_CONFIGURATION
constexpr std::string_view SOFA_BUILD_CONFIGURATION_STR = sofa_tostring(SOFA_BUILD_CONFIGURATION);
#else
constexpr std::string_view SOFA_BUILD_CONFIGURATION_STR = "NONE";
#endif

constexpr std::string_view GetSofaBuildConfigurationString()
{
return SOFA_BUILD_CONFIGURATION_STR;
}

namespace sofa::helper::system
{

Expand Down Expand Up @@ -469,17 +480,46 @@ std::string PluginManager::findPlugin(const std::string& pluginName, const std::
}
}
}

// Second try: case-insensitive and recursive

// Second try: case-insensitive and non-recursive
if (ignoreCase)
{
const std::string downcaseLibName = helper::downcaseString(libName);

for (const auto & dir : searchPaths)
{
const std::array paths =
{
dir, // Non-Multi-Config build, install
FileSystem::append(dir, GetSofaBuildConfigurationString()) // Multi-Config build
};

for (const auto & path : paths)
{
if ( fs::exists(path) )
{
for (auto const& dirEntry : std::filesystem::directory_iterator{path})
{
const std::string filename = dirEntry.path().filename().string();
const std::string downcaseFilename = helper::downcaseString(filename);
if (downcaseFilename == downcaseLibName)
{
return FileSystem::cleanPath(dirEntry.path().string());
}
}
}
}
}
}

// Last try: case-insensitive and recursive
if (ignoreCase)
{
if(!recursive) maxRecursiveDepth = 0;
const std::string downcaseLibName = helper::downcaseString(libName);

for (std::vector<std::string>::iterator i = searchPaths.begin(); i!=searchPaths.end(); i++)
for (const auto & dir : searchPaths)
{
const std::string& dir = *i;

fs::recursive_directory_iterator iter(dir);
fs::recursive_directory_iterator end;

Expand Down
Loading