Bug 536763 - Wrong indexer include path for files not referenced in CMakeLists.txt
Summary: Wrong indexer include path for files not referenced in CMakeLists.txt
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-cmake (show other bugs)
Version: 9.5.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: cdt-build-inbox@eclipse.org CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-06 09:36 EDT by Bartłomiej Golenko CLA
Modified: 2020-09-04 15:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bartłomiej Golenko CLA 2018-07-06 09:36:53 EDT
I encountered this problem while converting a pretty big project to cmake.

It seems that if the file is not part of some cmake target, then it is indexed using default (?) include paths (include_directories directive from CMakeLists.txt is ignored). It is not a problem (well, not a big problem - its still annoying to see lots of yellow and red warning/error markers), unless this file is a header included from various .cpp files - some of them not being part of a build.

It seems that if the header was first encountered by indexer while indexing a file that is not part of the build, then it will not see proper include paths.

Here are the steps I performed to test this:

1. Create new CMake project and modify CMakeLists.txt:

cmake_minimum_required (VERSION 2.6)

project (testyy)

# external include directory
include_directories ( /opt/poco-1.8.1/include)

add_executable(testyy testyy.cpp )

2. Add 3 files

testyy.cpp:

#include <iostream>
#include <Poco/Timestamp.h>

using namespace std;

struct Test {
	Poco::Timestamp ts;
};

int main(int argc, char **argv) {
	cout << "Hello world";
	return 0;
}

-------------------

foo.cpp

#include "bar.h"

void foo() {}

-------------------

bar.h

#ifndef BAR_H__
#define BAR_H__

#include <Poco/Timestamp.h> // warning - include not found

struct Bar {
	Poco::Timestamp ts; // error - Poco::Timestamp could not be resolved
};

#endif


After building the project - Poco/Timestamp is properly found and resolved in testyy.cpp, but not in bar.h


Adding foo.cpp to the build target "fixes it", but its rather not "practical" in my project to add absolutely all .cpp files (some of them being Linux, other Windows or Android code).

It would be best to exclude files that are not part of the build from indexer, but setting this option in Preferences seems to disable indexer completely for all files.