buildspec.cmake 3.9 KB

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