-if (USE_QT5)
- find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
- set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
- URL "http://qt.digia.com"
- DESCRIPTION "contains core functionality for Qt"
- )
- # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
- # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
- if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
- message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
+# Required Qt components
+set(qt_components Core Network)
+if (BUILD_GUI)
+ list(APPEND qt_components Gui Widgets)
+endif()
+if (BUILD_CORE)
+ list(APPEND qt_components Sql)
+endif()
+
+find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${qt_components})
+set_package_properties(Qt5 PROPERTIES TYPE REQUIRED
+ URL "https://www.qt.io/"
+ DESCRIPTION "the Qt libraries"
+)
+message(STATUS "Found Qt ${Qt5Core_VERSION}")
+
+# Determine minimum deployment target for macOS supported by Qt
+if(APPLE)
+ if(NOT QMAKE_MACOSX_DEPLOYMENT_TARGET)
+ # qmake cannot be queried directly for QMAKE_MACOSX_DEPLOYMENT_TARGET (it is a mkspec, not a property).
+ # Instead, invoke qmake on an empty project file, which causes it to output the relevant keys and their values
+ # for subsequent parsing.
+ # A file named .qmake.stash is always created, so remove it (and empty.pro) afterwards.
+ set(qmakeEmptyProjectFile "${CMAKE_BINARY_DIR}/empty.pro")
+ set(qmakeStashFile "${CMAKE_BINARY_DIR}/.qmake.stash")
+ file(WRITE ${qmakeEmptyProjectFile} "")
+ get_target_property(QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
+ execute_process(
+ COMMAND ${QMAKE_EXECUTABLE} -E ${qmakeEmptyProjectFile}
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ OUTPUT_VARIABLE qmakeOutput
+ )
+ file(REMOVE ${qmakeEmptyProjectFile} ${qmakeStashFile})
+ string(REGEX MATCH "QMAKE_MACOSX_DEPLOYMENT_TARGET[ ]*=[ ]*([0-9.]+)" foo ${qmakeOutput})
+ if(NOT CMAKE_MATCH_1)
+ message(FATAL_ERROR "Could not determine the deployment target for Qt")
+ endif()
+ set(QMAKE_MACOSX_DEPLOYMENT_TARGET ${CMAKE_MATCH_1} CACHE INTERNAL "")
+ mark_as_advanced(QMAKE_MACOSX_DEPLOYMENT_TARGET)