is there a Qt +CMAKE +qmake Setup for Dummies out there?
-
The only clear one liner i found explaining how to set up to use CMAKE for compiling a Qt command line program for Windows was in a post in these forums from 2020. A nice man said that all one should need to do is to set the CMAKE_PREFIX_PATH to the QT installation folder .. but is the only person to tell the exact format of the path.
in Windows the newbie would think that having told the Windows installer to put Qt at C:\Qt that would be it, so in a terminal do:
${env:CMAKE_PREFIX_PATH} = ""C:\Qt"
and one would be wrong ..
the answerer said it should be C:/Qt/<versionNum>/<xxx>/lib/cmake/ and that was the first time i had a real clue about what was actually meant by
"set it to the installation directory"
is there a source for the details of what to set CMAKE_* and Qt* enviroment variables to for the various platforms? i use Mac OS and Windows with occasional nostalgic trips into Umbuntu so .. for all of those platforms please
-
The only clear one liner i found explaining how to set up to use CMAKE for compiling a Qt command line program for Windows was in a post in these forums from 2020. A nice man said that all one should need to do is to set the CMAKE_PREFIX_PATH to the QT installation folder .. but is the only person to tell the exact format of the path.
in Windows the newbie would think that having told the Windows installer to put Qt at C:\Qt that would be it, so in a terminal do:
${env:CMAKE_PREFIX_PATH} = ""C:\Qt"
and one would be wrong ..
the answerer said it should be C:/Qt/<versionNum>/<xxx>/lib/cmake/ and that was the first time i had a real clue about what was actually meant by
"set it to the installation directory"
is there a source for the details of what to set CMAKE_* and Qt* enviroment variables to for the various platforms? i use Mac OS and Windows with occasional nostalgic trips into Umbuntu so .. for all of those platforms please
@bitbasher Did you see https://doc.qt.io/qt-6/cmake-build-on-cmdline.html ?
-
yes i saw it .. and it is incorrect .. in Windows if you must use the path all the way to the cmake folder before the cmake.exe is found so ..
= "C:\Qt\6.10.0\mingw64\lib\cmake\bin"and if one is also trying to use QCreator having the env var CMAKE_PREFIX_PATH interferes when you try to select a Kit for a project to work with .. i really should stick to working in the near unix world of Mac OS .. or perhaps go all the way back to Umbuntu
and .. as another poster pointed out .. if you are cross-compiling you MUST also set Qt_DIR to the correct compiler location
so .. is there any doc or page that does the CMAKE +QTfor Dummies?
-
is there a source for the details of what to set CMAKE_* and Qt* enviroment variables to for the various platforms?
I cannot answer that directly.
But this is what I have on windows:
export Qt6_DIR="${WINDLPATH}/Qt_desktop/6.5.3/msvc2019_64/lib/cmake/Qt6/" export Qt5_DIR="${WINDLPATH}/Qt_desktop/5.15.0/msvc2019_64/lib/cmake/Qt5/"(I use a bash terminal on Windows; specifically "git bash" that gets installed with git:
"C:\Program Files\Git\bin\bash.exe")That is the only environment variable that has proven necessary. I do not recall needing to set any other variable before being able to successfully build.
I also check in
CMakeLists.txtto make sure the variable is set:if(NOT DEFINED ENV{Qt6_DIR} ) message( FATAL_ERROR "You must set Qt6_DIR. This project was intended to be very\ strict about requiring your explicit path to your chosen Qt toolchain.\ (remove this check from the project if/when no longer relevant)" ) endif()The rest of this is a bit of an aside about how I can launch the build in Windows from bash (without WSL).
The "trick" basically consists of:
- open cmd.exe
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat""C:\Program Files\Git\bin\bash.exe"- (Note: at this point you are in bash, but with all the MSVC paths configured properly for the MSVC toolchain)
- Run your bash script that invokes
cmake, etc
Proof that this works: here is a github CI action that demonstrates the successful bash-on-Windows Qt-Cmake build.
The only other wrinkle (for git-bash based MSVC builds) is that there is a name collision between MSVC
linkand the bash/gnu util namedlink, which can be worked around thusly:MSVCPATHFORBUILDING=$(cygpath -u "${VCToolsInstallDir}/bin/HOSTx64/x64") export PATH="${MSVCPATHFORBUILDING}:$PATH" # make sure MSVC link.exe is found (not bash/unix 'link' tool) -
In addition the to "proof that this works" link from prior post: https://github.com/219-design/qt-qml-project-template-with-ci/blob/b0abc1b28/.github/workflows/cmakebuild_windows.yml
Here is another well-maintained github repository with a Qt cmake windows build (and github CI actions to prove it builds): https://github.com/emericg/QmlAppTemplate
-
yes i saw it .. and it is incorrect .. in Windows if you must use the path all the way to the cmake folder before the cmake.exe is found so ..
= "C:\Qt\6.10.0\mingw64\lib\cmake\bin"and if one is also trying to use QCreator having the env var CMAKE_PREFIX_PATH interferes when you try to select a Kit for a project to work with .. i really should stick to working in the near unix world of Mac OS .. or perhaps go all the way back to Umbuntu
and .. as another poster pointed out .. if you are cross-compiling you MUST also set Qt_DIR to the correct compiler location
so .. is there any doc or page that does the CMAKE +QTfor Dummies?
@bitbasher said in is there a Qt +CMAKE +qmake Setup for Dummies out there?:
in Windows if you must use the path all the way to the cmake folder before the cmake.exe is found
Not if you add C:\Qt\6.10.0\mingw64\lib\cmake\bin to PATH...