View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0009272CMakeCMakepublic2009-07-15 03:022009-09-16 14:38
ReporterBenjamin Schindler 
Assigned ToAlex Neundorf 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionCMake-2-6 
Target VersionFixed in Version 
Summary0009272: Eclipse generator should get list of defines for gcc so that eclipse can parse sources correctly
DescriptionAs 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 -
TagsNo tags attached.
Attached Filespatch file icon CMakeFindEclipseCDT4.cmake.patch [^] (3,584 bytes) 2009-09-15 15:06 [Show Content]

 Relationships

  Notes
(0017541)
Alex Neundorf (developer)
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 (developer)
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 (developer)
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 (developer)
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 (developer)
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

 Issue History
Date Modified Username Field Change
2009-07-15 03:02 Benjamin Schindler New Issue
2009-09-14 12:43 Bill Hoffman Status new => assigned
2009-09-14 12:43 Bill Hoffman Assigned To => Alex Neundorf
2009-09-15 14:12 Alex Neundorf Note Added: 0017541
2009-09-15 14:54 Miguel Figueroa Note Added: 0017542
2009-09-15 15:06 Alex Neundorf File Added: CMakeFindEclipseCDT4.cmake.patch
2009-09-15 15:09 Alex Neundorf Note Added: 0017543
2009-09-15 16:14 Miguel Figueroa Note Added: 0017546
2009-09-16 14:38 Alex Neundorf Note Added: 0017571
2009-09-16 14:38 Alex Neundorf Status assigned => closed
2009-09-16 14:38 Alex Neundorf Resolution open => fixed


Copyright © 2000 - 2018 MantisBT Team