forked from qt-creator/qt-creator
CMakePM: Set platform codegen and linker flags for GCC compilers
If a GCC compiler has platform codegen flags they will be set into CMAKE_C_FLAGS_INIT or CMAKE_CXX_FLAGS_INIT initial CMake parameters. The linker flags are set they will be set into CMAKE_EXE_LINKER_FLAGS_INIT, CMAKE_MODULE_LINKER_FLAGS_INIT and CMAKE_SHARED_LINKER_FLAGS_INIT initial CMake parameters. If the kit has a Qt the CMAKE_CXX_FLAGS_INIT value will merge both GCC C++ platform codegen flags and the QML Debugging flags. Fixes: QTCREATORBUG-24420 Change-Id: I066d30b816ae8575f615654bb85bd82a394f9737 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
#include <projectexplorer/environmentaspectwidget.h>
|
#include <projectexplorer/environmentaspectwidget.h>
|
||||||
#include <projectexplorer/environmentwidget.h>
|
#include <projectexplorer/environmentwidget.h>
|
||||||
|
#include <projectexplorer/gcctoolchain.h>
|
||||||
#include <projectexplorer/kitaspects.h>
|
#include <projectexplorer/kitaspects.h>
|
||||||
#include <projectexplorer/namedwidget.h>
|
#include <projectexplorer/namedwidget.h>
|
||||||
#include <projectexplorer/processparameters.h>
|
#include <projectexplorer/processparameters.h>
|
||||||
@@ -1176,6 +1177,30 @@ static CommandLine defaultInitialCMakeCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GCC compiler and linker specific flags
|
||||||
|
for (Toolchain *tc : ToolchainKitAspect::toolChains(k)) {
|
||||||
|
if (auto *gccTc = tc->asGccToolchain()) {
|
||||||
|
const QStringList compilerFlags = gccTc->platformCodeGenFlags();
|
||||||
|
|
||||||
|
QString language;
|
||||||
|
if (gccTc->language() == ProjectExplorer::Constants::C_LANGUAGE_ID)
|
||||||
|
language = "C";
|
||||||
|
else if (gccTc->language() == ProjectExplorer::Constants::CXX_LANGUAGE_ID)
|
||||||
|
language = "CXX";
|
||||||
|
|
||||||
|
if (!language.isEmpty() && !compilerFlags.isEmpty())
|
||||||
|
cmd.addArg("-DCMAKE_" + language + "_FLAGS_INIT:STRING=" + compilerFlags.join(" "));
|
||||||
|
|
||||||
|
const QStringList linkerFlags = gccTc->platformLinkerFlags();
|
||||||
|
if (!linkerFlags.isEmpty()) {
|
||||||
|
const QString joinedLinkerFlags = linkerFlags.join(" ");
|
||||||
|
cmd.addArg("-DCMAKE_EXE_LINKER_FLAGS_INIT:STRING=" + joinedLinkerFlags);
|
||||||
|
cmd.addArg("-DCMAKE_MODULE_LINKER_FLAGS_INIT:STRING=" + joinedLinkerFlags);
|
||||||
|
cmd.addArg("-DCMAKE_SHARED_LINKER_FLAGS_INIT:STRING=" + joinedLinkerFlags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd.addArgs(CMakeConfigurationKitAspect::toArgumentsList(k));
|
cmd.addArgs(CMakeConfigurationKitAspect::toArgumentsList(k));
|
||||||
cmd.addArgs(CMakeConfigurationKitAspect::additionalConfiguration(k), CommandLine::Raw);
|
cmd.addArgs(CMakeConfigurationKitAspect::additionalConfiguration(k), CommandLine::Raw);
|
||||||
|
|
||||||
@@ -2163,9 +2188,20 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis
|
|||||||
if (!cmakeGenerator.isEmpty())
|
if (!cmakeGenerator.isEmpty())
|
||||||
arguments.append(cmakeGenerator);
|
arguments.append(cmakeGenerator);
|
||||||
|
|
||||||
m_cmakeConfiguration = CMakeConfig::fromArguments(arguments, additionalOptions);
|
CMakeConfig config = CMakeConfig::fromArguments(arguments, additionalOptions);
|
||||||
for (CMakeConfigItem &ci : m_cmakeConfiguration)
|
// Join CMAKE_CXX_FLAGS_INIT values if more entries are present, or skip the same
|
||||||
|
// values like CMAKE_EXE_LINKER_FLAGS_INIT coming from both C and CXX compilers
|
||||||
|
QHash<QByteArray, CMakeConfigItem> uniqueConfig;
|
||||||
|
for (CMakeConfigItem &ci : config) {
|
||||||
ci.isInitial = true;
|
ci.isInitial = true;
|
||||||
|
if (uniqueConfig.contains(ci.key)) {
|
||||||
|
if (uniqueConfig[ci.key].value != ci.value)
|
||||||
|
uniqueConfig[ci.key].value = uniqueConfig[ci.key].value + " " + ci.value;
|
||||||
|
} else {
|
||||||
|
uniqueConfig.insert(ci.key, ci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_cmakeConfiguration = uniqueConfig.values();
|
||||||
|
|
||||||
// Display the unknown arguments in "Additional CMake Options"
|
// Display the unknown arguments in "Additional CMake Options"
|
||||||
const QString additionalOptionsValue = ProcessArgs::joinArgs(additionalOptions);
|
const QString additionalOptionsValue = ProcessArgs::joinArgs(additionalOptions);
|
||||||
|
Reference in New Issue
Block a user