Changeset View
Changeset View
Standalone View
Standalone View
projectmanagers/cmake/cmakebuilddirchooser.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | |||||
97 | { | 97 | { | ||
98 | m_srcFolder = srcFolder; | 98 | m_srcFolder = srcFolder; | ||
99 | 99 | | |||
100 | m_chooserUi->buildFolder->setUrl(KDevelop::proposedBuildFolder(srcFolder).toUrl()); | 100 | m_chooserUi->buildFolder->setUrl(KDevelop::proposedBuildFolder(srcFolder).toUrl()); | ||
101 | setWindowTitle(i18n("Configure a build directory for %1", srcFolder.toLocalFile())); | 101 | setWindowTitle(i18n("Configure a build directory for %1", srcFolder.toLocalFile())); | ||
102 | update(); | 102 | update(); | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | QString CMakeBuildDirChooser::buildDirProject(const Path &srcDir) | 105 | void CMakeBuildDirChooser::buildDirSettings( | ||
106 | { | 106 | const KDevelop::Path& buildDir, | ||
107 | const Path cachePath(srcDir, "CMakeCache.txt"); | 107 | QString& srcDir, | ||
108 | QString& installDir, | ||||
109 | QString& buildType) | ||||
110 | { | ||||
111 | static const QString srcLine = QStringLiteral("CMAKE_HOME_DIRECTORY:INTERNAL="); | ||||
112 | static const QString installLine = QStringLiteral("CMAKE_INSTALL_PREFIX:PATH="); | ||||
113 | static const QString buildLine = QStringLiteral("CMAKE_BUILD_TYPE:STRING="); | ||||
114 | | ||||
115 | const Path cachePath(buildDir, "CMakeCache.txt"); | ||||
108 | QFile file(cachePath.toLocalFile()); | 116 | QFile file(cachePath.toLocalFile()); | ||
109 | 117 | | |||
118 | srcDir.clear(); | ||||
119 | installDir.clear(); | ||||
120 | buildType.clear(); | ||||
121 | | ||||
110 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) | 122 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) | ||
111 | { | 123 | { | ||
112 | qCWarning(CMAKE) << "Something really strange happened reading" << cachePath; | 124 | qCWarning(CMAKE) << "Something really strange happened reading" << cachePath; | ||
113 | return QString(); | 125 | return; | ||
114 | } | 126 | } | ||
115 | 127 | | |||
116 | QString ret; | 128 | int cnt = 0; | ||
117 | bool correct=false; | 129 | while (cnt != 3 && !file.atEnd()) | ||
118 | const QString pLine="CMAKE_HOME_DIRECTORY:INTERNAL="; | | |||
119 | while (!correct && !file.atEnd()) | | |||
120 | { | 130 | { | ||
121 | // note: CMakeCache.txt is UTF8-encoded, also see bug 329305 | 131 | // note: CMakeCache.txt is UTF8-encoded, also see bug 329305 | ||
122 | QString line = QString::fromUtf8(file.readLine().trimmed()); | 132 | QString line = QString::fromUtf8(file.readLine().trimmed()); | ||
123 | if(line.startsWith(pLine)) | 133 | | ||
134 | if (line.startsWith(srcLine)) | ||||
135 | { | ||||
136 | srcDir = line.mid(srcLine.count()); | ||||
137 | ++cnt; | ||||
138 | } | ||||
139 | | ||||
140 | if (line.startsWith(installLine)) | ||||
124 | { | 141 | { | ||
125 | correct=true; | 142 | installDir = line.mid(installLine.count()); | ||
126 | ret=line.mid(pLine.count()); | 143 | ++cnt; | ||
127 | } | 144 | } | ||
145 | | ||||
146 | if (line.startsWith(buildLine)) | ||||
147 | { | ||||
148 | buildType = line.mid(buildLine.count()); | ||||
149 | ++cnt; | ||||
128 | } | 150 | } | ||
129 | qCDebug(CMAKE) << "The source directory for " << file.fileName() << "is" << ret; | 151 | } | ||
130 | return ret; | 152 | | ||
153 | qCDebug(CMAKE) << "The source directory for " << file.fileName() << "is" << srcDir; | ||||
154 | qCDebug(CMAKE) << "The install directory for " << file.fileName() << "is" << installDir; | ||||
155 | qCDebug(CMAKE) << "The build type for " << file.fileName() << "is" << buildType; | ||||
131 | } | 156 | } | ||
132 | 157 | | |||
133 | void CMakeBuildDirChooser::updated() | 158 | void CMakeBuildDirChooser::updated() | ||
134 | { | 159 | { | ||
135 | bool haveCMake=QFile::exists(m_chooserUi->cmakeBin->url().toLocalFile()); | 160 | bool haveCMake=QFile::exists(m_chooserUi->cmakeBin->url().toLocalFile()); | ||
136 | StatusTypes st; | 161 | StatusTypes st; | ||
137 | if( haveCMake ) st |= HaveCMake; | 162 | if( haveCMake ) st |= HaveCMake; | ||
138 | 163 | | |||
139 | m_chooserUi->buildFolder->setEnabled(haveCMake); | 164 | m_chooserUi->buildFolder->setEnabled(haveCMake); | ||
140 | m_chooserUi->installPrefix->setEnabled(haveCMake); | 165 | m_chooserUi->installPrefix->setEnabled(haveCMake); | ||
141 | m_chooserUi->buildType->setEnabled(haveCMake); | 166 | m_chooserUi->buildType->setEnabled(haveCMake); | ||
142 | // m_chooserUi->generator->setEnabled(haveCMake); | 167 | // m_chooserUi->generator->setEnabled(haveCMake); | ||
143 | if(!haveCMake) | 168 | if(!haveCMake) | ||
144 | { | 169 | { | ||
145 | setStatus(i18n("You need to select a cmake binary."), false); | 170 | setStatus(i18n("You need to select a cmake binary."), false); | ||
146 | return; | 171 | return; | ||
147 | } | 172 | } | ||
148 | 173 | | |||
149 | Path chosenBuildFolder(m_chooserUi->buildFolder->url()); | 174 | Path chosenBuildFolder(m_chooserUi->buildFolder->url()); | ||
150 | bool emptyUrl = chosenBuildFolder.isEmpty(); | 175 | bool emptyUrl = chosenBuildFolder.isEmpty(); | ||
151 | if( emptyUrl ) st |= BuildFolderEmpty; | 176 | if( emptyUrl ) st |= BuildFolderEmpty; | ||
152 | 177 | | |||
153 | bool dirEmpty = false, dirExists= false, dirRelative = false; | 178 | bool dirEmpty = false, dirExists= false, dirRelative = false; | ||
154 | QString srcDir; | 179 | QString srcDir; | ||
180 | QString installDir; | ||||
181 | QString buildType; | ||||
155 | if(!emptyUrl) | 182 | if(!emptyUrl) | ||
156 | { | 183 | { | ||
157 | QDir d(chosenBuildFolder.toLocalFile()); | 184 | QDir d(chosenBuildFolder.toLocalFile()); | ||
158 | dirExists = d.exists(); | 185 | dirExists = d.exists(); | ||
159 | dirEmpty = dirExists && d.count()<=2; | 186 | dirEmpty = dirExists && d.count()<=2; | ||
160 | dirRelative = d.isRelative(); | 187 | dirRelative = d.isRelative(); | ||
161 | if(!dirEmpty && dirExists && !dirRelative) | 188 | if(!dirEmpty && dirExists && !dirRelative) | ||
162 | { | 189 | { | ||
163 | bool hasCache=QFile::exists(Path(chosenBuildFolder, "CMakeCache.txt").toLocalFile()); | 190 | bool hasCache=QFile::exists(Path(chosenBuildFolder, "CMakeCache.txt").toLocalFile()); | ||
164 | if(hasCache) | 191 | if(hasCache) | ||
165 | { | 192 | { | ||
166 | QString proposed=m_srcFolder.toLocalFile(); | 193 | QString proposed=m_srcFolder.toLocalFile(); | ||
167 | 194 | | |||
168 | srcDir = buildDirProject(chosenBuildFolder); | 195 | buildDirSettings(chosenBuildFolder, srcDir, installDir, buildType); | ||
169 | if(!srcDir.isEmpty()) | 196 | if(!srcDir.isEmpty()) | ||
170 | { | 197 | { | ||
171 | if(QDir(srcDir).canonicalPath()==QDir(proposed).canonicalPath()) | 198 | if(QDir(srcDir).canonicalPath()==QDir(proposed).canonicalPath()) | ||
172 | { | 199 | { | ||
173 | st |= CorrectBuildDir | BuildDirCreated; | 200 | st |= CorrectBuildDir | BuildDirCreated; | ||
174 | } | 201 | } | ||
175 | } | 202 | } | ||
176 | else | 203 | else | ||
177 | { | 204 | { | ||
178 | qCWarning(CMAKE) << "maybe you are trying a damaged CMakeCache.txt file. Proper: "; | 205 | qCWarning(CMAKE) << "maybe you are trying a damaged CMakeCache.txt file. Proper: "; | ||
179 | } | 206 | } | ||
207 | | ||||
208 | if(!installDir.isEmpty() && QDir(installDir).exists()) | ||||
209 | { | ||||
210 | m_chooserUi->installPrefix->setUrl(QUrl::fromLocalFile(installDir)); | ||||
211 | } | ||||
212 | | ||||
213 | m_chooserUi->buildType->setCurrentText(buildType); | ||||
180 | } | 214 | } | ||
181 | } | 215 | } | ||
182 | 216 | | |||
183 | if(m_alreadyUsed.contains(chosenBuildFolder.toLocalFile())) { | 217 | if(m_alreadyUsed.contains(chosenBuildFolder.toLocalFile())) { | ||
184 | st=DirAlreadyCreated; | 218 | st=DirAlreadyCreated; | ||
185 | } | 219 | } | ||
186 | } | 220 | } | ||
187 | else | 221 | else | ||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |