forked from qt-creator/qt-creator
CMake: Make CMakeConfig a proper class
Looks a bit more "object oriented" in my book. Change-Id: I6a3b1b4691ec1c7465f652608678e8f31e7e52a7 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -135,20 +135,16 @@ QStringList CMakeProjectImporter::importCandidates()
|
||||
static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
||||
{
|
||||
// Qt4 way to define things (more convenient for us, so try this first;-)
|
||||
FilePath qmake
|
||||
= FilePath::fromUtf8(CMakeConfigItem::valueOf(QByteArray("QT_QMAKE_EXECUTABLE"), config));
|
||||
const FilePath qmake = config.filePathValueOf("QT_QMAKE_EXECUTABLE");
|
||||
qCDebug(cmInputLog) << "QT_QMAKE_EXECUTABLE=" << qmake.toUserOutput();
|
||||
if (!qmake.isEmpty())
|
||||
return qmake;
|
||||
|
||||
// Check Qt5 settings: oh, the horror!
|
||||
const FilePath qtCMakeDir = [config] {
|
||||
FilePath tmp = FilePath::fromUtf8(
|
||||
CMakeConfigItem::valueOf(QByteArray("Qt5Core_DIR"), config));
|
||||
if (tmp.isEmpty()) {
|
||||
tmp = FilePath::fromUtf8(
|
||||
CMakeConfigItem::valueOf(QByteArray("Qt6Core_DIR"), config));
|
||||
}
|
||||
FilePath tmp = config.filePathValueOf("Qt5Core_DIR");
|
||||
if (tmp.isEmpty())
|
||||
tmp = config.filePathValueOf("Qt6Core_DIR");
|
||||
return tmp;
|
||||
}();
|
||||
qCDebug(cmInputLog) << "QtXCore_DIR=" << qtCMakeDir.toUserOutput();
|
||||
@@ -206,11 +202,11 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
||||
cmake.setEnvironment(env);
|
||||
cmake.setTimeOutMessageBoxEnabled(false);
|
||||
|
||||
QString cmakeGenerator = CMakeConfigItem::stringValueOf(QByteArray("CMAKE_GENERATOR"), config);
|
||||
FilePath cmakeExecutable = CMakeConfigItem::filePathValueOf(QByteArray("CMAKE_COMMAND"), config);
|
||||
FilePath cmakeMakeProgram =CMakeConfigItem::filePathValueOf(QByteArray("CMAKE_MAKE_PROGRAM"), config);
|
||||
FilePath toolchainFile = CMakeConfigItem::filePathValueOf(QByteArray("CMAKE_TOOLCHAIN_FILE"), config);
|
||||
FilePath hostPath = CMakeConfigItem::filePathValueOf(QByteArray("QT_HOST_PATH"), config);
|
||||
QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR"));
|
||||
FilePath cmakeExecutable = config.filePathValueOf(QByteArray("CMAKE_COMMAND"));
|
||||
FilePath cmakeMakeProgram = config.filePathValueOf(QByteArray("CMAKE_MAKE_PROGRAM"));
|
||||
FilePath toolchainFile = config.filePathValueOf(QByteArray("CMAKE_TOOLCHAIN_FILE"));
|
||||
FilePath hostPath = config.filePathValueOf(QByteArray("QT_HOST_PATH"));
|
||||
|
||||
QStringList args;
|
||||
args.push_back("-S");
|
||||
@@ -270,7 +266,7 @@ static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfi
|
||||
}
|
||||
|
||||
if (!haveCCxxCompiler) {
|
||||
const QByteArray generator = CMakeConfigItem::valueOf(QByteArray("CMAKE_GENERATOR"), config);
|
||||
const QByteArray generator = config.valueOf("CMAKE_GENERATOR");
|
||||
QString cCompilerName;
|
||||
QString cxxCompilerName;
|
||||
if (generator.contains("Visual Studio")) {
|
||||
@@ -282,8 +278,7 @@ static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfi
|
||||
}
|
||||
|
||||
if (!cCompilerName.isEmpty() && !cxxCompilerName.isEmpty()) {
|
||||
const FilePath linker = FilePath::fromUtf8(
|
||||
CMakeConfigItem::valueOf(QByteArray("CMAKE_LINKER"), config));
|
||||
const FilePath linker = config.filePathValueOf("CMAKE_LINKER");
|
||||
if (!linker.isEmpty()) {
|
||||
const FilePath compilerPath = linker.parentDir();
|
||||
result.append({compilerPath.pathAppended(cCompilerName),
|
||||
@@ -315,13 +310,11 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
return { };
|
||||
}
|
||||
|
||||
QByteArrayList buildConfigurationTypes = {CMakeConfigItem::valueOf("CMAKE_BUILD_TYPE", config)};
|
||||
QByteArrayList buildConfigurationTypes = {config.valueOf("CMAKE_BUILD_TYPE")};
|
||||
if (buildConfigurationTypes.front().isEmpty()) {
|
||||
QByteArray buildConfigurationTypesString =
|
||||
CMakeConfigItem::valueOf("CMAKE_CONFIGURATION_TYPES", config);
|
||||
if (!buildConfigurationTypesString.isEmpty()) {
|
||||
QByteArray buildConfigurationTypesString = config.valueOf("CMAKE_CONFIGURATION_TYPES");
|
||||
if (!buildConfigurationTypesString.isEmpty())
|
||||
buildConfigurationTypes = buildConfigurationTypesString.split(';');
|
||||
}
|
||||
}
|
||||
|
||||
QList<void *> result;
|
||||
@@ -329,7 +322,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
auto data = std::make_unique<DirectoryData>();
|
||||
|
||||
data->cmakeHomeDirectory =
|
||||
FilePath::fromUserInput(CMakeConfigItem::stringValueOf("CMAKE_HOME_DIRECTORY", config))
|
||||
FilePath::fromUserInput(config.stringValueOf("CMAKE_HOME_DIRECTORY"))
|
||||
.canonicalPath();
|
||||
const FilePath canonicalProjectDirectory = projectDirectory().canonicalPath();
|
||||
if (data->cmakeHomeDirectory != canonicalProjectDirectory) {
|
||||
@@ -344,12 +337,12 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
data->buildDirectory = importPath;
|
||||
data->cmakeBuildType = buildType;
|
||||
|
||||
data->cmakeBinary = CMakeConfigItem::filePathValueOf("CMAKE_COMMAND", config);
|
||||
data->generator = CMakeConfigItem::stringValueOf("CMAKE_GENERATOR", config);
|
||||
data->extraGenerator = CMakeConfigItem::stringValueOf("CMAKE_EXTRA_GENERATOR", config);
|
||||
data->platform = CMakeConfigItem::stringValueOf("CMAKE_GENERATOR_PLATFORM", config);
|
||||
data->toolset = CMakeConfigItem::stringValueOf("CMAKE_GENERATOR_TOOLSET", config);
|
||||
data->sysroot = CMakeConfigItem::filePathValueOf("CMAKE_SYSROOT", config);
|
||||
data->cmakeBinary = config.filePathValueOf("CMAKE_COMMAND");
|
||||
data->generator = config.stringValueOf("CMAKE_GENERATOR");
|
||||
data->extraGenerator = config.stringValueOf("CMAKE_EXTRA_GENERATOR");
|
||||
data->platform = config.stringValueOf("CMAKE_GENERATOR_PLATFORM");
|
||||
data->toolset = config.stringValueOf("CMAKE_GENERATOR_TOOLSET");
|
||||
data->sysroot = config.filePathValueOf("CMAKE_SYSROOT");
|
||||
|
||||
// Qt:
|
||||
const FilePath qmake = qmakeFromCMakeCache(config);
|
||||
|
||||
Reference in New Issue
Block a user