MantisBT - CMake
View Issue Details
0009272CMakeCMakepublic2009-07-15 03:022009-09-16 14:38
Benjamin Schindler 
Alex Neundorf 
normalminoralways
closedfixed 
CMake-2-6 
 
0009272: Eclipse generator should get list of defines for gcc so that eclipse can parse sources correctly
As discussed in the cmake mailing list (http://www.cmake.org/pipermail/cmake/2009-July/030774.html [^]), the eclipse parser does not decend into parts like:

#ifdef __GNUC__
 ....
#endif

Which can then in turn cripple code completion.
Therefore, the eclipse generator should add all defines defined by gcc to the project file using

echo | gcc -v -x c -E -dD -
echo | gcc -v -x c++ -E -dD -
No tags attached.
patch CMakeFindEclipseCDT4.cmake.patch (3,584) 2009-09-15 15:06
https://public.kitware.com/Bug/file/2453/CMakeFindEclipseCDT4.cmake.patch
Issue History
2009-07-15 03:02Benjamin SchindlerNew Issue
2009-09-14 12:43Bill HoffmanStatusnew => assigned
2009-09-14 12:43Bill HoffmanAssigned To => Alex Neundorf
2009-09-15 14:12Alex NeundorfNote Added: 0017541
2009-09-15 14:54Miguel FigueroaNote Added: 0017542
2009-09-15 15:06Alex NeundorfFile Added: CMakeFindEclipseCDT4.cmake.patch
2009-09-15 15:09Alex NeundorfNote Added: 0017543
2009-09-15 16:14Miguel FigueroaNote Added: 0017546
2009-09-16 14:38Alex NeundorfNote Added: 0017571
2009-09-16 14:38Alex NeundorfStatusassigned => closed
2009-09-16 14:38Alex NeundorfResolutionopen => fixed

Notes
(0017541)
Alex Neundorf   
2009-09-15 14:12   
Once I have the list of builtin macros, how should they end up in the project files ?
Do you have any example files or pointers to documentation ?

Alex
(0017542)
Miguel Figueroa   
2009-09-15 14:54   
This is the code that inserts the definitions from CMakeLists.txt files into the .cproject:

        // insert the definition if not already added.
        if(emmited.find(def) == emmited.end())
          {
          emmited.insert(def);
          fout << "<pathentry kind=\"mac\" name=\"" << def
               << "\" path=\"\" value=\"" << this->EscapeForXML(val)
               << "\"/>\n";
          }

It should end up with an entry in the .cproject file such as:

for -DFOO:
    <pathentry kind="mac" name="FOO" path="" value=""/>

for -DFOO=BAR:
    <pathentry kind="mac" name="FOO" path="" value="BAR"/>

I guess, we could refactor out the code between the comments:
  // add pre-processor definitions to allow eclipse to gray out sections
  ...
  // include dirs

and process the list of CMake COMPILE_DEFINITIONS and the list obtained from the compiler (only if gcc).

--Miguel
(0017543)
Alex Neundorf   
2009-09-15 15:09   
The patch CMakeFindEclipseCDT4.cmake.patch makes cmake query gcc during the initial run for the builtin definitions, and stores them in the cache in the variables CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS and CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS. Both are then a list of the following form: MACRO1;value_of_macro1;MACRO2;value_of_macro2;
etc.

These variables could then be used from within cmExtraEclipseGenerator.cxx.

Alex
(0017546)
Miguel Figueroa   
2009-09-15 16:14   
What happens in the case of empty values (e.g., -DFOO)? I briefly reviewed the code in cmSystemTools::ExpandListArgument and presuming that it results in an empty string then no problems should arise.

The following code should work:

  // add pre-processor definitions to allow eclipse to gray out sections
  emmited.clear();
  for (std::vector<cmLocalGenerator*>::const_iterator
        it = this->GlobalGenerator->GetLocalGenerators().begin();
       it != this->GlobalGenerator->GetLocalGenerators().end();
       ++it)
    {

    if(const char* cdefs = (*it)->GetMakefile()->GetProperty(
                                                        "COMPILE_DEFINITIONS"))
      {
      ...
      }

    // add system defined c macros
    if(const char* cdefs = (*it)->GetMakefile()->GetSafeDefinition(
                                      "CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS"))
      {
      // Expand the list.
      std::vector<std::string> defs;
      cmSystemTools::ExpandListArgument(cdefs, defs);

      std::vector<std::string>::const_iterator di = defs.begin();
      while (di != defs.end())
        {
        std::string def = *di;
        std::string val;

        if (++di != defs.end)
          {
          val = *di;
          }
        
        // insert the definition if not already added.
        if(emmited.find(def) == emmited.end())
          {
          emmited.insert(def);
          fout << "<pathentry kind=\"mac\" name=\"" << def
               << "\" path=\"\" value=\"" << this->EscapeForXML(val)
               << "\"/>\n";
          }
        }
      }

    // add system defined c++ macros
    ... same for CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS ...
    }

I like the approach Alex is taking, because the for other platforms you could populate the CMAKE_ECLIPSE_C[XX]_SYSTEM_DEFINED_MACROS variables appropriately without modifying the code.

--Miguel
(0017571)
Alex Neundorf   
2009-09-16 14:38   
Patch changed somewhat (we need to ask the makefile only at the toplevel for the defines) and committed to cvs HEAD, should work now.
Please test, feel free to reopen if it doesn't work.

Alex