buildspec.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # OBS CMake Windows build dependencies module
  2. include_guard(GLOBAL)
  3. include(buildspec_common)
  4. # _handle_qt_cross_compile: Check for and handle cross compiled Qt dependency
  5. function(_handle_qt_cross_compile architecture)
  6. set(options "")
  7. set(oneValueArgs DIRECTORY)
  8. set(multiValueArgs "")
  9. cmake_parse_arguments(PARSE_ARGV 0 _HQCC "${options}" "${oneValueArgs}" "${multiValueArgs}")
  10. _get_dependency_data(dependency_data)
  11. string(JSON data GET ${dependency_data} qt6)
  12. string(JSON version GET ${data} version)
  13. set(qt_build_arch "")
  14. set(qt_target_arch "")
  15. set(host_arch "")
  16. set(platform_name "")
  17. set(config_has_buildabi FALSE)
  18. set(qt_cross_compiled FALSE)
  19. string(REPLACE "VERSION" "${version}" directory "${_HQCC_DIRECTORY}")
  20. string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" platform_name)
  21. string(REPLACE "ARCH" "${platform_name}" qt_arch_location "${directory}")
  22. file(READ "${qt_arch_location}/mkspecs/qconfig.pri" qt_arch_config)
  23. string(REGEX MATCH ".+QT_TARGET_BUILDABI = (.+)\n.+" config_has_buildabi "${qt_arch_config}")
  24. if(config_has_buildabi)
  25. string(
  26. REGEX REPLACE
  27. "host_build {\n[ \t]+QT_ARCH = (x86_64|arm64)\n.+[ \t]+QT_TARGET_ARCH = (x86_64|arm64)\n.+}.+"
  28. "\\1;\\2"
  29. host_build_tuple
  30. "${qt_arch_config}"
  31. )
  32. list(GET host_build_tuple 0 qt_build_arch)
  33. list(GET host_build_tuple 1 qt_target_arch)
  34. set(qt_cross_compiled TRUE)
  35. else()
  36. string(REGEX REPLACE ".*QT_ARCH = (x86_64|arm64)\n.+" "\\1" build_arch "${qt_arch_config}")
  37. set(qt_build_arch "${build_arch}")
  38. set(qt_target_arch "${build_arch}")
  39. endif()
  40. if(NOT qt_build_arch MATCHES "x86_64|arm64" OR NOT qt_target_arch MATCHES "x86_64|arm64")
  41. message(FATAL_ERROR "Unable to detect host or target architecture from Qt dependencies in '${qt_arch_location}'")
  42. endif()
  43. string(REPLACE "x86_64" "x64" qt_build_arch "${qt_build_arch}")
  44. string(REPLACE "x86_64" "x64" qt_target_arch "${qt_target_arch}")
  45. string(REPLACE "AMD64" "x64" architecture "${architecture}")
  46. string(REPLACE "ARM64" "arm64" architecture "${architecture}")
  47. if(NOT qt_cross_compiled)
  48. if(architecture STREQUAL qt_target_arch OR (architecture STREQUAL arm64 AND qt_target_arch STREQUAL x64))
  49. unset(QT_HOST_PATH CACHE)
  50. unset(QT_REQUIRE_HOST_PATH_CHECK CACHE)
  51. return()
  52. endif()
  53. set(QT_REQUIRE_HOST_PATH_CHECK TRUE CACHE STRING "Qt Host Tools Check Required" FORCE)
  54. endif()
  55. if(NOT DEFINED QT_HOST_PATH)
  56. string(REPLACE "${qt_target_arch}" "${architecture}" host_tools_directory "${qt_arch_location}")
  57. if(NOT IS_DIRECTORY "${host_tools_directory}")
  58. message(
  59. FATAL_ERROR
  60. "Required Qt host tools for ${architecture} when building for ${qt_target_arch} not found in '${host_tools_directory}'"
  61. )
  62. endif()
  63. set(QT_HOST_PATH "${host_tools_directory}" CACHE STRING "Qt Host Tools Path" FORCE)
  64. endif()
  65. endfunction()
  66. # _check_dependencies_windows: Set up Windows slice for _check_dependencies
  67. function(_check_dependencies_windows)
  68. set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps")
  69. set(prebuilt_filename "windows-deps-VERSION-ARCH-REVISION.zip")
  70. set(prebuilt_destination "obs-deps-VERSION-ARCH")
  71. set(qt6_filename "windows-deps-qt6-VERSION-ARCH-REVISION.zip")
  72. set(qt6_destination "obs-deps-qt6-VERSION-ARCH")
  73. set(cef_filename "cef_binary_VERSION_windows_ARCH_REVISION.zip")
  74. set(cef_destination "cef_binary_VERSION_windows_ARCH")
  75. if(CMAKE_VS_PLATFORM_NAME STREQUAL Win32)
  76. set(arch x86)
  77. set(dependencies_list prebuilt)
  78. else()
  79. string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" arch)
  80. set(dependencies_list prebuilt qt6 cef)
  81. endif()
  82. set(platform windows-${arch})
  83. _check_dependencies(${dependencies_list})
  84. if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL Win32)
  85. _handle_qt_cross_compile(${CMAKE_HOST_SYSTEM_PROCESSOR} DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.deps/${qt6_destination}")
  86. endif()
  87. endfunction()
  88. _check_dependencies_windows()