diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-04-15 16:41:02 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-04-16 16:49:28 +0200 |
commit | f4417bf7e8f843438345f496cf5d6a9b6fa33709 (patch) | |
tree | 502ea3d41257505a9c899ebab75d13ab9a97cfcf | |
parent | 5656a60dd067a69f9e864a33068ec300124d4e05 (diff) | |
download | qtbase-f4417bf7e8f843438345f496cf5d6a9b6fa33709.tar.gz |
Check whether CMake was built with zstd support
CMake 3.18 introduced the file(ARCHIVE_CREATE) API that we use with
COMPRESSION Zstd for compressing corelib's mimedatabase.
It's possible to build CMake without proper zstd support, and we have
encountered such builds in the wild where the file(ARCHIVE_CREATE) call
crashes.
Add a configure test to determine whether CMake properly supports the
Zstd compression method.
Fixes: QTBUG-89108
Change-Id: I37e389c878845162b6f18457984d4f73a265b604
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | config.tests/cmake_zstd/check_zstd.cmake | 5 | ||||
-rw-r--r-- | configure.cmake | 18 | ||||
-rw-r--r-- | src/corelib/CMakeLists.txt | 5 |
3 files changed, 28 insertions, 0 deletions
diff --git a/config.tests/cmake_zstd/check_zstd.cmake b/config.tests/cmake_zstd/check_zstd.cmake new file mode 100644 index 0000000000..267494f90b --- /dev/null +++ b/config.tests/cmake_zstd/check_zstd.cmake @@ -0,0 +1,5 @@ +file(ARCHIVE_CREATE + OUTPUT cmake_zstd.zstd + PATHS "${CMAKE_CURRENT_LIST_FILE}" + FORMAT raw + COMPRESSION Zstd) diff --git a/configure.cmake b/configure.cmake index 840d5f586c..cfd355dcfe 100644 --- a/configure.cmake +++ b/configure.cmake @@ -830,6 +830,24 @@ qt_feature("zstd" PRIVATE LABEL "Zstandard support" CONDITION ZSTD_FOUND ) +# special case begin +# Check whether CMake was built with zstd support. +# See https://gitlab.kitware.com/cmake/cmake/-/issues/21552 +if(NOT DEFINED CACHE{QT_CMAKE_ZSTD_SUPPORT}) + set(QT_CMAKE_ZSTD_SUPPORT FALSE CACHE INTERNAL "") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") + execute_process(COMMAND "${CMAKE_COMMAND}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/config.tests/cmake_zstd/check_zstd.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/config.tests" + OUTPUT_QUIET ERROR_QUIET + RESULT_VARIABLE qt_check_zstd_exit_code) + if(qt_check_zstd_exit_code EQUAL 0) + set(QT_CMAKE_ZSTD_SUPPORT TRUE CACHE INTERNAL "") + endif() + unset(qt_check_zstd_exit_code) + endif() +endif() +# special case end qt_feature("thread" PUBLIC SECTION "Kernel" LABEL "Thread support" diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 2af8854798..3c6b20636a 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -1187,6 +1187,11 @@ if(QT_FEATURE_mimetype AND QT_FEATURE_mimetype_database) ) else() if(QT_FEATURE_zstd) + if(NOT QT_CMAKE_ZSTD_SUPPORT) + message(FATAL_ERROR + "CMake was not built with zstd support. " + "Rebuild CMake or set QT_AVOID_CMAKE_ARCHIVING_API=ON.") + endif() set(qmime_db_compression Zstd) string(APPEND qmime_db_content "#define MIME_DATABASE_IS_ZSTD\n") else() |