From f4417bf7e8f843438345f496cf5d6a9b6fa33709 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 15 Apr 2021 16:41:02 +0200 Subject: [PATCH] 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 --- config.tests/cmake_zstd/check_zstd.cmake | 5 +++++ configure.cmake | 18 ++++++++++++++++++ src/corelib/CMakeLists.txt | 5 +++++ 3 files changed, 28 insertions(+) create mode 100644 config.tests/cmake_zstd/check_zstd.cmake diff --git a/config.tests/cmake_zstd/check_zstd.cmake b/config.tests/cmake_zstd/check_zstd.cmake new file mode 100644 index 00000000000..267494f90b1 --- /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 840d5f586cb..cfd355dcfe2 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 2af8854798c..3c6b20636a5 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()