QtConfiguration.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Gui)
  22. endif()
  23. if(LINUX_DBUS)
  24. set(components ${components} DBus)
  25. endif(LINUX_DBUS)
  26. if(WIN32)
  27. set(components ${components} WinExtras)
  28. endif(WIN32)
  29. foreach(COMP ${components})
  30. set(mod Qt5${COMP})
  31. # look for the config files in the QtConfigRoot defined above
  32. set(${mod}_DIR ${QTCONFIGROOT}${COMP})
  33. # look for the actual package
  34. find_package(${mod} ${REQUIRED_QT_VERSION} REQUIRED)
  35. include_directories(${${mod}_INCLUDE_DIRS})
  36. if(OPENELEC)
  37. include_directories(${${mod}_PRIVATE_INCLUDE_DIRS})
  38. endif(OPENELEC)
  39. # Need private interfaces for qpa/qplatformnativeinterface.h:
  40. if(${mod} STREQUAL Qt5Gui)
  41. include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
  42. endif()
  43. list(APPEND QT5_LIBRARIES ${${mod}_LIBRARIES})
  44. list(APPEND QT5_CFLAGS ${${mod}_EXECUTABLE_COMPILE_FLAGS})
  45. endforeach(COMP ${components})
  46. if(QT5_CFLAGS)
  47. list(REMOVE_DUPLICATES QT5_CFLAGS)
  48. if(WIN32)
  49. list(REMOVE_ITEM QT5_CFLAGS -fPIC)
  50. endif(WIN32)
  51. endif(QT5_CFLAGS)
  52. message(STATUS "Qt version: ${Qt5Core_VERSION_STRING}")
  53. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT5_CFLAGS}")
  54. set(CMAKE_REQUIRED_INCLUDES ${Qt5WebEngine_INCLUDE_DIRS};${Qt5WebEngine_PRIVATE_INCLUDE_DIRS})
  55. set(CMAKE_REQUIRED_LIBRARIES ${QT5_LIBRARIES})
  56. include(CheckCXXSourceCompiles)
  57. CHECK_CXX_SOURCE_COMPILES(
  58. "
  59. #include <QSurfaceFormat>
  60. int main(int argc, char** argv) {
  61. QSurfaceFormat::FormatOption o = QSurfaceFormat::UseOptimalOrientation;
  62. return 0;
  63. }
  64. " QT5_HAVE_OPTIMALORIENTATION)
  65. if(QT5_HAVE_OPTIMALORIENTATION)
  66. message(STATUS "QSurfaceFormat::UseOptimalOrientation found")
  67. add_definitions(-DHAVE_OPTIMALORIENTATION)
  68. endif()