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
- glob to find all subdirectories that looks like version string within Qt5_ROOT
- sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.
- compare the parsed version strings with version_spec to get the requested version
- set the output variable
Could anyone help on any of the above 1, 2, or 3? Thank you!