forked from qt-creator/qt-creator
CMake: Add paths from target_link_directories to ((DY)LD_LIBRARY_)PATH
So far we only looked at a target and added all paths of actually linked libraries to the ((DY)LD_LIBRARY_)PATH, if the "Add build library search path" option is on (the default). That often is fine, but - if the library to link to is only given as a library name, not a path and not a CMake target, then CMake file-api doesn't give us a path to the library either - on Windows, where the .lib is needed for compiletime linking, but the .dll is needed for runtime linking this only helps if the .dll was in the same directory as the .lib We already have a hack on Windows, if the directory ends in /lib, that we also add /lib/../bin, but that again only helps for that specific layout. Instead actually add the "build library search path", by adding the directories from target_link_directories, even if no libraries are linked from there. This fixes the "linked only by name" issue, and allows users to add a build library search path to the .dll too, and have that used by Qt Creator for running the application. Fixes: QTCREATORBUG-27201 Change-Id: I7b9210b791b4dae3a6d1747ff36e4b82235db2f9 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -268,7 +268,18 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
|||||||
|
|
||||||
// CMake sometimes mixes several shell-escaped pieces into one fragment. Disentangle that again:
|
// CMake sometimes mixes several shell-escaped pieces into one fragment. Disentangle that again:
|
||||||
const QStringList parts = ProcessArgs::splitArgs(f.fragment);
|
const QStringList parts = ProcessArgs::splitArgs(f.fragment);
|
||||||
for (const QString &part : parts) {
|
for (QString part : parts) {
|
||||||
|
// Library search paths that are added with target_link_directories are added as
|
||||||
|
// -LIBPATH:... (Windows/MSVC), or
|
||||||
|
// -L... (Unix/GCC)
|
||||||
|
// with role "libraryPath"
|
||||||
|
if (f.role == "libraryPath") {
|
||||||
|
if (part.startsWith("-LIBPATH:"))
|
||||||
|
part = part.mid(9);
|
||||||
|
else if (part.startsWith("-L"))
|
||||||
|
part = part.mid(2);
|
||||||
|
}
|
||||||
|
|
||||||
// Some projects abuse linking to libraries to pass random flags to the linker, so ignore
|
// Some projects abuse linking to libraries to pass random flags to the linker, so ignore
|
||||||
// flags mixed into a fragment
|
// flags mixed into a fragment
|
||||||
if (part.startsWith("-"))
|
if (part.startsWith("-"))
|
||||||
|
Reference in New Issue
Block a user