[cmake-developers] Correct way to get include directories for a target (automoc regression) ?

Alexander Neundorf neundorf at kde.org
Fri Nov 9 14:31:01 EST 2012


On Friday 09 November 2012, Alexander Neundorf wrote:
> Hi,
> 
> as you know, there is a regression in 2.8.10 with automoc:
> http://public.kitware.com/Bug/view.php?id=13667
> http://public.kitware.com/Bug/view.php?id=13646
> 
> I'm looking at this right now.
> The problem is that when moc is invoked, an include directory is missing, -
> I/usr/lib/qt/include is missing.
> 
> Now, I printed ${QT_INCLUDES} in the CMakeLists.txt:
> 
> -- qt:
> -/usr/lib/qt/include/QtXmlPatterns;/usr/lib/qt/include/QtXml;/usr/lib/qt/in
> clude/QtWebKit;/usr/lib/qt/include/QtUiTools;/usr/lib/qt/include/QtTest;/us
> r/lib/qt/include/QtSvg;/usr/lib/qt/include/QtSql;/usr/lib/qt/include/QtScri
> ptTools;/usr/lib/qt/include/QtScript;/usr/lib/qt/include/QtOpenGL;/usr/lib/
> qt/include/QtNetwork;/usr/lib/qt/include/QtMultimedia;/usr/lib/qt/include/Q
> tHelp;/usr/lib/qt/include/QtDesigner;/usr/lib/qt/include/QtDesigner;/usr/li
> b/qt/include/QtDeclarative;/usr/lib/qt/include/QtDBus;/usr/lib/qt/include/Q
> t3Support;/usr/lib/qt/include/QtGui;/usr/lib/qt/include/QtCore;/usr/lib/qt/
> include/Qt;/usr/lib/qt/mkspecs/default;/usr/lib/qt/include-
> 
> This has /usr/lib/qt/includes/ at the end.
> 
> Now I added debug output to the point where the include directories are
> queried from the target in cmQtAutomoc.cxx:
> 
> 
> std::vector<std::string> includeDirs;
> cmGeneratorTarget gtgt(target);
> localGen->GetIncludeDirectories(includeDirs, &gtgt, "CXX");
> std::string _moc_incs = "";
> const char* sep = "";
> fprintf(stderr, "---------- %s--------\n", targetNames);
> for(std::vector<std::string>::const_iterator incDirIt =
> includeDirs.begin(); incDirIt != includeDirs.end();
>     ++incDirIt)
>   {
>   fprintf(stderr, "%s\n", incDirIt->c_str());
>   _moc_incs += sep;
>   sep = ";";
>   _moc_incs += *incDirIt;
>   }
> 
> 
> This gives:
> 
> ---------- phononqmlplugin--------
> /home/alex/src/packages/phonon/build-HEAD/declarative
> /home/alex/src/packages/phonon/declarative
> /home/alex/src/packages/phonon
> /home/alex/src/packages/phonon/includes
> /home/alex/src/packages/phonon/phonon
> /home/alex/src/packages/phonon/build-HEAD/phonon
> /home/alex/src/packages/phonon/build-HEAD/declarative/..
> /usr/lib/qt/include/QtXmlPatterns
> /usr/lib/qt/include/QtXml
> /usr/lib/qt/include/QtWebKit
> /usr/lib/qt/include/QtUiTools
> /usr/lib/qt/include/QtTest
> /usr/lib/qt/include/QtSvg
> /usr/lib/qt/include/QtSql
> /usr/lib/qt/include/QtScriptTools
> /usr/lib/qt/include/QtScript
> /usr/lib/qt/include/QtOpenGL
> /usr/lib/qt/include/QtNetwork
> /usr/lib/qt/include/QtMultimedia
> /usr/lib/qt/include/QtHelp
> /usr/lib/qt/include/QtDesigner
> /usr/lib/qt/include/QtDeclarative
> /usr/lib/qt/include/QtDBus
> /usr/lib/qt/include/Qt3Support
> /usr/lib/qt/include/QtGui
> /usr/lib/qt/include/QtCore
> /usr/lib/qt/include/Qt
> /usr/lib/qt/mkspecs/default
> ---------- phonon--------
> 
> 
> So here /usr/lib/qt/include is missing.
> 
> Am I doing something wrong or is the list of returned include dirs wrong ?

I'm getting closer.
Phonon and kdelibs do the following

_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs)
set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
    ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} ${_dirs}
   )


_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS() calls the compiler (gcc -v -E -x c++ -dD) 
and parses the include search dirs. This contains /usr/lib/qt/include on my 
system (/usr/lib/qt/include;;/usr/lib/gcc/i486-slackware-
linux/4.5.2/../../../../include/c++/4.5.2;;/usr/lib/gcc/i486-slackware-
linux/4.5.2/../../../../include/c++/4.5.2/i486-slackware-
linux;;/usr/lib/gcc/i486-slackware-
linux/4.5.2/../../../../include/c++/4.5.2/backward;;/usr/local/include;;/usr/lib/gcc/i486-
slackware-linux/4.5.2/include;;/usr/lib/gcc/i486-slackware-
linux/4.5.2/include-fixed;;/usr/include)

In 2.8.9 automoc did not ask the target for its include dirs, but it asked the 
directory for its include dirs. This contained and still contains as it seems 
the CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES.
In 2.8.10 the target is asked for its include dirs, and it seems there the 
implicit include dirs have been stripped.

So what should I do ?

Simply always add all ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} to the include 
dirs used by moc ?

Getting the include dirs from the directory and the include dirs from the 
target, and then using the union of both is probably not the right way to go I 
think ?

Alex



More information about the cmake-developers mailing list