Make it possible to undefine NDEBUG for nmake and VS projects

For nmake and VS projects we added the NDEBUG define for the release
configuration unconditionally within the qmake generators. To undefine
it, users had to use a nasty work-around.

Now, define NDEBUG within the MSVC mkspecs. In order to do that we
introduce the DEFINES_RELEASE and DEFINES_DEBUG variables that are
merged into DEFINES in default_pre.prf.

Users can unset NDEBUG by writing
    DEFINES -= NDEBUG
in their .pro file.

Note that DEFINES_RELEASE and DEFINES_DEBUG are merged in
default_pre.prf in order to give extra compilers (like moc) the chance
to see the fully resolved DEFINES variable. This is different from the
QMAKE_CFLAGS_(DEBUG|RELEASE) variables that get merged in default_post.prf.

Fixes: QTBUG-78071
Change-Id: I381770a1d2f974fbae9b09a2254e3f2fc7842b68
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
bb10
Joerg Bornemann 2019-09-12 10:27:16 +02:00
parent 983cfc773d
commit 1456b8091a
7 changed files with 28 additions and 8 deletions

View File

@ -19,6 +19,7 @@ CONFIG += flat debug_and_release debug_and_release_target precom
# MSVC 2017 15.8+ fixed std::aligned_storage but compilation fails without
# _ENABLE_EXTENDED_ALIGNED_STORAGE flag since the fix breaks binary compatibility.
DEFINES += UNICODE _UNICODE WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE
DEFINES_RELEASE += NDEBUG
QMAKE_COMPILER_DEFINES += _WIN32
contains(QMAKE_TARGET.arch, x86_64) {
DEFINES += WIN64

View File

@ -11,6 +11,7 @@ CONFIG = package_manifest $$CONFIG incremental flat precompile_
# MSVC 2017 15.8+ fixed std::aligned_storage but compilation fails without
# _ENABLE_EXTENDED_ALIGNED_STORAGE flag since the fix breaks binary compatibility.
DEFINES += UNICODE WIN32 QT_LARGEFILE_SUPPORT Q_BYTE_ORDER=Q_LITTLE_ENDIAN _ENABLE_EXTENDED_ALIGNED_STORAGE
DEFINES_RELEASE += NDEBUG
QMAKE_COMPILER_DEFINES += _WIN32
DEPLOYMENT_PLUGIN += qwinrt

View File

@ -26,4 +26,10 @@ CONFIG = \
unset(today)
}
CONFIG(debug, debug|release) {
DEFINES += $$DEFINES_DEBUG
} else {
DEFINES += $$DEFINES_RELEASE
}
load(toolchain)

View File

@ -1144,6 +1144,26 @@
\snippet code/doc_src_qmake-manual.pro 27
\target DEFINES_DEBUG
\section1 DEFINES_DEBUG
Specifies preprocessor defines for the debug configuration. The values of
this variable get added to \l{DEFINES} before the project is loaded. This
variable is typically set in \l{#QMAKESPEC}{qmake.conf} and rarely needs
to be modified.
This variable was introduced in Qt 5.13.2.
\target DEFINES_RELEASE
\section1 DEFINES_RELEASE
Specifies preprocessor defines for the release configuration. The values of
this variable get added to \l{DEFINES} before the project is loaded. This
variable is typically set in \l{#QMAKESPEC}{qmake.conf} and rarely needs
to be modified.
This variable was introduced in Qt 5.13.2.
\target DEF_FILE
\section1 DEF_FILE

View File

@ -281,10 +281,6 @@ void NmakeMakefileGenerator::init()
if (project->isActiveConfig("debug")) {
project->values("QMAKE_CLEAN").append(targetBase + ".ilk");
project->values("QMAKE_CLEAN").append(targetBase + ".idb");
} else {
ProStringList &defines = project->values("DEFINES");
if (!defines.contains("NDEBUG"))
defines.append("NDEBUG");
}
if (project->values("QMAKE_APP_FLAG").isEmpty() && project->isActiveConfig("dll")) {

View File

@ -2125,7 +2125,6 @@ VCResourceCompilerTool::VCResourceCompilerTool()
ShowProgress(linkProgressNotSet),
SuppressStartupBanner(unset)
{
PreprocessorDefinitions = QStringList("NDEBUG");
}
// VCDeploymentTool --------------------------------------------

View File

@ -1038,9 +1038,6 @@ void VcprojGenerator::initConfiguration()
initDeploymentTool();
initWinDeployQtTool();
initPreLinkEventTools();
if (!isDebug)
conf.compiler.PreprocessorDefinitions += "NDEBUG";
}
void VcprojGenerator::initCompilerTool()