[cmake-developers] Regression when using multiple Qt installations (FindQt4.make)
Clinton Stimpson
clinton at elemtech.com
Mon May 7 11:29:55 EDT 2012
On Monday, May 07, 2012 09:14:55 am Benoit Walter wrote:
> On Monday 07 May 2012, you wrote:
> > On Monday, May 07, 2012 08:43:07 am Benoit Walter wrote:
> > > On Monday 07 May 2012, Clinton Stimpson wrote:
> > > > On Sunday, May 06, 2012 04:27:17 am Benoit Walter wrote:
> > > > > Hi CMake developers,
> > > > >
> > > > > as I need to maintain different projects using different Qt
> > > > > versions, I needed to have a look at FindQt4.cmake.
> > > > >
> > > > > Based on the path of qmake, I can successfully decide which Qt
> > > > > version is used (for example using Debian's update-alternatives).
> > > > >
> > > > > Ex:
> > > > > /opt/qt4.7 (custom version)
> > > > > /usr/include/qt4 (default
> > > > > version)PATH=/PATH=/path/to/custom/qt/bin:$PATH
> > >
> > > cmake ..path/to/custom/qt/bin:$PATH cmake ..
> > >
> > > > > However, even if I set qmake to the directory of the custom
> > > > > version, I see that cmake uses the headers of the default version.
> > > > >
> > > > > It seems to me like a regression in commit
> > > > > 0ae8a3405bb32afadda13f43100484e85f7ef74f ("Add qt4/QtCore to help
> > > > > find Qt headers when cross-compiling.")
> > > > >
> > > > > qt4/QtCore is found in /usr/include instead of /opt/qt4.7/include,
> > > > > in contradiction with the qmake information (qmake -query
> > > > > QT_INSTALL_HEADERS).
> > > > >
> > > > > Corresponding lines in FindQt4.make:
> > > > > FIND_PATH(QT_QTCORE_INCLUDE_DIR QtCore
> > > > >
> > > > > HINTS ${qt_headers} ${QT_LIBRARY_DIR}
> > > > > PATH_SUFFIXES QtCore qt4/QtCore
> > > > >
> > > > > )
> > > > >
> > > > > Removing qt4/QtCore fixes the problem, but I guess that the commit
> > > > > was useful for other reasons :)
> > > > > So my suggestion is to either revert the commit because it
> > > > > invalidates a common scenario when using cmake with several Qt
> > > > > installations, or to fix the FIND_PATH call, making sure that the
> > > > > custom location is found before the default one.
> > > > >
> > > > > Any idea?
> > > > >
> > > > > Best regards,
> > > > > Benoit.
> > > >
> > > > What version of cmake are you using?
> > > >
> > > > I also have
> > > > /usr/include/qt4
> > > > and a custom Qt, but do not see this problem with the latest cmake.
> > > >
> > > > The FIND_PATH(QT_QTCORE_INCLUDE_DIR QtCore
> > > >
> > > > HINTS ${qt_headers} ${QT_LIBRARY_DIR}
> > > > PATH_SUFFIXES QtCore qt4/QtCore
> > > >
> > > > It should first look for ${qt_headers}/QtCore, which should be
> > > > /opt/qt4.7/include/QtCore.
> > > >
> > > > I tried these 3 ways, but was not able to reproduce.
> > > > 1. PATH=/path/to/custom/qt/bin:$PATH cmake ..
> > > > 2. CMAKE_PREFIX_PATH=/path/to/custom/qt cmake ..
> > > > 3. cmake .. -> modify CMakeCache.txt to use custom qmake then re-run
> > > >
> > > > cmake.
> > > >
> > > > I have no "/usr/include" in my CMakeCache.txt file.
> > > >
> > > > Can you expand the ${qt_headers} and tell me what you have?
> > >
> > > I am using CMake 2.8.7. I would also expect that it first looks for
> > > ${qt_headers}/QtCore and then qt4/QtCore but this is unfortunately not
> > > the case for me.
> > >
> > > qt_header points to the right directory (/opt/qt4.7/include), so my
> > > guess is that the problem is related to the FIND_PATH() function. It
> > > seems that it first checks the default path (/usr/include). If I add
> > > the
> > > NO_DEFAULT_PATH argument, it works as expected and
> > > QT_QTCORE_INCLUDE_DIR
> > >
> > > points to the right directory (the custom one):
> > > FIND_PATH(QT_QTCORE_INCLUDE_DIR QtCore
> > >
> > > HINTS ${qt_headers} ${QT_LIBRARY_DIR}
> > > PATH_SUFFIXES QtCore qt4/QtCore
> > > NO_DEFAULT_PATH
> > >
> > > )
> > >
> > > Maybe because of a recent CMake change in FIND_PATH()?
> > >
> > > Note: On my system, the PATH is not changed (/usr/bin is *before*
> > > /opt/qt4.7/bin) and /usr/bin/cmake is linked to /opt/qt4.7/bin/cmake
> > > using update-alternatives. But that should not change anything and the
> > > first steps (including "_qt4_query_qmake(QT_INSTALL_HEADERS
> > > qt_headers)") are successful.
> > >
> > > Regards,
> > > Benoit.
> >
> > According to the docs, /usr/include is searched after any paths given by
> > HINTS. However, I can reproduce your problem by doing this:
> > export CMAKE_PREFIX_PATH=/usr
> > cmake -DQT_QMAKE_EXECUTABLE=/path/to/custom/qt/bin/qmake ../
> >
> > but that can easily be fixed by a more standard approach of specifying a
> > desired package (in this case, Qt) in CMAKE_PREFIX_PATH instead.
> > export CMAKE_PREFIX_PATH=/path/to/qt:/usr
> > cmake ../
> >
> > So, are you setting either CMAKE_PREFIX_PATH or CMAKE_INCLUDE_PATH in the
> > environment or in your CMakeLists.txt files?
>
> You got it! CMAKE_PREFIX_PATH is set in my environment. I agree that it can
> easily be fixed, it is however likely to happen again to other users.
> Furthermore, changing CMAKE_PREFIX_PATH when selecting another Qt version
> is probably not the best approach (especially for update-alternatives
> fans).
>
> As for /usr/include, CMAKE_PREFIX_PATH and CMAKE_INCLUDE_PATH should
> actually be searched after the paths given by HINTS. Maybe this behavior
> should be adjusted for FIND_PATH?
>
I doubt FIND_PATH can be adjusted for this.
But we can probably fix this by changing FindQt4.cmake to make two calls to
find_path(), the first one with NO_DEFAULT_PATH and the second without. Or
FindQt4.cmake could probably adjust the CMAKE_PREFIX_PATH/CMAKE_INCLUDE_PATH
for itself.
Would you mind adding a bug report for this, so we can look further into it?
Or feel free to look further yourself.
--
Clinton Stimpson
Elemental Technologies, Inc
Computational Simulation Software, LLC
www.csimsoft.com
More information about the cmake-developers
mailing list