diff --git a/Sofa/framework/Helper/CMakeLists.txt b/Sofa/framework/Helper/CMakeLists.txt index 0fc3c9d2650..f78ff2917ee 100644 --- a/Sofa/framework/Helper/CMakeLists.txt +++ b/Sofa/framework/Helper/CMakeLists.txt @@ -263,6 +263,23 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$") +set(is_release "$") +set(is_debug "$") +set(is_relwithdebinfo "$") +set(is_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( diff --git a/Sofa/framework/Helper/src/sofa/helper/system/FileRepository.cpp b/Sofa/framework/Helper/src/sofa/helper/system/FileRepository.cpp index 9fbef88b423..dfd888f7de4 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/FileRepository.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/FileRepository.cpp @@ -86,7 +86,6 @@ FileRepository PluginRepository( { Utils::getSofaPathTo("bin"), Utils::getSofaPathTo("plugins"), - Utils::getSofaPathTo("collections"), Utils::getExecutableDirectory(), } ); @@ -94,9 +93,8 @@ FileRepository PluginRepository( FileRepository PluginRepository( "SOFA_PLUGIN_PATH", { - Utils::getSofaPathTo("plugins"), - Utils::getSofaPathTo("collections"), Utils::getSofaPathTo("lib"), + Utils::getSofaPathTo("plugins"), } ); #endif diff --git a/Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp b/Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp index bf4df3e3c7b..2c60200c2bc 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/PluginManager.cpp @@ -40,6 +40,17 @@ using sofa::helper::system::FileSystem; #include #include +#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 { @@ -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::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;