MantisBT - CMake
View Issue Details
0011779CMakeCMakepublic2011-01-31 16:382011-01-31 17:09
Jean Porcherot 
Clinton Stimpson 
normalfeaturealways
closedfixed 
WindowsXP/Seven
CMake 2.8.3 
 
0011779: FindQt4 fails because I re-organised my Qt folder
- I download and compiled Qt 4.7.1, let's say from C:/Qt/4.7.1
- To make it easier for other developers from my company to use Qt, I then moved the src/include/lib/bin folders to our internal SVN repository (I used to do this with Qt 4.5.2 and an earlier cmake version). Then, all our developers can use Qt without having to install it locally on their machine.
- Later, we try to have cmake work with a working copy checked-out from this repository on a different machine (we cannot use the orginial folder where I unzipped and compiled Qt sources). Let's say this working copy is in C:/MyWC, it contains a sub folder (C:/MyWC/qt) with src/include/lib/bin Qt files copied above, ready to be used.

Unfortunately some problems then appear:

1- FindQt4.cmake will fail to find qmake. One workaround could be to set QTDIR but, for other reasons, I don't want to do that. Ideally, I would say that, if QT_QMAKE_EXECUTABLE is already set, FIND_PROGRAM( QT_QMAKE_EXECUTABLE ... ) should not be called in FindQt4.cmake. This would make it easy, in my case, to tell cmake where to fing qmake
2- Now I modified FindQt4.cmake as mentioned in (1-) above, I'm in face of a harder problem. FindQt4.cmake asks qmake to tell where lib/bin/include....folders are. And, obviously, qmake reports they are located in C:/Qt/4.7.1, when I expect it to use them from C:/MyWC/qt, as C:/Qt/4.7.1 is not present on this machine (I suppose this original Qt folder is hardly coded in qmake, as I did not run any installer, this folder is not referenced in my environement variable nor in my registry). I'm pretty sure there is a good reason to do so, but, it would be great if, as a cmake user, I could force those locations as I know where I want those files/folders to be picked from.

Personnaly, I modified FindQt4.cmake. I protected two statements as below:

line 460:
IF( NOT QT_QMAKE_EXECUTABLE ) # Added by Jean
# check for qmake
# Debian uses qmake-qt4
# macports' Qt uses qmake-mac
FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake qmake4 qmake-qt4 qmake-mac PATHS
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]/bin"
  $ENV{QTDIR}/bin
  DOC "The qmake executable for the Qt installation to use"
)
ENDIF()

line 601;
IF (NOT QT_LIBRARY_DIR_TMP) #Test added by Jean
    _qt4_query_qmake(QT_INSTALL_LIBS QT_LIBRARY_DIR_TMP)
ENDIF()

Then, I invoke find_package as below:

set( QT_INCLUDE_DIR C:/MyWC/qt/include )
set( QT_HEADERS_DIR C:/MyWC/qt/include )
set( QT_LIBRARY_DIRC:/MyWC/qt/lib )
set( QT_BINARY_DIR C:/MyWC/qt/bin )
set( QT_LIBRARY_DIR_TMP ${QT_LIBRARY_DIR} )
set( QT_QMAKE_EXECUTABLE ${QT_BINARY_DIR}/qmake.exe )
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED )
set( QT_QTCORE_INCLUDE_DIR ${QT_INCLUDE_DIR} )

It works fine! So, I'm wondering if it would make sense to have those 2 small changes I did in FindQt4.cmake be incorporated in the next cmake release. To make FindQt4.cmake behaviour customizable. Let the cmake script setup the whole Qt/Cmake variables, but, have a way to force the Qt original sources/include/lib and bin major locations on disk.

If there is an alternative solution, I would be glad to know it....maybe I missed a point...
No tags attached.
related to 0011789closed Clinton Stimpson Unable to force a Qt version to be picked by cmake 
Issue History
2011-01-31 16:38Jean PorcherotNew Issue
2011-01-31 17:01James BiglerNote Added: 0025189
2011-01-31 17:09Clinton StimpsonNote Added: 0025190
2011-01-31 17:09Clinton StimpsonStatusnew => closed
2011-01-31 17:09Clinton StimpsonAssigned To => Clinton Stimpson
2011-01-31 17:09Clinton StimpsonResolutionopen => fixed
2011-02-03 08:15Brad KingRelationship addedrelated to 0011789

Notes
(0025189)
James Bigler   
2011-01-31 17:01   
You can fix the relocation issue with a qt.conf file in the same directory as qmake.exe. This is what we do with qt checked into our source tree. In fact, we have CMake write the qt.conf file as part of the configure step.

qt.conf:

[Paths]
Prefix = C:/code/sw/3rdparty/Qt/qt-win32-msvc2008
Plugins = C:/code/sw/3rdparty/Qt/qt-win32-msvc2008/plugins

qt.conf.in:
[Paths]
Prefix = $ENV{QTDIR}
Plugins = $ENV{QTDIR}/plugins

CMakeLists.txt:

# Set QTDIR and or QT_DIST to whatever you want
set(ENV{QTDIR} "${CMAKE_SOURCE_DIR}/3rdparty/Qt/${QT_DIST}")

# Create the qt.conf file. This needs to happen before you call find_package
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.in" "$ENV{QTDIR}/bin/qt.conf")
# Also set it in the build directory for run time location of Qt libraries.
foreach(config ${CMAKE_CONFIGURATION_TYPES})
  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.in" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${config}/qt.conf")
endforeach()

find_package(Qt4 REQUIRED)
(0025190)
Clinton Stimpson   
2011-01-31 17:09   
Yeah, what James said...
Its the same thing people do to make Qt work when packaged with an app and given to other users.