From 543929cd2c0550314957b0db6a73bca2c04e7341 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 22 Jun 2017 13:53:48 +0200 Subject: [PATCH] CMake: Warn when doing out-of-source builds with in-source configuration Warn when attempting to do an out-of-source build while an in-source build is configured. This seems to confuse cmake. Task-number: QTCREATORBUG-18381 Change-Id: I1abd3be4129ba5af6439dcd60d16d429b93c0382 Reviewed-by: Tim Jenssen --- .../cmakeprojectmanager/cmakebuildstep.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index c5f1b6a8f38..ff2a3d2c9a6 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -217,6 +217,22 @@ bool CMakeBuildStep::init(QList &earlierSteps) return false; } + // Warn if doing out-of-source builds with a CMakeCache.txt is the source directory + const Utils::FileName projectDirectory = bc->target()->project()->projectDirectory(); + if (bc->buildDirectory() != projectDirectory) { + Utils::FileName cmc = projectDirectory; + cmc.appendPath("CMakeCache.txt"); + if (cmc.exists()) { + emit addTask(Task(Task::Warning, + tr("There is a CMakeCache.txt file in \"%1\", which suggest an " + "in-source build was done before. You are now building in \"%2\", " + "and the CMakeCache.txt file might confuse CMake.") + .arg(projectDirectory.toUserOutput(), bc->buildDirectory().toUserOutput()), + Utils::FileName(), -1, + ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)); + } + } + QString arguments = allArguments(rc); setIgnoreReturnValue(m_buildTarget == CMakeBuildStep::cleanTarget());