QtConfiguration.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. 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. # Need private interfaces for qpa/qplatformnativeinterface.h:
  37. if(${mod} STREQUAL Qt5Gui)
  38. include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
  39. endif()
  40. list(APPEND QT5_LIBRARIES ${${mod}_LIBRARIES})
  41. list(APPEND QT5_CFLAGS ${${mod}_EXECUTABLE_COMPILE_FLAGS})
  42. endforeach(COMP ${components})
  43. if(QT5_CFLAGS)
  44. list(REMOVE_DUPLICATES QT5_CFLAGS)
  45. if(WIN32)
  46. list(REMOVE_ITEM QT5_CFLAGS -fPIC)
  47. endif(WIN32)
  48. endif(QT5_CFLAGS)
  49. message(STATUS "Qt version: ${Qt5Core_VERSION_STRING}")
  50. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT5_CFLAGS}")
  51. set(CMAKE_REQUIRED_INCLUDES ${Qt5WebEngine_INCLUDE_DIRS};${Qt5WebEngine_PRIVATE_INCLUDE_DIRS})
  52. set(CMAKE_REQUIRED_LIBRARIES ${QT5_LIBRARIES})
  53. include(CheckCXXSourceCompiles)
  54. CHECK_CXX_SOURCE_COMPILES(
  55. "
  56. #include <QSurfaceFormat>
  57. int main(int argc, char** argv) {
  58. QSurfaceFormat::FormatOption o = QSurfaceFormat::UseOptimalOrientation;
  59. return 0;
  60. }
  61. " QT5_HAVE_OPTIMALORIENTATION)
  62. if(QT5_HAVE_OPTIMALORIENTATION)
  63. message(STATUS "QSurfaceFormat::UseOptimalOrientation found")
  64. add_definitions(-DHAVE_OPTIMALORIENTATION)
  65. endif()