diff options
author | Brad King <brad.king@kitware.com> | 2022-02-24 17:57:25 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-02-24 17:57:32 (GMT) |
commit | 9568325cf49fd9102f1da113214153c53ac2a725 (patch) | |
tree | e0abbd3668184f932d64a5556e8f8e5f253e8b65 | |
parent | 39a3c3eda3cf49ab3da584e7ca63c5b0052df6c6 (diff) | |
parent | 525faec4e9d7a25431504d6fe47313f1478b26e9 (diff) | |
download | CMake-9568325cf49fd9102f1da113214153c53ac2a725.zip CMake-9568325cf49fd9102f1da113214153c53ac2a725.tar.gz CMake-9568325cf49fd9102f1da113214153c53ac2a725.tar.bz2 |
Merge topic 'cpack-zstd-parallel'
525faec4e9 CPack: Add parallel zstd compression
215c4efd3e cmArchiveWrite: Factor out thread count selection
29f63129be CPack: Format CPACK_THREADS compression methods as a definition list
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7003
-rw-r--r-- | Help/release/dev/cpack-zstd-parallel.rst | 6 | ||||
-rw-r--r-- | Modules/CPack.cmake | 23 | ||||
-rw-r--r-- | Source/cmArchiveWrite.cxx | 59 |
3 files changed, 57 insertions, 31 deletions
diff --git a/Help/release/dev/cpack-zstd-parallel.rst b/Help/release/dev/cpack-zstd-parallel.rst new file mode 100644 index 0000000..da22625 --- /dev/null +++ b/Help/release/dev/cpack-zstd-parallel.rst @@ -0,0 +1,6 @@ +cpack-zstd-parallel +------------------- + +* CPack now supports the :variable:`CPACK_THREADS` option for ``zstd`` + compression when compiled with libarchive 3.6 or higher. It is + supported by official CMake binaries available on ``cmake.org``. diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 6650f7c..5a22be5 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -304,14 +304,25 @@ installers. The most commonly-used variables are: By default ``CPACK_THREADS`` is set to ``1``. - Currently only ``xz`` compression *may* take advantage of multiple cores. - Other compression methods ignore this value and use only one thread. + The following compression methods may take advantage of multiple cores: + + ``xz`` + Supported if CMake is built with a ``liblzma`` that supports + parallel compression. + + .. versionadded:: 3.21 - .. versionadded:: 3.21 + Official CMake binaries available on ``cmake.org`` now ship + with a ``liblzma`` that supports parallel compression. + Older versions did not. - Official CMake binaries available on ``cmake.org`` now ship - with a ``liblzma`` that supports parallel compression. - Older versions did not. + ``zstd`` + .. versionadded:: 3.24 + + Supported if CMake is built with libarchive 3.6 or higher. + Official CMake binaries available on ``cmake.org`` support it. + + Other compression methods ignore this value and use only one thread. Variables for Source Package Generators ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 9e0d80c..cfde37c 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -95,6 +95,19 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, , Verbose(false) , Format(format) { + // Upstream fixed an issue with their integer parsing in 3.4.0 + // which would cause spurious errors to be raised from `strtoull`. + + if (numThreads < 1) { + int upperLimit = (numThreads == 0) ? std::numeric_limits<int>::max() + : std::abs(numThreads); + + numThreads = + cm::clamp<int>(std::thread::hardware_concurrency(), 1, upperLimit); + } + + std::string sNumThreads = std::to_string(numThreads); + switch (c) { case CompressNone: if (archive_write_add_filter_none(this->Archive) != ARCHIVE_OK) { @@ -150,36 +163,23 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, return; } - { #if ARCHIVE_VERSION_NUMBER >= 3004000 - // Upstream fixed an issue with their integer parsing in 3.4.0 - // which would cause spurious errors to be raised from `strtoull`. - - if (numThreads < 1) { - int upperLimit = (numThreads == 0) ? std::numeric_limits<int>::max() - : std::abs(numThreads); - - numThreads = - cm::clamp<int>(std::thread::hardware_concurrency(), 1, upperLimit); - } # ifdef _AIX - // FIXME: Using more than 2 threads creates an empty archive. - // Enforce this limit pending further investigation. - numThreads = std::min(numThreads, 2); + // FIXME: Using more than 2 threads creates an empty archive. + // Enforce this limit pending further investigation. + if (numThreads > 2) { + numThreads = 2; + sNumThreads = std::to_string(numThreads); + } # endif - - std::string sNumThreads = std::to_string(numThreads); - - if (archive_write_set_filter_option(this->Archive, "xz", "threads", - sNumThreads.c_str()) != - ARCHIVE_OK) { - this->Error = cmStrCat("archive_compressor_xz_options: ", - cm_archive_error_string(this->Archive)); - return; - } -#endif + if (archive_write_set_filter_option(this->Archive, "xz", "threads", + sNumThreads.c_str()) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_compressor_xz_options: ", + cm_archive_error_string(this->Archive)); + return; } +#endif break; case CompressZstd: @@ -188,6 +188,15 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, cm_archive_error_string(this->Archive)); return; } + +#if ARCHIVE_VERSION_NUMBER >= 3006000 + if (archive_write_set_filter_option(this->Archive, "zstd", "threads", + sNumThreads.c_str()) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_compressor_zstd_options: ", + cm_archive_error_string(this->Archive)); + return; + } +#endif break; } |