Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. is there a Qt +CMAKE +qmake Setup for Dummies out there?
Forum Updated to NodeBB v4.3 + New Features

is there a Qt +CMAKE +qmake Setup for Dummies out there?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 100 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bitbasher
    wrote last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • B bitbasher

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote last edited by
      #2

      @bitbasher Did you see https://doc.qt.io/qt-6/cmake-build-on-cmdline.html ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • B Offline
        B Offline
        bitbasher
        wrote last edited by
        #3

        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?

        jsulmJ 1 Reply Last reply
        0
        • KH-219DesignK Offline
          KH-219DesignK Offline
          KH-219Design
          wrote last edited by KH-219Design
          #4

          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.txt to 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 link and the bash/gnu util named link, 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)
          

          www.219design.com
          Software | Electrical | Mechanical | Product Design

          1 Reply Last reply
          1
          • KH-219DesignK Offline
            KH-219DesignK Offline
            KH-219Design
            wrote last edited by
            #5

            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

            www.219design.com
            Software | Electrical | Mechanical | Product Design

            1 Reply Last reply
            0
            • B bitbasher

              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?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote last edited by
              #6

              @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...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved