Bug 259099 - [CMake] Source files outside of project root are not shown
Summary: [CMake] Source files outside of project root are not shown
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Build tools: CMake (other bugs)
Version First Reported In: 4.1.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: 4.2.0
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-07 12:03 UTC by Andriy Beregovenko
Modified: 2011-12-19 02:59 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andriy Beregovenko 2010-12-07 12:03:12 UTC
Version:           4.1.0 (using KDE 4.5.3) 
OS:                Linux

In CMake-based project, If source files is out of build tree, it not shown in project files tree.

Reproducible: Always

Steps to Reproduce:
Place files out of project directory. Define it in CMakeLists.txt.

Actual Results:  
Source files is not shown

Expected Results:  
Must be shown

My CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
PROJECT(test)

FILE(GLOB_RECURSE SOURCES "../../../../sources/test/src/*.cpp" )
INCLUDE_DIRECTORIES( ../../../../sources/test/include )
Comment 1 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 2 Andriy Beregovenko 2011-01-06 21:37:09 UTC
Bug is not fixed, due to incorrect/incomplete parse of GLOB and GLOB_RECURSE
Comment 3 Andriy Beregovenko 2011-01-06 21:41:15 UTC
This patch fix problem completely
http://git.reviewboard.kde.org/r/100283/
Comment 4 Aleix Pol 2011-12-19 02:59:14 UTC
This was fixed by the revewboard patch. Closing the bug.