Skip to content

Instantly share code, notes, and snippets.

@cristianadam
Created October 30, 2020 10:31
Show Gist options
  • Save cristianadam/f92fd7f32ee6f9bce313300d8ed965a2 to your computer and use it in GitHub Desktop.
Save cristianadam/f92fd7f32ee6f9bce313300d8ed965a2 to your computer and use it in GitHub Desktop.
CMake script to download qt5. Just need to run `cmake -P download_qt5.cmake`. Tested on Windows, Linux, macOS. For Mingw use `cmake -P download_qt5.cmake mingw`
set(qt_version "5.15.1")
string(REPLACE "." "" qt_version_dotless "${qt_version}")
if (WIN32)
set(url_os "windows_x86")
if (CMAKE_ARG_3 STREQUAL "mingw")
set(qt_package_arch_suffix "win64_mingw81")
set(qt_dir_prefix "${qt_version}/mingw81_64")
set(qt_package_suffix "-Windows-Windows_10-Mingw-Windows-Windows_10-X86_64")
else()
set(qt_package_arch_suffix "win64_msvc2019_64")
set(qt_dir_prefix "${qt_version}/msvc2019_64")
set(qt_package_suffix "-Windows-Windows_10-MSVC2019-Windows-Windows_10-X86_64")
endif()
elseif (APPLE)
set(url_os "mac_x64")
set(qt_package_arch_suffix "clang_64")
set(qt_dir_prefix "${qt_version}/clang_64")
set(qt_package_suffix "-MacOS-MacOS_10_13-Clang-MacOS-MacOS_10_13-X86_64")
else()
set(url_os "linux_x64")
set(qt_package_arch_suffix "gcc_64")
set(qt_dir_prefix "${qt_version}/gcc_64")
set(qt_package_suffix "-Linux-RHEL_7_6-GCC-Linux-RHEL_7_6-X86_64")
endif()
set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt5_${qt_version_dotless}")
file(DOWNLOAD "${qt_base_url}/Updates.xml" ./Updates.xml SHOW_PROGRESS)
file(READ ./Updates.xml updates_xml)
string(REGEX MATCH "<Name>qt.qt5.*<Version>([0-9+-.]+)</Version>" updates_xml_output "${updates_xml}")
set(qt_package_version ${CMAKE_MATCH_1})
file(MAKE_DIRECTORY qt5)
function(downloadAndExtract url archive)
message("Downloading ${url}")
file(DOWNLOAD "${url}" ./${archive} SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ../${archive} WORKING_DIRECTORY qt5)
endfunction()
foreach(package qtbase qtdeclarative qttools qtsvg qtserialport qtquickcontrols qtquickcontrols2 qtgraphicaleffects qtlocation qtimageformats qttranslations)
downloadAndExtract(
"${qt_base_url}/qt.qt5.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z"
${package}.7z
)
endforeach()
foreach(package qtquicktimeline qtquick3d qtscript)
downloadAndExtract(
"${qt_base_url}/qt.qt5.${qt_version_dotless}.${package}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z"
${package}.7z
)
endforeach()
# uic depends on libicu56.so
if (NOT WIN32 AND NOT APPLE)
downloadAndExtract(
"${qt_base_url}/qt.qt5.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}icu-linux-Rhel7.2-x64.7z"
icu.7z
)
endif()
file(READ "qt5/${qt_dir_prefix}/mkspecs/qconfig.pri" qtconfig)
string(REPLACE "Enterprise" "OpenSource" qtconfig "${qtconfig}")
string(REPLACE "licheck.exe" "" qtconfig "${qtconfig}")
string(REPLACE "licheck64" "" qtconfig "${qtconfig}")
string(REPLACE "licheck_mac" "" qtconfig "${qtconfig}")
file(WRITE "qt5/${qt_dir_prefix}/mkspecs/qconfig.pri" "${qtconfig}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment