From 5c92a8b70a0349cc13a0758ef674cf817fc41381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 14 Oct 2013 15:09:00 +0200 Subject: [PATCH] Xcode: Dynamically choose release/debug libs based on current configuration Non-framework builds would automatically link to whatever Qt library matched the config at the time of running qmake, eg hard-coded to libQtCore_debug, while Xcode itself allowed the user to switch between release and debug configurations. We now append an Xcode settings variable to the library path, which gets resolved at build time depending on the current config in Xcode. Change-Id: I12873e38a28d9595ef3fd0ae0ad849e6744833a9 Reviewed-by: Oswald Buddenhagen Reviewed-by: Andy Shaw --- mkspecs/features/mac/default_pre.prf | 6 +++++ mkspecs/features/resolve_config.prf | 37 ++++++++++++++++++++++----- qmake/generators/mac/pbuilder_pbx.cpp | 14 ++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/mkspecs/features/mac/default_pre.prf b/mkspecs/features/mac/default_pre.prf index e535c4d9e9d..c0596d5ef04 100644 --- a/mkspecs/features/mac/default_pre.prf +++ b/mkspecs/features/mac/default_pre.prf @@ -23,3 +23,9 @@ isEmpty(QMAKE_XCODE_VERSION) { isEmpty(QMAKE_XCODE_VERSION): error("Could not resolve Xcode version.") unset(xcode_version) } + +# These two variables are used by the xcode_dynamic_library_suffix +# feature, which allows Xcode to choose the Qt libraries to link to +# at build time, depending on the current Xcode SDK and configuration. +QMAKE_XCODE_LIBRARY_SUFFIX = $$qtPlatformTargetSuffix() +QMAKE_XCODE_LIBRARY_SUFFIX_SETTING = QT_LIBRARY_SUFFIX diff --git a/mkspecs/features/resolve_config.prf b/mkspecs/features/resolve_config.prf index 41e82b23821..3884598a941 100644 --- a/mkspecs/features/resolve_config.prf +++ b/mkspecs/features/resolve_config.prf @@ -36,11 +36,34 @@ CONFIG(debug, debug|release): \ else: \ CONFIG -= debug -debug_and_release { - !macx-xcode: addExclusiveBuilds(debug, Debug, release, Release) -} else: fix_output_dirs { - debug: \ - fixExclusiveOutputDirs(debug, release) - else: \ - fixExclusiveOutputDirs(release, debug) +!macx-xcode { + debug_and_release { + addExclusiveBuilds(debug, Debug, release, Release) + } else: fix_output_dirs { + debug: \ + fixExclusiveOutputDirs(debug, release) + else: \ + fixExclusiveOutputDirs(release, debug) + } +} else { + # The Xcode generator always generates project files with + # debug and release configurations, regardless of whether + # or not debug_and_release is active. + for(build, $$list(debug release)) { + suffix = + contains(QT_CONFIG, debug_and_release) { + equals(build, debug): \ + suffix = _debug + } else { + contains(QT_CONFIG, debug): \ + suffix = _debug + } + + library_suffix_$${build}.name = $$QMAKE_XCODE_LIBRARY_SUFFIX_SETTING + library_suffix_$${build}.value = $$suffix + library_suffix_$${build}.build = $$build + QMAKE_MAC_XCODE_SETTINGS += library_suffix_$${build} + + CONFIG *= xcode_dynamic_library_suffix + } } diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp index ac9e4cc71aa..03887e79387 100644 --- a/qmake/generators/mac/pbuilder_pbx.cpp +++ b/qmake/generators/mac/pbuilder_pbx.cpp @@ -874,6 +874,20 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) debug_msg(1, "pbuilder: Found library (%s) via PRL %s (%s)", opt.toLatin1().constData(), lib_file.toLatin1().constData(), library.toLatin1().constData()); remove = true; + + if (project->isActiveConfig("xcode_dynamic_library_suffix")) { + QString suffixSetting = project->first("QMAKE_XCODE_LIBRARY_SUFFIX_SETTING").toQString(); + if (!suffixSetting.isEmpty()) { + QString librarySuffix = project->first("QMAKE_XCODE_LIBRARY_SUFFIX").toQString(); + suffixSetting = "$(" + suffixSetting + ")"; + if (!librarySuffix.isEmpty()) { + library = library.replace(librarySuffix, suffixSetting); + name = name.remove(librarySuffix); + } else { + library = library.replace(name, name + suffixSetting); + } + } + } } } }