diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index 80ea50c6d0c..1474a8da4da 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -179,6 +179,14 @@ QVector extractBacktraceInformation(const BacktraceInf return info; } +static bool isChildOf(const FilePath &path, const QStringList &prefixes) +{ + for (const QString &prefix : prefixes) + if (path.isChildOf(FilePath::fromString(prefix))) + return true; + return false; +} + QList generateBuildTargets(const PreprocessedData &input, const FilePath &sourceDirectory, const FilePath &buildDirectory) @@ -269,16 +277,28 @@ QList generateBuildTargets(const PreprocessedData &input, if (f.role == "libraries") tmp = tmp.parentDir(); - if (!tmp.isEmpty() - && tmp.isDir()) { // f.role is libraryPath or frameworkPath - librarySeachPaths.append(tmp); - // Libraries often have their import libs in ../lib and the - // actual dll files in ../bin on windows. Qt is one example of that. - if (tmp.fileName() == "lib" && HostOsInfo::isWindowsHost()) { - const FilePath path = tmp.parentDir().pathAppended("bin"); + if (!tmp.isEmpty() && tmp.isDir()) { + // f.role is libraryPath or frameworkPath + // On Linux, exclude sub-paths from "/lib(64)", "/usr/lib(64)" and + // "/usr/local/lib" since these are usually in the standard search + // paths. There probably are more, but the naming schemes are arbitrary + // so we'd need to ask the linker ("ld --verbose | grep SEARCH_DIR"). + if (!HostOsInfo::isLinuxHost() + || !isChildOf(tmp, + {"/lib", + "/lib64", + "/usr/lib", + "/usr/lib64", + "/usr/local/lib"})) { + librarySeachPaths.append(tmp); + // Libraries often have their import libs in ../lib and the + // actual dll files in ../bin on windows. Qt is one example of that. + if (tmp.fileName() == "lib" && HostOsInfo::isWindowsHost()) { + const FilePath path = tmp.parentDir().pathAppended("bin"); - if (path.isDir()) - librarySeachPaths.append(path); + if (path.isDir()) + librarySeachPaths.append(path); + } } } }