From fc70e3512ad2785daad4629f62309d12f1a3a32b Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Sat, 18 Feb 2006 11:03:36 -0500 Subject: [PATCH] ENH: apply patch from Alex to support some more kdevelop stuff --- Source/cmGlobalKdevelopGenerator.cxx | 60 +++++++++++++++++++++++----- Source/cmGlobalKdevelopGenerator.h | 16 +++++--- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx index 012262d58..94b431d32 100644 --- a/Source/cmGlobalKdevelopGenerator.cxx +++ b/Source/cmGlobalKdevelopGenerator.cxx @@ -66,10 +66,11 @@ void cmGlobalKdevelopGenerator::Generate() std::string projectDir=mf->GetHomeDirectory(); std::string projectName=mf->GetProjectName(); std::string cmakeFilePattern("CMakeLists.txt;*.cmake;"); + std::string fileToOpen; // create the project.kdevelop.filelist file if(!this->CreateFilelistFile(it->second[0], it->second, outputDir, projectDir, - projectName, cmakeFilePattern)) + projectName, cmakeFilePattern, fileToOpen)) { cmSystemTools::Error("Can not create filelist file"); return; @@ -83,13 +84,13 @@ void cmGlobalKdevelopGenerator::Generate() { if (ti->second.GetType()==cmTarget::EXECUTABLE) { - executable=ti->first; + executable = ti->second.GetProperty("LOCATION"); break; } } // now create a project file this->CreateProjectFile(outputDir, projectDir, projectName, - executable, cmakeFilePattern); + executable, cmakeFilePattern, fileToOpen); } } @@ -99,7 +100,8 @@ bool cmGlobalKdevelopGenerator const std::string& outputDir, const std::string& projectDirIn, const std::string& projectname, - std::string& cmakeFilePattern) + std::string& cmakeFilePattern, + std::string& fileToOpen) { std::string projectDir = projectDirIn + "/"; std::string filename = outputDir+ "/" + projectname +".kdevelop.filelist"; @@ -188,11 +190,21 @@ bool cmGlobalKdevelopGenerator return false; } + fileToOpen=""; for (std::set::const_iterator it=files.begin(); it!=files.end(); it++) { // get the full path to the file tmp=cmSystemTools::CollapseFullPath(it->c_str(), projectDir.c_str()); + // just select the first source file + if (fileToOpen.empty()) + { + std::string ext = cmSystemTools::GetFilenameExtension(tmp); + if ((ext==".c") || (ext==".cc") || (ext==".cpp") || (ext==".C") || (ext==".h")) + { + fileToOpen=tmp; + } + } // make it relative to the project dir cmSystemTools::ReplaceString(tmp, projectDir.c_str(), ""); // only put relative paths @@ -212,20 +224,24 @@ cmGlobalKdevelopGenerator::CreateProjectFile(const std::string& outputDir, const std::string& projectDir, const std::string& projectname, const std::string& executable, - const std::string& cmakeFilePattern) + const std::string& cmakeFilePattern, + const std::string& fileToOpen) { std::string filename=outputDir+"/"; filename+=projectname+".kdevelop"; + std::string sessionFilename=outputDir+"/"; + sessionFilename+=projectname+".kdevses"; if (cmSystemTools::FileExists(filename.c_str())) { this->MergeProjectFiles(outputDir, projectDir, filename, - executable, cmakeFilePattern); + executable, cmakeFilePattern, fileToOpen, sessionFilename); } else { + this->CreateNewProjectFile(outputDir, projectDir, filename, - executable, cmakeFilePattern); + executable, cmakeFilePattern, fileToOpen, sessionFilename); } } @@ -235,12 +251,14 @@ cmGlobalKdevelopGenerator::MergeProjectFiles(const std::string& outputDir, const std::string& projectDir, const std::string& filename, const std::string& executable, - const std::string& cmakeFilePattern) + const std::string& cmakeFilePattern, + const std::string& fileToOpen, + const std::string& sessionFilename) { std::ifstream oldProjectFile(filename.c_str()); if (!oldProjectFile) { - this->CreateNewProjectFile(outputDir, projectDir, filename, executable, cmakeFilePattern); + this->CreateNewProjectFile(outputDir, projectDir, filename, executable, cmakeFilePattern, fileToOpen, sessionFilename); return; } @@ -305,7 +323,9 @@ cmGlobalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir, const std::string& projectDir, const std::string& filename, const std::string& executable, - const std::string& cmakeFilePattern) + const std::string& cmakeFilePattern, + const std::string& fileToOpen, + const std::string& sessionFilename) { cmGeneratedFileStream fout(filename.c_str()); if(!fout) @@ -331,7 +351,7 @@ cmGlobalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir, fout<<" \n"; fout<<" "<\n"; fout<<" \n"; - fout<<" "<\n"; + fout<<" "<\n"; fout<<" custom\n"; fout<<" /\n"; fout<<" \n"; @@ -409,5 +429,23 @@ cmGlobalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir, fout<<" \n"; fout<<"\n"; + if (sessionFilename.empty()) + return; + + // and a session file, so that kdevelop opens a file if it opens the project the first time + cmGeneratedFileStream devses(sessionFilename.c_str()); + if(!devses) + { + return; + } + devses<<"\n"; + devses<<"\n"; + devses<<"\n"; + devses<<" \n"; + devses<<" \n"; + devses<<" \n"; + devses<<" \n"; + devses<<" \n"; + devses<<"\n"; } diff --git a/Source/cmGlobalKdevelopGenerator.h b/Source/cmGlobalKdevelopGenerator.h index b0ad05f5d..5f71e728d 100644 --- a/Source/cmGlobalKdevelopGenerator.h +++ b/Source/cmGlobalKdevelopGenerator.h @@ -63,7 +63,8 @@ public: const std::string& outputDir, const std::string& projectDirIn, const std::string& projectname, - std::string& cmakeFilePattern); + std::string& cmakeFilePattern, + std::string& fileToOpen); /** Create the foo.kdevelop file. This one calls MergeProjectFiles() if it already exists, otherwise createNewProjectFile() The project @@ -75,7 +76,8 @@ public: const std::string& projectDir, const std::string& projectname, const std::string& executable, - const std::string& cmakeFilePattern); + const std::string& cmakeFilePattern, + const std::string& fileToOpen); /*** Reads the old foo.kdevelop line by line and only replaces the "important" lines @@ -84,13 +86,17 @@ public: const std::string& projectDir, const std::string& filename, const std::string& executable, - const std::string& cmakeFilePattern); - ///! Creates a new foo.kdevelop file + const std::string& cmakeFilePattern, + const std::string& fileToOpen, + const std::string& sessionFilename); + ///! Creates a new foo.kdevelop and a new foo.kdevses file void CreateNewProjectFile(const std::string& outputDir, const std::string& projectDir, const std::string& filename, const std::string& executable, - const std::string& cmakeFilePattern); + const std::string& cmakeFilePattern, + const std::string& fileToOpen, + const std::string& sessionFilename); };