How do you get CMake to compile conditionally with Qt4.8 or Qt5? In other words, if Qt5 is available then compile with Qt5. Otherwise if Qt4.8 is available use that.
In my CMake, I have:
find_package(Qt5 COMPONENTS Core Gui Widgets...)
This works fine with my Qt5 builds, but how do I get the same software to build with Qt4.8?
I need something that contains the major version number, eg.:
find_package(Qt $QT_VERSION_MAJOR...)
or to use a condition, such as:
result = find_package(Qt 5...)
if (!result) then find_package(Qt4 ...)
or somehow detect the currently install Qt version.
The error I get for the machine with Qt4.8 installed is (unsurprisingly):
CMake Error at CMakeLists.txt:54 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
What is the best approach here?