diff --git a/include/gz/gui/CMakeLists.txt b/include/gz/gui/CMakeLists.txt index 27db7054e..ccf76a2da 100644 --- a/include/gz/gui/CMakeLists.txt +++ b/include/gz/gui/CMakeLists.txt @@ -75,5 +75,9 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} TINYXML2::TINYXML2 ) +target_compile_definitions(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE + SHARED_LIBRARY_PREFIX=\"${CMAKE_SHARED_LIBRARY_PREFIX}\" + SHARED_LIBRARY_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\") + gz_install_all_headers() diff --git a/src/Application.cc b/src/Application.cc index 6031e4c30..f1b3ffc4d 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -837,10 +837,19 @@ std::vector>> { auto plugin = common::basename(*dirIter); - // All we verify is that the file starts with "lib", any further - // checks would require loading the plugin. + // All we verify is that the file starts with shared library prefix and + // ends with shared library suffix, any further checks would require + // loading the plugin. - if (plugin.find("lib") == 0) + // TODO(anyone): Move this logic into gz-plugin to be reusable + + // This computation could underflow the unsigned range, but that is okay + // as in such case we would check if the suffix is placed somewhere much + // further than allowed filename length. + const auto suffixPos = plugin.length() - strlen(SHARED_LIBRARY_SUFFIX); + + if (plugin.find(SHARED_LIBRARY_PREFIX) == 0 && + plugin.rfind(SHARED_LIBRARY_SUFFIX) == suffixPos) ps.push_back(plugin); } diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 234591ae2..37be9d851 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -126,8 +126,13 @@ QStringList MainWindow::PluginListModel() const { for (auto const &plugin : path.second) { - // Remove lib and .so - auto pluginName = plugin.substr(3, plugin.find(".") - 3); + // TODO(anyone): Move this into gz-plugin to be reusable + + // Remove shared library prefix and shared library suffix + auto pluginName = plugin.substr( + strlen(SHARED_LIBRARY_PREFIX), + plugin.length() - strlen(SHARED_LIBRARY_PREFIX) - + strlen(SHARED_LIBRARY_SUFFIX)); // Split WWWCamelCase3D -> WWW Camel Case 3D std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])");