Search code examples
c++eclipsebuildeclipse-cdtcustom-build

Eclipse IDE C/C++ automatic include paths from custom build script


I have a custom python script to build my projects in order to keep dependency simple, I would like to use Eclipse as a C++ IDE but keeping my build script.

To maintain autocompletion and intellisense (with docs etc...) I would like to tell Eclipse the (non standard) headers and defines added during dependency resolution in my script.

I've found that ".cproject" file contains such information, is it safe to alter it from the build scripts or is there any way to integrate my script in Eclipse itself?

Example:

# TestGame.json
{
  "name": "TestGame",
  "extend": "BASE",
  "actions": ["COMPILE", "LINK"],
  "CC": [
    "G++11"
  ],
  "dep": {
    "builds": ["DFResourcer", "DFSDL"],
    "libs": ["SDL2", "SDL2main"]
  }
}

My build scripts will compile modified files and link them with all the needed files and will find "/home/cpp-projects/DFSDL/include", other paths that must be included and the need for --std=c++11, I want a way to tell Eclipse (not manually) to search for headers also there for autocompletion etc...


Solution

  • I've found that ".cproject" file contains such information, is it safe to alter it from the build scripts

    It's doable, but not recommended, because the file format is undocumented and not guaranteed to be stable across Eclipse versions.

    is there any way to integrate my script in Eclipse itself?

    You could write an Eclipse plugin that runs your script and communicates with it or consumes output it produces. However, that seems like a heavyweight solution.

    I would suggest the following simple solution:

    Eclipse has a build output parser. I've written about how to use it in other answers, like this one. Basically, it's designed to parse the output of a make invocation, parse any line that looks like a compiler command, and configure include paths based on the -I arguments in that command.

    You can make use of this even though you're using a custom build script rather than make: just get your script to output the compiler commands it invokes (if you want, you can make this conditional on a flag like --verbose), and configure Eclipse to invoke your build script rather than make (passing in the flag if you used one) when building your project.