Skip to content

Commit

Permalink
Check whether CMake was built with zstd support
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jobor committed Apr 16, 2021
1 parent 5656a60 commit f4417bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.tests/cmake_zstd/check_zstd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file(ARCHIVE_CREATE
OUTPUT cmake_zstd.zstd
PATHS "${CMAKE_CURRENT_LIST_FILE}"
FORMAT raw
COMPRESSION Zstd)
18 changes: 18 additions & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f4417bf

Please sign in to comment.