diff options
author | Mark Brand <mabrand@mabrand.nl> | 2011-01-10 15:41:55 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-01-10 15:41:55 (GMT) |
commit | 95646b07968604aa69f7e367dab7c9966dc44772 (patch) | |
tree | 682b4926a0c3534eea994725d8890f2a40ed559b | |
parent | 89886a34d7c4fdacc472f6e1498bc0769f2302ad (diff) | |
download | Qt-95646b07968604aa69f7e367dab7c9966dc44772.zip Qt-95646b07968604aa69f7e367dab7c9966dc44772.tar.gz Qt-95646b07968604aa69f7e367dab7c9966dc44772.tar.bz2 |
qmake: don't limit pkg-config writing to unix generator
Move pkg-config related methods from unix generator to base class
so they can be used by other generators too.
Merge-request: 2543
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
-rw-r--r-- | qmake/generators/makefile.cpp | 178 | ||||
-rw-r--r-- | qmake/generators/makefile.h | 5 | ||||
-rw-r--r-- | qmake/generators/unix/unixmake.h | 4 | ||||
-rw-r--r-- | qmake/generators/unix/unixmake2.cpp | 178 |
4 files changed, 183 insertions, 182 deletions
diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index 9579ae4..e18c9b5 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -3123,4 +3123,182 @@ MakefileGenerator::openOutput(QFile &file, const QString &build) const return false; } +QString +MakefileGenerator::pkgConfigFileName(bool fixify) +{ + QString ret = var("TARGET"); + int slsh = ret.lastIndexOf(Option::dir_sep); + if(slsh != -1) + ret = ret.right(ret.length() - slsh - 1); + if(ret.startsWith("lib")) + ret = ret.mid(3); + int dot = ret.indexOf('.'); + if(dot != -1) + ret = ret.left(dot); + ret += Option::pkgcfg_ext; + QString subdir = project->first("QMAKE_PKGCONFIG_DESTDIR"); + if(!subdir.isEmpty()) { + // initOutPaths() appends dir_sep, but just to be safe.. + if (!subdir.endsWith(Option::dir_sep)) + ret.prepend(Option::dir_sep); + ret.prepend(subdir); + } + if(fixify) { + if(QDir::isRelativePath(ret) && !project->isEmpty("DESTDIR")) + ret.prepend(project->first("DESTDIR")); + ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir)); + } + return ret; +} + +QString +MakefileGenerator::pkgConfigPrefix() const +{ + if(!project->isEmpty("QMAKE_PKGCONFIG_PREFIX")) + return project->first("QMAKE_PKGCONFIG_PREFIX"); + return QLibraryInfo::location(QLibraryInfo::PrefixPath); +} + +QString +MakefileGenerator::pkgConfigFixPath(QString path) const +{ + QString prefix = pkgConfigPrefix(); + if(path.startsWith(prefix)) + path = path.replace(prefix, "${prefix}"); + return path; +} + +void +MakefileGenerator::writePkgConfigFile() +{ + QString fname = pkgConfigFileName(), lname = fname; + mkdir(fileInfo(fname).path()); + int slsh = lname.lastIndexOf(Option::dir_sep); + if(slsh != -1) + lname = lname.right(lname.length() - slsh - 1); + QFile ft(fname); + if(!ft.open(QIODevice::WriteOnly)) + return; + project->values("ALL_DEPS").append(fileFixify(fname)); + QTextStream t(&ft); + + QString prefix = pkgConfigPrefix(); + QString libDir = project->first("QMAKE_PKGCONFIG_LIBDIR"); + if(libDir.isEmpty()) + libDir = prefix + Option::dir_sep + "lib" + Option::dir_sep; + QString includeDir = project->first("QMAKE_PKGCONFIG_INCDIR"); + if(includeDir.isEmpty()) + includeDir = prefix + "/include"; + + t << "prefix=" << prefix << endl; + t << "exec_prefix=${prefix}\n" + << "libdir=" << pkgConfigFixPath(libDir) << "\n" + << "includedir=" << pkgConfigFixPath(includeDir) << endl; + // non-standard entry. Provides useful info normally only + // contained in the internal .qmake.cache file + t << varGlue("CONFIG", "qt_config=", " ", "") << endl; + + //extra PKGCONFIG variables + const QStringList &pkgconfig_vars = project->values("QMAKE_PKGCONFIG_VARIABLES"); + for(int i = 0; i < pkgconfig_vars.size(); ++i) { + QString var = project->first(pkgconfig_vars.at(i) + ".name"), + val = project->values(pkgconfig_vars.at(i) + ".value").join(" "); + if(var.isEmpty()) + continue; + if(val.isEmpty()) { + const QStringList &var_vars = project->values(pkgconfig_vars.at(i) + ".variable"); + for(int v = 0; v < var_vars.size(); ++v) { + const QStringList &vars = project->values(var_vars.at(v)); + for(int var = 0; var < vars.size(); ++var) { + if(!val.isEmpty()) + val += " "; + val += pkgConfigFixPath(vars.at(var)); + } + } + } + t << var << "=" << val << endl; + } + + t << endl; + + QString name = project->first("QMAKE_PKGCONFIG_NAME"); + if(name.isEmpty()) { + name = project->first("QMAKE_ORIG_TARGET").toLower(); + name.replace(0, 1, name[0].toUpper()); + } + t << "Name: " << name << endl; + QString desc = project->values("QMAKE_PKGCONFIG_DESCRIPTION").join(" "); + if(desc.isEmpty()) { + if(name.isEmpty()) { + desc = project->first("QMAKE_ORIG_TARGET").toLower(); + desc.replace(0, 1, desc[0].toUpper()); + } else { + desc = name; + } + if(project->first("TEMPLATE") == "lib") { + if(project->isActiveConfig("plugin")) + desc += " Plugin"; + else + desc += " Library"; + } else if(project->first("TEMPLATE") == "app") { + desc += " Application"; + } + } + t << "Description: " << desc << endl; + t << "Version: " << project->first("VERSION") << endl; + + // libs + t << "Libs: "; + QString pkgConfiglibDir; + QString pkgConfiglibName; + if (Option::target_mode == Option::TARG_MACX_MODE && project->isActiveConfig("lib_bundle")) { + pkgConfiglibDir = "-F${libdir}"; + QString bundle; + if (!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME")) + bundle = unescapeFilePath(project->first("QMAKE_FRAMEWORK_BUNDLE_NAME")); + else + bundle = unescapeFilePath(project->first("TARGET")); + int suffix = bundle.lastIndexOf(".framework"); + if (suffix != -1) + bundle = bundle.left(suffix); + pkgConfiglibName = "-framework " + bundle + " "; + } else { + pkgConfiglibDir = "-L${libdir}"; + pkgConfiglibName = "-l" + lname.left(lname.length()-Option::libtool_ext.length()); + } + t << pkgConfiglibDir << " " << pkgConfiglibName << " " << endl; + + QStringList libs; + if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) { + libs = project->values("QMAKE_INTERNAL_PRL_LIBS"); + } else { + libs << "QMAKE_LIBS"; //obvious one + } + libs << "QMAKE_LIBS_PRIVATE"; + libs << "QMAKE_LFLAGS_THREAD"; //not sure about this one, but what about things like -pthread? + t << "Libs.private: "; + for(QStringList::ConstIterator it = libs.begin(); it != libs.end(); ++it) { + t << project->values((*it)).join(" ") << " "; + } + t << endl; + + // flags + // ### too many + t << "Cflags: " + // << var("QMAKE_CXXFLAGS") << " " + << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ") + << project->values("PRL_EXPORT_CXXFLAGS").join(" ") + << project->values("QMAKE_PKGCONFIG_CFLAGS").join(" ") + // << varGlue("DEFINES","-D"," -D"," ") + << " -I${includedir}" << endl; + + // requires + const QString requires = project->values("QMAKE_PKGCONFIG_REQUIRES").join(" "); + if (!requires.isEmpty()) { + t << "Requires: " << requires << endl; + } + + t << endl; +} + QT_END_NAMESPACE diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index 4c3be3d..fe611b2 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -105,6 +105,11 @@ protected: virtual bool writeStubMakefile(QTextStream &t); virtual bool writeMakefile(QTextStream &t); + QString pkgConfigPrefix() const; + QString pkgConfigFileName(bool fixify=true); + QString pkgConfigFixPath(QString) const; + void writePkgConfigFile(); // for pkg-config + //generating subtarget makefiles struct SubTarget { diff --git a/qmake/generators/unix/unixmake.h b/qmake/generators/unix/unixmake.h index 0ea3350..f017672 100644 --- a/qmake/generators/unix/unixmake.h +++ b/qmake/generators/unix/unixmake.h @@ -51,10 +51,6 @@ class UnixMakefileGenerator : public MakefileGenerator bool init_flag, include_deps; QString libtoolFileName(bool fixify=true); void writeLibtoolFile(); // for libtool - QString pkgConfigPrefix() const; - QString pkgConfigFileName(bool fixify=true); - QString pkgConfigFixPath(QString) const; - void writePkgConfigFile(); // for pkg-config void writePrlFile(QTextStream &); public: diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp index 009d4b5..1ea9e30 100644 --- a/qmake/generators/unix/unixmake2.cpp +++ b/qmake/generators/unix/unixmake2.cpp @@ -1340,182 +1340,4 @@ UnixMakefileGenerator::writeLibtoolFile() "libdir='" << Option::fixPathToTargetOS(install_dir, false) << "'\n"; } -QString -UnixMakefileGenerator::pkgConfigFileName(bool fixify) -{ - QString ret = var("TARGET"); - int slsh = ret.lastIndexOf(Option::dir_sep); - if(slsh != -1) - ret = ret.right(ret.length() - slsh - 1); - if(ret.startsWith("lib")) - ret = ret.mid(3); - int dot = ret.indexOf('.'); - if(dot != -1) - ret = ret.left(dot); - ret += Option::pkgcfg_ext; - QString subdir = project->first("QMAKE_PKGCONFIG_DESTDIR"); - if(!subdir.isEmpty()) { - // initOutPaths() appends dir_sep, but just to be safe.. - if (!subdir.endsWith(Option::dir_sep)) - ret.prepend(Option::dir_sep); - ret.prepend(subdir); - } - if(fixify) { - if(QDir::isRelativePath(ret) && !project->isEmpty("DESTDIR")) - ret.prepend(project->first("DESTDIR")); - ret = Option::fixPathToLocalOS(fileFixify(ret, qmake_getpwd(), Option::output_dir)); - } - return ret; -} - -QString -UnixMakefileGenerator::pkgConfigPrefix() const -{ - if(!project->isEmpty("QMAKE_PKGCONFIG_PREFIX")) - return project->first("QMAKE_PKGCONFIG_PREFIX"); - return QLibraryInfo::location(QLibraryInfo::PrefixPath); -} - -QString -UnixMakefileGenerator::pkgConfigFixPath(QString path) const -{ - QString prefix = pkgConfigPrefix(); - if(path.startsWith(prefix)) - path = path.replace(prefix, "${prefix}"); - return path; -} - -void -UnixMakefileGenerator::writePkgConfigFile() -{ - QString fname = pkgConfigFileName(), lname = fname; - mkdir(fileInfo(fname).path()); - int slsh = lname.lastIndexOf(Option::dir_sep); - if(slsh != -1) - lname = lname.right(lname.length() - slsh - 1); - QFile ft(fname); - if(!ft.open(QIODevice::WriteOnly)) - return; - project->values("ALL_DEPS").append(fileFixify(fname)); - QTextStream t(&ft); - - QString prefix = pkgConfigPrefix(); - QString libDir = project->first("QMAKE_PKGCONFIG_LIBDIR"); - if(libDir.isEmpty()) - libDir = prefix + Option::dir_sep + "lib" + Option::dir_sep; - QString includeDir = project->first("QMAKE_PKGCONFIG_INCDIR"); - if(includeDir.isEmpty()) - includeDir = prefix + "/include"; - - t << "prefix=" << prefix << endl; - t << "exec_prefix=${prefix}\n" - << "libdir=" << pkgConfigFixPath(libDir) << "\n" - << "includedir=" << pkgConfigFixPath(includeDir) << endl; - // non-standard entry. Provides useful info normally only - // contained in the internal .qmake.cache file - t << varGlue("CONFIG", "qt_config=", " ", "") << endl; - - //extra PKGCONFIG variables - const QStringList &pkgconfig_vars = project->values("QMAKE_PKGCONFIG_VARIABLES"); - for(int i = 0; i < pkgconfig_vars.size(); ++i) { - QString var = project->first(pkgconfig_vars.at(i) + ".name"), - val = project->values(pkgconfig_vars.at(i) + ".value").join(" "); - if(var.isEmpty()) - continue; - if(val.isEmpty()) { - const QStringList &var_vars = project->values(pkgconfig_vars.at(i) + ".variable"); - for(int v = 0; v < var_vars.size(); ++v) { - const QStringList &vars = project->values(var_vars.at(v)); - for(int var = 0; var < vars.size(); ++var) { - if(!val.isEmpty()) - val += " "; - val += pkgConfigFixPath(vars.at(var)); - } - } - } - t << var << "=" << val << endl; - } - - t << endl; - - QString name = project->first("QMAKE_PKGCONFIG_NAME"); - if(name.isEmpty()) { - name = project->first("QMAKE_ORIG_TARGET").toLower(); - name.replace(0, 1, name[0].toUpper()); - } - t << "Name: " << name << endl; - QString desc = project->values("QMAKE_PKGCONFIG_DESCRIPTION").join(" "); - if(desc.isEmpty()) { - if(name.isEmpty()) { - desc = project->first("QMAKE_ORIG_TARGET").toLower(); - desc.replace(0, 1, desc[0].toUpper()); - } else { - desc = name; - } - if(project->first("TEMPLATE") == "lib") { - if(project->isActiveConfig("plugin")) - desc += " Plugin"; - else - desc += " Library"; - } else if(project->first("TEMPLATE") == "app") { - desc += " Application"; - } - } - t << "Description: " << desc << endl; - t << "Version: " << project->first("VERSION") << endl; - - // libs - t << "Libs: "; - QString pkgConfiglibDir; - QString pkgConfiglibName; - if (Option::target_mode == Option::TARG_MACX_MODE && project->isActiveConfig("lib_bundle")) { - pkgConfiglibDir = "-F${libdir}"; - QString bundle; - if (!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME")) - bundle = unescapeFilePath(project->first("QMAKE_FRAMEWORK_BUNDLE_NAME")); - else - bundle = unescapeFilePath(project->first("TARGET")); - int suffix = bundle.lastIndexOf(".framework"); - if (suffix != -1) - bundle = bundle.left(suffix); - pkgConfiglibName = "-framework " + bundle + " "; - } else { - pkgConfiglibDir = "-L${libdir}"; - pkgConfiglibName = "-l" + lname.left(lname.length()-Option::libtool_ext.length()); - } - t << pkgConfiglibDir << " " << pkgConfiglibName << " " << endl; - - QStringList libs; - if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) { - libs = project->values("QMAKE_INTERNAL_PRL_LIBS"); - } else { - libs << "QMAKE_LIBS"; //obvious one - } - libs << "QMAKE_LIBS_PRIVATE"; - libs << "QMAKE_LFLAGS_THREAD"; //not sure about this one, but what about things like -pthread? - t << "Libs.private: "; - for(QStringList::ConstIterator it = libs.begin(); it != libs.end(); ++it) { - t << project->values((*it)).join(" ") << " "; - } - t << endl; - - // flags - // ### too many - t << "Cflags: " - // << var("QMAKE_CXXFLAGS") << " " - << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ") - << project->values("PRL_EXPORT_CXXFLAGS").join(" ") - << project->values("QMAKE_PKGCONFIG_CFLAGS").join(" ") - // << varGlue("DEFINES","-D"," -D"," ") - << " -I${includedir}" << endl; - - // requires - const QString requires = project->values("QMAKE_PKGCONFIG_REQUIRES").join(" "); - if (!requires.isEmpty()) { - t << "Requires: " << requires << endl; - } - - t << endl; -} - QT_END_NAMESPACE |