QtConfiguration.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. include(FetchDependencies)
  2. if(WIN32)
  3. set(WINARCHSTR ARCHSTR windows-x86_64)
  4. endif(WIN32)
  5. if((NOT IS_DIRECTORY ${QTROOT}) AND (NOT "${QTROOT}" STREQUAL ""))
  6. # Write qt.conf in the Qt depends directory so that the Qt tools can find QML files
  7. set(QTCONFCONTENT "[Paths]
  8. Prefix=${QTROOT}
  9. ")
  10. file(WRITE ${QTROOT}/bin/qt.conf ${QTCONFCONTENT})
  11. endif()
  12. message(STATUS "Qt root directory: ${QTROOT}")
  13. list(APPEND CMAKE_FIND_ROOT_PATH ${QTROOT})
  14. list(APPEND CMAKE_PREFIX_PATH ${QTROOT})
  15. include_directories(${QTROOT}/include)
  16. set(REQUIRED_QT_VERSION "5.7.0")
  17. set(QTCONFIGROOT ${QTROOT}/lib/cmake/Qt5)
  18. set(components Core Network WebChannel Qml Quick Xml WebEngine Widgets)
  19. if(UNIX AND (NOT APPLE) AND ((NOT BUILD_TARGET STREQUAL "RPI")))
  20. add_definitions(-DUSE_X11EXTRAS)
  21. set(components ${components} X11Extras)
  22. endif()
  23. if(LINUX_DBUS)
  24. set(components ${components} DBus)
  25. endif(LINUX_DBUS)
  26. foreach(COMP ${components})
  27. set(mod Qt5${COMP})
  28. # look for the config files in the QtConfigRoot defined above
  29. set(${mod}_DIR ${QTCONFIGROOT}${COMP})
  30. # look for the actual package
  31. find_package(${mod} ${REQUIRED_QT_VERSION} REQUIRED)
  32. include_directories(${${mod}_INCLUDE_DIRS})
  33. if(OPENELEC)
  34. include_directories(${${mod}_PRIVATE_INCLUDE_DIRS})
  35. endif(OPENELEC)
  36. list(APPEND QT5_LIBRARIES ${${mod}_LIBRARIES})
  37. list(APPEND QT5_CFLAGS ${${mod}_EXECUTABLE_COMPILE_FLAGS})
  38. endforeach(COMP ${components})
  39. if(QT5_CFLAGS)
  40. list(REMOVE_DUPLICATES QT5_CFLAGS)
  41. if(WIN32)
  42. list(REMOVE_ITEM QT5_CFLAGS -fPIC)
  43. endif(WIN32)
  44. endif(QT5_CFLAGS)
  45. message(STATUS "Qt version: ${Qt5Core_VERSION_STRING}")
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT5_CFLAGS}")
  47. set(CMAKE_REQUIRED_INCLUDES ${Qt5WebEngine_INCLUDE_DIRS};${Qt5WebEngine_PRIVATE_INCLUDE_DIRS})
  48. set(CMAKE_REQUIRED_LIBRARIES ${QT5_LIBRARIES})
  49. include(CheckCXXSourceCompiles)
  50. CHECK_CXX_SOURCE_COMPILES(
  51. "
  52. #include <QSurfaceFormat>
  53. int main(int argc, char** argv) {
  54. QSurfaceFormat::FormatOption o = QSurfaceFormat::UseOptimalOrientation;
  55. return 0;
  56. }
  57. " QT5_HAVE_OPTIMALORIENTATION)
  58. if(QT5_HAVE_OPTIMALORIENTATION)
  59. message(STATUS "QSurfaceFormat::UseOptimalOrientation found")
  60. add_definitions(-DHAVE_OPTIMALORIENTATION)
  61. endif()