| Summary: | Project definitions not working for C++ if sources spicefied via CMake variable | ||
|---|---|---|---|
| Product: | [Applications] kdevelop | Reporter: | Andriy Beregovenko <jet> |
| Component: | Language Support: CPP (old) | Assignee: | kdevelop-bugs-null |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | aleixpol, jet, karganov+kdebugs |
| Priority: | NOR | ||
| Version First Reported In: | 4.1.0 | ||
| Target Milestone: | 4.2.0 | ||
| Platform: | Compiled Sources | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
maybe related to bug 259099 - does it work if you put CMakeLists.txt in the same folder as the main.cpp and open that as a project? commit bfd6423e29fb775146b92532d133fc4418ea5022 branch 4.1 Author: Aleix Pol <aleixpol@kde.org> Date: Wed Dec 8 00:18:15 2010 +0100 Properly add relative globs. BUG: 259099 CCBUG: 259135 diff --git a/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp b/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp index 75a8299..c8f0616 100644 --- a/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp +++ b/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp @@ -1418,26 +1418,38 @@ int CMakeProjectVisitor::visit(const FileAst *file) break; case FileAst::Glob: { QStringList matches; - QString relative=file->path(); + QString currentPath=m_vars->value("CMAKE_CURRENT_SOURCE_DIR").first(); + QString relativeto=file->path(); + if(!relativeto.isEmpty()) { + if(KUrl::isRelativeUrl(relativeto)) + currentPath += '/'+relativeto; + else + currentPath = relativeto; + } + foreach(const QString& glob, file->globbingExpressions()) { QStringList globs; - QString current; - if(KUrl::isRelativeUrl(glob)) { - KUrl urlGlob(glob); - current=urlGlob.upUrl().path(); + QString current(currentPath); + int lastSlash = glob.lastIndexOf('/'); + + if(lastSlash>=0) { + QString path = glob.left(lastSlash); + if(KUrl::isRelativeUrl(glob)) + current+='/'+path; + else + current = path; - globs.append(urlGlob.fileName()); - } else if(!relative.isEmpty()) { - current=relative; - globs.append(glob); + globs.append(glob.right(glob.size()-lastSlash-1)); } else { - current=m_vars->value("CMAKE_CURRENT_SOURCE_DIR").first(); globs.append(glob); } QDir d(current); - matches+=d.entryList(globs, QDir::NoDotAndDotDot | QDir::AllEntries); + QStringList matching=d.entryList(globs, QDir::NoDotAndDotDot | QDir::AllEntries); + + foreach(const QString& match, matching) + matches += d.absoluteFilePath(match); } m_vars->insert(file->variable(), matches); kDebug(9042) << "file glob" << file->path() << file->globbingExpressions() << matches; I fixed the bug 259009, this bug still applies since the defines are not passed. Maybe a C++ support problem? BTW, I say it might be c++ because it complains of not having a Makefile in the ../src directory. Still, the CMakeLists.txt definitions are not read by the DUChain analyzer. I have similar code, variable in add_definitions() and the code like: if ( foo(bar, HAS_FEATURE) ) in KDevelop I see red wavy lines under both closing brackets with popup saying "Problem in Lexer: invalid input" and the first ')' and "Problem in Lexer: unexpected newline" and the second. works for me, create a new report if you find out how to reproduce. Note: your example (of course) only works if you do this in the cmakelists.txt: add_definitions(-DHAS_FEATURE=1) or similar, the macro needs contents. What's wrong with defining macros in cmake? this should be supported, c++ support is prepared for that. Problem with string constants, I've created separate bug: https://bugs.kde.org/show_bug.cgi?id=260858 This patch fix bug http://git.reviewboard.kde.org/r/100283/ *** Bug 241819 has been marked as a duplicate of this bug. *** |
Version: 4.1.0 (using KDE 4.5.3) OS: Linux If source spicified via CMake variables then code highlight not working. Look to reproduce for detail. Reproducible: Always Steps to Reproduce: Create simple CMake-based project: CMakeLists.txt: cmake_minimum_required(VERSION 2.6) project(testdef) file(GLOB SOURCES "../src/main.cpp" ) add_definitions(-DHAS_FEATURE) add_executable(testdef ${SOURCES}) ../src/main.cpp: #include <iostream> #ifdef HAS_FEATURE class blabla { public: static void test(); }; void blabla::test() { std::cout << "This is blabla" << std::endl; } #endif int main(int argc, char **argv) { std::cout << "Hello, world!" << std::endl; #ifdef HAS_FEATURE blabla::test(); #endif return 0; } Actual Results: ifdef'ed source code in main.cpp still "gray" and not highlighted. Expected Results: Source code must highlight.