diff --git a/projectbuilders/cmakebuilder/cmakejob.cpp b/projectbuilders/cmakebuilder/cmakejob.cpp --- a/projectbuilders/cmakebuilder/cmakejob.cpp +++ b/projectbuilders/cmakebuilder/cmakejob.cpp @@ -82,7 +82,11 @@ QStringList CMakeJob::commandLine() const { QStringList args; - args << CMakeBuilderSettings::self()->cmakeExecutable().toLocalFile(); + QString cmakeProjectExecutable = CMake::currentCmakeExecutable( m_project ); + args << + (cmakeProjectExecutable.isEmpty() ? + CMakeBuilderSettings::self()->cmakeExecutable().toLocalFile() : cmakeProjectExecutable); + args << QStringLiteral("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"); QString installDir = CMake::currentInstallDir( m_project ).toLocalFile(); diff --git a/projectmanagers/cmake/cmakeutils.h b/projectmanagers/cmake/cmakeutils.h --- a/projectmanagers/cmake/cmakeutils.h +++ b/projectmanagers/cmake/cmakeutils.h @@ -104,6 +104,11 @@ */ KDEVCMAKECOMMON_EXPORT QString currentBuildType( KDevelop::IProject* project, int builddir = -1 ); + /** + * @returns the current build type for the given project or "Release" as default value. + */ + KDEVCMAKECOMMON_EXPORT QString currentCmakeExecutable( KDevelop::IProject* project, int builddir = -1 ); + /** * @returns the CMake executable, taking into account standard * installation dirs on Windows, or empty string in case of failure. @@ -170,6 +175,11 @@ */ KDEVCMAKECOMMON_EXPORT void setCurrentExtraArguments( KDevelop::IProject* project, const QString& args ); + /** + * Sets the current CMake binary the given project. + */ + KDEVCMAKECOMMON_EXPORT void setCurrentCmakeExecutable(KDevelop::IProject* project, const QString& string); + /** * Obtains a cmake documentation instance if it exists */ diff --git a/projectmanagers/cmake/cmakeutils.cpp b/projectmanagers/cmake/cmakeutils.cpp --- a/projectmanagers/cmake/cmakeutils.cpp +++ b/projectmanagers/cmake/cmakeutils.cpp @@ -54,6 +54,7 @@ namespace Old { static const QString currentBuildDirKey = QStringLiteral("CurrentBuildDir"); +static const QString oldcmakeExecutableKey = QStringLiteral("CMake Binary"); // Todo: Remove at some point static const QString currentBuildTypeKey = QStringLiteral("CurrentBuildType"); static const QString currentInstallDirKey = QStringLiteral("CurrentInstallDir"); static const QString currentEnvironmentKey = QStringLiteral("CurrentEnvironment"); @@ -75,7 +76,7 @@ namespace Specific { static const QString buildDirPathKey = QStringLiteral("Build Directory Path"); -// TODO: migrate to more generic & consistent key term "CMake Executable" +static const QString cmakeExecutableKey = QStringLiteral("CMake Executable"); static const QString cmakeBuildTypeKey = QStringLiteral("Build Type"); static const QString cmakeInstallDirKey = QStringLiteral("Install Directory"); static const QString cmakeEnvironmentKey = QStringLiteral("Environment Profile"); @@ -352,6 +353,11 @@ return readBuildDirParameter( project, Config::Specific::cmakeArgumentsKey, QString(), builddir ); } +QString currentCmakeExecutable( KDevelop::IProject* project, int builddir ) +{ + return readBuildDirParameter( project, Config::Specific::cmakeExecutableKey, QString(), builddir ); +} + void setCurrentInstallDir( KDevelop::IProject* project, const KDevelop::Path& path ) { writeBuildDirParameter( project, Config::Specific::cmakeInstallDirKey, path.toLocalFile() ); @@ -377,6 +383,11 @@ writeBuildDirParameter( project, Config::Specific::cmakeArgumentsKey, string ); } +void setCurrentCmakeExecutable( KDevelop::IProject* project, const QString& string ) +{ + writeBuildDirParameter( project, Config::Specific::cmakeExecutableKey, string ); +} + QString currentEnvironment(KDevelop::IProject* project, int builddir) { return readBuildDirParameter( project, Config::Specific::cmakeEnvironmentKey, QString(), builddir ); diff --git a/projectmanagers/cmake/settings/cmakepreferences.cpp b/projectmanagers/cmake/settings/cmakepreferences.cpp --- a/projectmanagers/cmake/settings/cmakepreferences.cpp +++ b/projectmanagers/cmake/settings/cmakepreferences.cpp @@ -126,6 +126,7 @@ } m_prefsUi->buildType->setCurrentIndex(m_prefsUi->buildType->findText(buildType)); m_prefsUi->extraArguments->setEditText(CMake::currentExtraArguments(m_project)); + m_prefsUi->cMakeExecutable->setText(CMake::currentCmakeExecutable(m_project)); } void CMakePreferences::reset() @@ -168,12 +169,16 @@ } CMake::setCurrentBuildType( m_project, buildType ); CMake::setCurrentExtraArguments( m_project, m_prefsUi->extraArguments->currentText() ); + CMake::setCurrentCmakeExecutable( m_project, m_prefsUi->cMakeExecutable->text() ); + qCDebug(CMAKE) << "writing to cmake config: using builddir " << CMake::currentBuildDirIndex(m_project); qCDebug(CMAKE) << "writing to cmake config: builddir path " << CMake::currentBuildDir(m_project); qCDebug(CMAKE) << "writing to cmake config: installdir " << CMake::currentInstallDir(m_project); qCDebug(CMAKE) << "writing to cmake config: build type " << CMake::currentBuildType(m_project); qCDebug(CMAKE) << "writing to cmake config: environment " << CMake::currentEnvironment(m_project); + qCDebug(CMAKE) << "writing to cmake config: cmake executable " << CMake::currentCmakeExecutable(m_project); + //We run cmake on the builddir to generate it configure(); @@ -352,6 +357,7 @@ qCDebug(CMAKE) << "removing from cmake config: buildtype " << CMake::currentBuildType( m_project ); qCDebug(CMAKE) << "removing from cmake config: environment " << CMake::currentEnvironment( m_project ); + CMake::removeBuildDirConfig(m_project); m_prefsUi->buildDirs->removeItem( curr ); // this triggers buildDirChanged() if(m_prefsUi->buildDirs->count()==0)