ECMQueryQmake.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. find_package(Qt5Core QUIET)
  2. if (Qt5Core_FOUND)
  3. set(_qmake_executable_default "qmake-qt5")
  4. endif ()
  5. if (TARGET Qt5::qmake)
  6. get_target_property(_qmake_executable_default Qt5::qmake LOCATION)
  7. endif()
  8. set(QMAKE_EXECUTABLE ${_qmake_executable_default}
  9. CACHE FILEPATH "Location of the Qt5 qmake executable")
  10. # Helper method
  11. # This is not public API (yet)!
  12. # Usage: query_qmake(<result_variable> <qt_variable> [TRY])
  13. # Passing TRY will result in the method not failing fatal if no qmake executable
  14. # has been found, but instead simply returning an empty string
  15. function(query_qmake result_variable qt_variable)
  16. set(options TRY)
  17. set(oneValueArgs )
  18. set(multiValueArgs )
  19. cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  20. if(NOT QMAKE_EXECUTABLE)
  21. if(ARGS_TRY)
  22. set(${result_variable} "" PARENT_SCOPE)
  23. message(STATUS "No qmake Qt5 binary found. Can't check ${qt_variable}")
  24. return()
  25. else()
  26. message(FATAL_ERROR "No qmake Qt5 binary found. Can't check ${qt_variable} as required")
  27. endif()
  28. endif()
  29. execute_process(
  30. COMMAND ${QMAKE_EXECUTABLE} -query "${qt_variable}"
  31. RESULT_VARIABLE return_code
  32. OUTPUT_VARIABLE output
  33. )
  34. if(return_code EQUAL 0)
  35. string(STRIP "${output}" output)
  36. file(TO_CMAKE_PATH "${output}" output_path)
  37. set(${result_variable} "${output_path}" PARENT_SCOPE)
  38. else()
  39. message(WARNING "Failed call: ${QMAKE_EXECUTABLE} -query \"${qt_variable}\"")
  40. message(FATAL_ERROR "QMake call failed: ${return_code}")
  41. endif()
  42. endfunction()