0

I am converting a qmake project to cmake, and I am able to get it work, except the part that equivalent to !versionAtLeast(QT_VERSION, 5.11): error("Use at least Qt version 5.11".

The issue here is that I am currently using a user-supplied variable -DQt5_PREFIX=/path/to/Qt5/prefix to inform CMake the location of the Qt libs. In macOS, this is /Applications/Qt5/5.xx.x/clang_64 by default.

What I would like to achieve in my cmake scripts is a function that works as the following:

set(Qt_ROOT "/Applications/Qt")
GetQt5Prefix(Qt5_PREFIX ${Qt_ROOT} version_spec)
message("use Qt5 from ${Qt5_PREFIX}")

# suppose that in /Applications/Qt,
# I have three Qt: 5.11.2, 5.10.3 5.12.1
# the above will print "use Qt5 from"
# 5.12.1 if version_spec is 5
# 5.11.2 if version_spec is 5.11
# empty if version_spec is 5.10.1

From what I've got so far, I would image this function should do

  1. glob to find all subdirectories that looks like version string within Qt5_ROOT
  2. sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.
  3. compare the parsed version strings with version_spec to get the requested version
  4. set the output variable

Could anyone help on any of the above 1, 2, or 3? Thank you!

Jerry Ma
  • 511
  • 4
  • 15
  • 1
    What is wrong in using `find_package(QT5 5.11 REQUIRED)` when search for QT? Such way CMake will emit an error if version of QT5 is too small. – Tsyvarev Jan 01 '19 at 09:54
  • The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within `${QT_ROOT}`, to `CMAKE_PREFIX_PATH`. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2 – Jerry Ma Jan 03 '19 at 04:12

0 Answers0