diff --git a/mkspecs/macx-xcode/WorkspaceSettings.xcsettings b/mkspecs/macx-xcode/WorkspaceSettings.xcsettings new file mode 100644 index 00000000000..08de0be8d3c --- /dev/null +++ b/mkspecs/macx-xcode/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded + + + diff --git a/mkspecs/macx-xcode/default.xcscheme b/mkspecs/macx-xcode/default.xcscheme new file mode 100644 index 00000000000..53c736cc15f --- /dev/null +++ b/mkspecs/macx-xcode/default.xcscheme @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mkspecs/macx-xcode/qmake.conf b/mkspecs/macx-xcode/qmake.conf index fde682b64b9..6fc6160ec7f 100644 --- a/mkspecs/macx-xcode/qmake.conf +++ b/mkspecs/macx-xcode/qmake.conf @@ -6,6 +6,8 @@ QMAKESPEC = $$dirname(PWD)/$$[QMAKE_XSPEC] +QMAKE_XCODE_SPECDIR = $$PWD + include($$QMAKESPEC/qmake.conf) MAKEFILE_GENERATOR = XCODE diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp index 36ec6ef7423..e2b5f5f90b9 100644 --- a/qmake/generators/mac/pbuilder_pbx.cpp +++ b/qmake/generators/mac/pbuilder_pbx.cpp @@ -1573,6 +1573,52 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) } } + // Scheme + { + QString xcodeSpecDir = project->first("QMAKE_XCODE_SPECDIR").toQString(); + + bool wroteCustomScheme = false; + + QString projectSharedSchemesPath = pbx_dir + "/xcshareddata/xcschemes"; + if (mkdir(projectSharedSchemesPath)) { + QString target = project->first("QMAKE_ORIG_TARGET").toQString(); + + QFile defaultSchemeFile(xcodeSpecDir + "/default.xcscheme"); + QFile outputSchemeFile(projectSharedSchemesPath + Option::dir_sep + target + ".xcscheme"); + + if (defaultSchemeFile.open(QIODevice::ReadOnly) + && outputSchemeFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + + QTextStream defaultSchemeStream(&defaultSchemeFile); + QString schemeData = defaultSchemeStream.readAll(); + + schemeData.replace("@QMAKE_ORIG_TARGET@", target); + schemeData.replace("@TARGET_PBX_KEY@", keyFor(pbx_dir + "QMAKE_PBX_TARGET")); + + QTextStream outputSchemeStream(&outputSchemeFile); + outputSchemeStream << schemeData; + + wroteCustomScheme = true; + } + } + + if (wroteCustomScheme) { + // Prevent Xcode from auto-generating schemes + QString workspaceSettingsFilename("WorkspaceSettings.xcsettings"); + QString workspaceSharedDataPath = pbx_dir + "/project.xcworkspace/xcshareddata"; + if (mkdir(workspaceSharedDataPath)) { + QFile::copy(xcodeSpecDir + Option::dir_sep + workspaceSettingsFilename, + workspaceSharedDataPath + Option::dir_sep + workspaceSettingsFilename); + } else { + wroteCustomScheme = false; + } + } + + if (!wroteCustomScheme) + warn_msg(WarnLogic, "Failed to generate schemes in '%s', " \ + "falling back to Xcode auto-generated schemes", qPrintable(projectSharedSchemesPath)); + } + qmake_setpwd(input_dir); return true;