Results 1 to 6 of 6

Thread: CMake: vcpkg-qt takes precedence over onlineinstaller-qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Thanked 15 Times in 14 Posts
    Qt products

    Default CMake: vcpkg-qt takes precedence over onlineinstaller-qt


    I am using the standard autogenerated CMake-template, with vpckg.
    Thus I have this line at the very top:

    Qt Code:
    1. set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
    To copy to clipboard, switch view to plain text mode 

    Everything works fine when I open this in QtCreater 8 and build it.
    For Kits, I have 5.15 and 6.2 installed from the online installer. I configure both in QtCreator and can then switch between them in the build menu.

    This works fine ... as long as no Qt is installed in vcpkg. If I install "qtbase" vcpkg package (which contains Qt 6.3), then the build will *always* use this Qt installation, no matter what I select in Qt Creator (even when I select Qt 5.15).

    How can I resolve this situation so that CMake prefers the online installer Kits from QtCreator over the vcpkg package?

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

    Default Re: CMake: vcpkg-qt takes precedence over onlineinstaller-qt

    Somewhere, either in the CMakelists.txt file that Qt Creator makes for your project, or perhaps in the vcpkg.cmake toolchain file, there will be a find_package() command that loads the Qt references. This find_package() command takes an optional "version" argument that appears after the package name. There is also a "REQUIRED" argument which causes CMake to fail if the package can't be found.

    There are some predefined constants that are passed in to the Qt package finder in CMake, one of which is QT_DEFAULT_MAJOR_VERSION. See the discussion here, especially the part about setting the value to either 5 or 6 before the find_package() command is called if you have mixed projects.

    You will probably have to modify your CMakelists.txt file to define this appropriately. Qt Creator has a "%(Qt:Version)" variable which I assume changes with the kit, but I don't have any idea how to reference this from within CMake.

    CMake can also take optional command line arguments that pass variables into CMake. I don't use Qt Creator much, especially not with CMake, so I do not know how Qt Creator invokes CMake. If you can specify a command line argument on a kit by kit basis, then that is where you could set a value for the QT_DEFAULT_MAJOR_VERSION variable.

    Thanks for this. I had no idea it existed and it looks like it could be useful. Sort of Microsoft's answer for the C++ world to Python's pip and conda I suppose.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    tuli (23rd September 2022)

Similar Threads

  1. deploy vcpkg dependencies in QtCreator-Cmake
    By tuli in forum Installation and Deployment
    Replies: 2
    Last Post: 23rd August 2021, 18:44
  2. Using QLoggingCategory, rules precedence seem backwards
    By in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2014, 19:17
  3. Qt server, which takes http-requests
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 2nd July 2012, 11:04
  4. QProgressBar takes big steps
    By Jayes in forum Qt Programming
    Replies: 14
    Last Post: 24th March 2012, 00:01
  5. QGraphicsItem.setPos takes a lot of time
    By ricofe25 in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2009, 20:28

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.