Bug 259135

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:

Description Andriy Beregovenko 2010-12-07 16:08:57 UTC
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.
Comment 1 Milian Wolff 2010-12-07 16:37:18 UTC
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?
Comment 2 Aleix Pol 2010-12-08 00:22:03 UTC
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;
Comment 3 Aleix Pol 2010-12-08 00:23:39 UTC
I fixed the bug 259009, this bug still applies since the defines are not passed. Maybe a C++ support problem?
Comment 4 Aleix Pol 2010-12-08 00:24:35 UTC
BTW, I say it might be c++ because it complains of not having a Makefile in the ../src directory.
Comment 5 Kostik Karganov 2010-12-21 10:16:54 UTC
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.
Comment 6 Milian Wolff 2010-12-21 10:30:36 UTC
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.
Comment 7 Aleix Pol 2010-12-21 12:06:27 UTC
What's wrong with defining macros in cmake? this should be supported, c++ support is prepared for that.
Comment 8 Kostik Karganov 2010-12-21 12:11:45 UTC
Problem with string constants, I've created separate bug: https://bugs.kde.org/show_bug.cgi?id=260858
Comment 9 Andriy Beregovenko 2011-01-06 21:38:05 UTC
This patch fix bug
http://git.reviewboard.kde.org/r/100283/
Comment 10 Andriy Beregovenko 2011-01-10 00:29:10 UTC
*** Bug 241819 has been marked as a duplicate of this bug. ***