revamp handling of qmake target mode
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Tue, 17 Apr 2012 10:15:39 +0000 (12:15 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Wed, 27 Jun 2012 07:39:50 +0000 (09:39 +0200)
the project evaluator becomes oblivious of the target mode.
the mode is set up in spec_post.prf according to the spec.
$$QMAKE_TARGET contains the feature suffixes to search, and is also
contained in $$CONFIG.
the target_mode variable itself becomes private to the Makefile class.

Change-Id: I3c06d9dab536b753343cec6c5c491d3203e50bd8
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
mkspecs/features/spec_post.prf [new file with mode: 0644]
qmake/generators/makefile.cpp
qmake/generators/makefile.h
qmake/generators/metamakefile.cpp
qmake/generators/metamakefile.h
qmake/generators/unix/unixmake.cpp
qmake/option.cpp
qmake/option.h
qmake/project.cpp
qmake/project.h

diff --git a/mkspecs/features/spec_post.prf b/mkspecs/features/spec_post.prf
new file mode 100644 (file)
index 0000000..fcc7314
--- /dev/null
@@ -0,0 +1,31 @@
+isEmpty(MAKEFILE_GENERATOR):error("Qmake spec does not set MAKEFILE_GENERATOR.")
+isEmpty(QMAKE_PLATFORM) {
+    isEmpty(TARGET_PLATFORM) {
+        equals(MAKEFILE_GENERATOR, UNIX) {
+            equals(QMAKE_HOST.os, Darwin): \
+                TARGET_PLATFORM = macx
+            else: \
+                TARGET_PLATFORM = unix
+        } else:if(equals(MAKEFILE_GENERATOR, MSVC.NET) \
+                 |equals(MAKEFILE_GENERATOR, BMAKE) \
+                 |equals(MAKEFILE_GENERATOR, MSBUILD) \
+                 |equals(MAKEFILE_GENERATOR, MINGW)) {
+            TARGET_PLATFORM = win32
+        } else:if(equals(MAKEFILE_GENERATOR, PROJECTBUILDER) \
+                 |equals(MAKEFILE_GENERATOR, XCODE)) {
+        } else:equals(MAKEFILE_GENERATOR, GBUILD) {
+            TARGET_PLATFORM = unix
+        } else {
+            error("Qmake spec sets an invalid MAKEFILE_GENERATOR.")
+        }
+    }
+    equals(TARGET_PLATFORM, unix): \
+        QMAKE_PLATFORM = unix
+    else:equals(TARGET_PLATFORM, macx): \
+        QMAKE_PLATFORM = mac macx unix
+    else:equals(TARGET_PLATFORM, win32): \
+        QMAKE_PLATFORM = win32
+    else: \
+        error("Qmake spec sets an invalid TARGET_PLATFORM.")
+}
+CONFIG += $$QMAKE_PLATFORM
index 2a21aa9..f187190 100644 (file)
@@ -300,6 +300,12 @@ MakefileGenerator::setProjectFile(QMakeProject *p)
     if(project)
         return;
     project = p;
+    if (project->isActiveConfig("win32"))
+        target_mode = TARG_WIN_MODE;
+    else if (project->isActiveConfig("macx"))
+        target_mode = TARG_MACX_MODE;
+    else
+        target_mode = TARG_UNIX_MODE;
     init();
     findLibraries();
     if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE &&
@@ -3253,7 +3259,7 @@ MakefileGenerator::writePkgConfigFile()
     t << "Libs: ";
     QString pkgConfiglibDir;
     QString pkgConfiglibName;
-    if (Option::target_mode == Option::TARG_MACX_MODE && project->isActiveConfig("lib_bundle")) {
+    if (target_mode == TARG_MACX_MODE && project->isActiveConfig("lib_bundle")) {
         pkgConfiglibDir = "-F${libdir}";
         QString bundle;
         if (!project->isEmpty("QMAKE_FRAMEWORK_BUNDLE_NAME"))
index 2cf774e..b177cc7 100644 (file)
@@ -91,6 +91,8 @@ class MakefileGenerator : protected QMakeSourceFileInfo
     mutable QHash<ReplaceExtraCompilerCacheKey, QString> extraCompilerVariablesCache;
 
 protected:
+    enum TARG_MODE { TARG_UNIX_MODE, TARG_MACX_MODE, TARG_WIN_MODE } target_mode;
+
     QStringList createObjectList(const QStringList &sources);
 
     //makefile style generator functions
index 54ab475..4203050 100644 (file)
@@ -514,28 +514,5 @@ MetaMakefileGenerator::createMetaGenerator(QMakeProject *proj, const QString &na
 
 #endif // QT_QMAKE_PARSER_ONLY
 
-bool
-MetaMakefileGenerator::modeForGenerator(const QString &gen, Option::TARG_MODE *target_mode)
-{
-    if (gen == "UNIX") {
-#ifdef Q_OS_MAC
-        *target_mode = Option::TARG_MACX_MODE;
-#else
-        *target_mode = Option::TARG_UNIX_MODE;
-#endif
-    } else if (gen == "MSVC.NET" || gen == "BMAKE" || gen == "MSBUILD") {
-        *target_mode = Option::TARG_WIN_MODE;
-    } else if (gen == "MINGW") {
-        *target_mode = Option::TARG_WIN_MODE;
-    } else if (gen == "PROJECTBUILDER" || gen == "XCODE") {
-        *target_mode = Option::TARG_MACX_MODE;
-    } else if (gen == "GBUILD") {
-        *target_mode = Option::TARG_UNIX_MODE;
-    } else {
-        fprintf(stderr, "Unknown generator specified: %s\n", gen.toLatin1().constData());
-        return false;
-    }
-    return true;
-}
 
 QT_END_NAMESPACE
index a6889fd..846a798 100644 (file)
@@ -42,8 +42,6 @@
 #ifndef METAMAKEFILE_H
 #define METAMAKEFILE_H
 
-#include <option.h>
-
 #include <qlist.h>
 #include <qstring.h>
 
@@ -67,8 +65,6 @@ public:
     static MetaMakefileGenerator *createMetaGenerator(QMakeProject *proj, const QString &name, bool op=true, bool *success = 0);
     static MakefileGenerator *createMakefileGenerator(QMakeProject *proj, bool noIO = false);
 
-    static bool modeForGenerator(const QString &generator, Option::TARG_MODE *target_mode);
-
     inline QMakeProject *projectFile() const { return project; }
 
     virtual bool init() = 0;
index b8b4f1b..02f8666 100644 (file)
@@ -491,9 +491,9 @@ UnixMakefileGenerator::findLibraries()
                     } else {
                         stub = opt.mid(2);
                     }
-                } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) {
+                } else if (target_mode == TARG_MACX_MODE && opt.startsWith("-F")) {
                     frameworkdirs.append(QMakeLocalFileName(opt.right(opt.length()-2)));
-                } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
+                } else if (target_mode == TARG_MACX_MODE && opt.startsWith("-framework")) {
                     if(opt.length() > 11) {
                         opt = opt.mid(11);
                     } else {
@@ -612,11 +612,11 @@ UnixMakefileGenerator::processPrlFiles()
                             break;
                         }
                     }
-                } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) {
+                } else if (target_mode == TARG_MACX_MODE && opt.startsWith("-F")) {
                     QMakeLocalFileName f(opt.right(opt.length()-2));
                     if(!frameworkdirs.contains(f))
                         frameworkdirs.append(f);
-                } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
+                } else if (target_mode == TARG_MACX_MODE && opt.startsWith("-framework")) {
                     if(opt.length() > 11)
                         opt = opt.mid(11);
                     else
@@ -655,7 +655,7 @@ UnixMakefileGenerator::processPrlFiles()
                 QString arch("default");
                 QString opt = l.at(lit).trimmed();
                 if(opt.startsWith("-")) {
-                    if (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-Xarch")) {
+                    if (target_mode == TARG_MACX_MODE && opt.startsWith("-Xarch")) {
                         if (opt.length() > 7) {
                             arch = opt.mid(7);
                             opt = l.at(++lit);
@@ -663,7 +663,7 @@ UnixMakefileGenerator::processPrlFiles()
                     }
 
                     if(opt.startsWith("-L") ||
-                       (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F"))) {
+                       (target_mode == TARG_MACX_MODE && opt.startsWith("-F"))) {
                         if(!lflags[arch].contains(opt))
                             lflags[arch].append(opt);
                     } else if(opt.startsWith("-l") || opt == "-pthread") {
@@ -671,12 +671,12 @@ UnixMakefileGenerator::processPrlFiles()
                         if (lflags[arch].contains(opt))
                             lflags[arch].removeAll(opt);
                         lflags[arch].append(opt);
-                    } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) {
+                    } else if (target_mode == TARG_MACX_MODE && opt.startsWith("-framework")) {
                         if(opt.length() > 11)
                             opt = opt.mid(11);
                         else {
                             opt = l.at(++lit);
-                            if (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-Xarch"))
+                            if (target_mode == TARG_MACX_MODE && opt.startsWith("-Xarch"))
                                 opt = l.at(++lit); // The user has done the right thing and prefixed each part
                         }
                         bool found = false;
@@ -838,8 +838,7 @@ UnixMakefileGenerator::defaultInstall(const QString &t)
             uninst.append("-$(DEL_FILE) \"" + dst_targ + "\"");
         if(!links.isEmpty()) {
             for(int i = 0; i < links.size(); ++i) {
-                if(Option::target_mode == Option::TARG_UNIX_MODE ||
-                   Option::target_mode == Option::TARG_MACX_MODE) {
+                if (target_mode == TARG_UNIX_MODE || target_mode == TARG_MACX_MODE) {
                     QString link = Option::fixPathToTargetOS(destdir + links[i], false);
                     int lslash = link.lastIndexOf(Option::dir_sep);
                     if(lslash != -1)
index 4d97d4d..aaf9b55 100644 (file)
@@ -93,7 +93,6 @@ QString Option::user_template;
 QString Option::user_template_prefix;
 QStringList Option::shellPath;
 Option::HOST_MODE Option::host_mode = Option::HOST_UNKNOWN_MODE;
-Option::TARG_MODE Option::target_mode = Option::TARG_UNKNOWN_MODE;
 
 //QMAKE_*_PROPERTY stuff
 QStringList Option::prop::properties;
@@ -557,14 +556,6 @@ Option::init(int argc, char **argv)
             }
 #endif
         }
-    } else if (Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
-#if defined(Q_OS_MAC)
-        Option::target_mode = Option::TARG_MACX_MODE;
-#elif defined(Q_OS_UNIX)
-        Option::target_mode = Option::TARG_UNIX_MODE;
-#else
-        Option::target_mode = Option::TARG_WIN_MODE;
-#endif
     }
 
     //defaults for globals
index 09922e9..32bc06b 100644 (file)
@@ -173,8 +173,6 @@ struct Option
     static QStringList before_user_vars, after_user_vars;
     enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE };
     static HOST_MODE host_mode;
-    enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE };
-    static TARG_MODE target_mode;
     static QString user_template, user_template_prefix;
     static QStringList shellPath;
 
index e7aee48..a9d4042 100644 (file)
@@ -565,28 +565,14 @@ static void qmake_error_msg(const QString &msg)
    1) features/(unix|win32|macx)/
    2) features/
 */
-QStringList qmake_feature_paths(QMakeProperty *prop, bool host_build)
+QStringList QMakeProject::qmakeFeaturePaths()
 {
     const QString mkspecs_concat = QLatin1String("/mkspecs");
     const QString base_concat = QLatin1String("/features");
     QStringList concat;
-    {
-        switch(Option::target_mode) {
-        case Option::TARG_MACX_MODE:                     //also a unix
-            concat << base_concat + QLatin1String("/mac");
-            concat << base_concat + QLatin1String("/macx");
-            concat << base_concat + QLatin1String("/unix");
-            break;
-        default: // Can't happen, just make the compiler shut up
-        case Option::TARG_UNIX_MODE:
-            concat << base_concat + QLatin1String("/unix");
-            break;
-        case Option::TARG_WIN_MODE:
-            concat << base_concat + QLatin1String("/win32");
-            break;
-        }
-        concat << base_concat;
-    }
+    foreach (const QString &sfx, values("QMAKE_PLATFORM"))
+        concat << base_concat + QLatin1Char('/') + sfx;
+    concat << base_concat;
 
     QStringList feature_roots = splitPathList(QString::fromLocal8Bit(qgetenv("QMAKEFEATURES")));
     feature_roots += cached_qmakefeatures;
@@ -1489,7 +1475,8 @@ QMakeProject::read(uchar cmd)
                 return false;
             }
             doProjectInclude("spec_post", IncludeFlagFeature, vars);
-            validateModes();
+            // The spec extends the feature search path, so invalidate the cache.
+            invalidateFeatureRoots();
 
             if (!conffile.isEmpty()) {
                 debug_msg(1, "Project config file: reading %s", conffile.toLatin1().constData());
@@ -1607,34 +1594,6 @@ QMakeProject::read(uchar cmd)
     return true;
 }
 
-void QMakeProject::validateModes()
-{
-    if (Option::target_mode == Option::TARG_UNKNOWN_MODE) {
-        Option::TARG_MODE target_mode;
-        const QStringList &gen = vars.value("MAKEFILE_GENERATOR");
-        if (gen.isEmpty()) {
-            fprintf(stderr, "%s:%d: Using OS scope before setting MAKEFILE_GENERATOR\n",
-                            parser.file.toLatin1().constData(), parser.line_no);
-        } else if (MetaMakefileGenerator::modeForGenerator(gen.first(), &target_mode)) {
-            const QStringList &tgt = vars.value("TARGET_PLATFORM");
-            if (!tgt.isEmpty()) {
-                const QString &os = tgt.first();
-                if (os == "unix")
-                    Option::target_mode = Option::TARG_UNIX_MODE;
-                else if (os == "macx")
-                    Option::target_mode = Option::TARG_MACX_MODE;
-                else if (os == "win32")
-                    Option::target_mode = Option::TARG_WIN_MODE;
-                else
-                    fprintf(stderr, "Unknown target platform specified: %s\n",
-                            os.toLatin1().constData());
-            } else {
-                Option::target_mode = target_mode;
-            }
-        }
-    }
-}
-
 void
 QMakeProject::resolveSpec(QString *spec, const QString &qmakespec)
 {
@@ -1677,18 +1636,6 @@ QMakeProject::isActiveConfig(const QString &x, bool regex, QHash<QString, QStrin
     else if(x == "false")
         return false;
 
-    if (x == "unix") {
-        validateModes();
-        return Option::target_mode == Option::TARG_UNIX_MODE
-               || Option::target_mode == Option::TARG_MACX_MODE;
-    } else if (x == "macx" || x == "mac") {
-        validateModes();
-        return Option::target_mode == Option::TARG_MACX_MODE;
-    } else if (x == "win32") {
-        validateModes();
-        return Option::target_mode == Option::TARG_WIN_MODE;
-    }
-
     if (x == "host_build")
         return host_build;
 
@@ -1758,7 +1705,7 @@ QMakeProject::doProjectInclude(QString file, uchar flags, QHash<QString, QString
                 qmakeAddCacheClear(qmakeDeleteCacheClear<QStringList>, (void**)&feature_roots);
             }
             if (feature_roots->isEmpty())
-                *feature_roots = qmake_feature_paths(prop, host_build);
+                *feature_roots = qmakeFeaturePaths();
             debug_msg(2, "Looking for feature '%s' in (%s)", file.toLatin1().constData(),
                        feature_roots->join("::").toLatin1().constData());
             int start_root = 0;
index e733f60..4ee6a02 100644 (file)
@@ -114,8 +114,8 @@ class QMakeProject
     void init(QMakeProperty *);
     void cleanup();
     QStringList &values(const QString &v, QHash<QString, QStringList> &place);
-    void validateModes();
     void resolveSpec(QString *spec, const QString &qmakespec);
+    QStringList qmakeFeaturePaths();
 
 public:
     QMakeProject(QMakeProperty *p = 0) { init(p); }