From c19bafc60c1c2e9a73cb3d212293462a1be4eb47 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 13 Dec 2019 21:19:26 +0100 Subject: [PATCH] QtCore: Use system-wide libb2 if present This adds the option to build Qt with libb2, which is especially recommended, if you care about the performance of the BLAKE2 hashing algorithms. The bundled version is the pure reference C implementation of BLAKE2, while libb2 has many additional hardware optimizations. However, the API of both is the same, so no changes to the code were necessary here. Change-Id: I3563982f4e07be300291fe103c38b16a404b3ebb Reviewed-by: Alexandru Croitor --- cmake/FindLibb2.cmake | 7 +++++ src/corelib/.prev_CMakeLists.txt | 21 +++++++++------ src/corelib/CMakeLists.txt | 27 +++++++++++-------- src/corelib/configure.cmake | 13 +++++++++ src/corelib/configure.json | 20 ++++++++++++++ src/corelib/tools/qcryptographichash.cpp | 4 +++ .../tools/qmessageauthenticationcode.cpp | 6 +++++ src/corelib/tools/tools.pri | 4 +++ util/cmake/helper.py | 1 + util/cmake/pro2cmake.py | 1 + 10 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 cmake/FindLibb2.cmake diff --git a/cmake/FindLibb2.cmake b/cmake/FindLibb2.cmake new file mode 100644 index 0000000000..18b6e4df04 --- /dev/null +++ b/cmake/FindLibb2.cmake @@ -0,0 +1,7 @@ +find_package(PkgConfig QUIET) + +pkg_check_modules(Libb2 libb2 IMPORTED_TARGET) + +if (NOT TARGET PkgConfig::Libb2) + set(Libb2_FOUND 0) +endif() diff --git a/src/corelib/.prev_CMakeLists.txt b/src/corelib/.prev_CMakeLists.txt index 4ae1329db7..e143581087 100644 --- a/src/corelib/.prev_CMakeLists.txt +++ b/src/corelib/.prev_CMakeLists.txt @@ -642,6 +642,11 @@ qt_extend_target(Core CONDITION QT_FEATURE_doubleconversion AND NOT QT_FEATURE_s ../3rdparty/double-conversion/include ) +qt_extend_target(Core CONDITION QT_FEATURE_system_libb2 + LIBRARIES + PkgConfig::Libb2 +) + qt_extend_target(Core CONDITION QT_FEATURE_easingcurve SOURCES tools/qeasingcurve.cpp tools/qeasingcurve.h @@ -1018,7 +1023,7 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype mimetypes/qmimetypeparser.cpp mimetypes/qmimetypeparser_p.h ) -#### Keys ignored in scope 180:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype: +#### Keys ignored in scope 181:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype: # MIME_DATABASE = "mimetypes/mime/packages/freedesktop.org.xml" # OTHER_FILES = "$$MIME_DATABASE" @@ -1027,7 +1032,7 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype AND QT_FEATURE_mimetype_data .rcc ) -#### Keys ignored in scope 181:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype_database: +#### Keys ignored in scope 182:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype_database: # QMAKE_EXTRA_COMPILERS = "mimedb" # mimedb.commands = "${QMAKE_FILE_IN}" ">" "${QMAKE_FILE_OUT}" # mimedb.depends = "$$PWD/mime/generate.pl" @@ -1035,23 +1040,23 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype AND QT_FEATURE_mimetype_data # mimedb.output = "$$outpath/qmimeprovider_database.cpp" # mimedb.variable_out = "INCLUDED_SOURCES" -#### Keys ignored in scope 182:.:mimetypes:mimetypes/mimetypes.pri:ANDROID: +#### Keys ignored in scope 183:.:mimetypes:mimetypes/mimetypes.pri:ANDROID: # outpath = "$$outpath/$${QT_ARCH}" -#### Keys ignored in scope 184:.:mimetypes:mimetypes/mimetypes.pri:(CMAKE_BUILD_TYPE STREQUAL Debug): +#### Keys ignored in scope 185:.:mimetypes:mimetypes/mimetypes.pri:(CMAKE_BUILD_TYPE STREQUAL Debug): # outpath = "$$outpath/debug" -#### Keys ignored in scope 185:.:mimetypes:mimetypes/mimetypes.pri:else: +#### Keys ignored in scope 186:.:mimetypes:mimetypes/mimetypes.pri:else: # outpath = "$$outpath/release" -#### Keys ignored in scope 186:.:mimetypes:mimetypes/mimetypes.pri:MAKEFILE_GENERATOR___equals___MSVC.NET OR MAKEFILE_GENERATOR___equals___MSBUILD OR QMAKE_SH_ISEMPTY: +#### Keys ignored in scope 187:.:mimetypes:mimetypes/mimetypes.pri:MAKEFILE_GENERATOR___equals___MSVC.NET OR MAKEFILE_GENERATOR___equals___MSBUILD OR QMAKE_SH_ISEMPTY: # mimedb.commands = "cmd" "/c" "$$shell_path($$PWD/mime/generate.bat)" # mimedb.depends = "$$PWD/mime/generate.bat" "$$PWD/mime/hexdump.ps1" -#### Keys ignored in scope 187:.:mimetypes:mimetypes/mimetypes.pri:else: +#### Keys ignored in scope 188:.:mimetypes:mimetypes/mimetypes.pri:else: # mimedb.commands = "perl" "$${mimedb.depends}" -#### Keys ignored in scope 188:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_zstd: +#### Keys ignored in scope 189:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_zstd: # mimedb.commands = "--zstd" qt_extend_target(Core CONDITION WASM diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 5d79b00bf9..4a3204e381 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -247,13 +247,13 @@ qt_add_module(Core # ../3rdparty/md5 # special case remove # ../3rdparty/sha3 # special case remove ../3rdparty/tinycbor/src + LIBRARIES + Qt::GlobalConfigPrivate # special case + Threads::Threads # special case PRECOMPILED_HEADER "global/qt_pch.h" NO_PCH_SOURCES "text/qstring_compat.cpp" - LIBRARIES - Qt::GlobalConfigPrivate # special case - Threads::Threads # special case PUBLIC_LIBRARIES # special case: Qt::Platform # special case: # special case begin @@ -747,6 +747,11 @@ qt_extend_target(Core CONDITION QT_FEATURE_doubleconversion AND NOT QT_FEATURE_s ../3rdparty/double-conversion/include ) +qt_extend_target(Core CONDITION QT_FEATURE_system_libb2 + LIBRARIES + PkgConfig::Libb2 +) + qt_extend_target(Core CONDITION QT_FEATURE_easingcurve SOURCES tools/qeasingcurve.cpp tools/qeasingcurve.h @@ -1123,7 +1128,7 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype mimetypes/qmimetypeparser.cpp mimetypes/qmimetypeparser_p.h ) -#### Keys ignored in scope 180:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype: +#### Keys ignored in scope 181:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype: # MIME_DATABASE = "mimetypes/mime/packages/freedesktop.org.xml" # OTHER_FILES = "$$MIME_DATABASE" @@ -1134,7 +1139,7 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype #) # special case end -#### Keys ignored in scope 181:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype_database: +#### Keys ignored in scope 182:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_mimetype_database: # QMAKE_EXTRA_COMPILERS = "mimedb" # mimedb.commands = "${QMAKE_FILE_IN}" ">" "${QMAKE_FILE_OUT}" # mimedb.depends = "$$PWD/mime/generate.pl" @@ -1142,23 +1147,23 @@ qt_extend_target(Core CONDITION QT_FEATURE_mimetype # mimedb.output = "$$outpath/qmimeprovider_database.cpp" # mimedb.variable_out = "INCLUDED_SOURCES" -#### Keys ignored in scope 182:.:mimetypes:mimetypes/mimetypes.pri:ANDROID: +#### Keys ignored in scope 183:.:mimetypes:mimetypes/mimetypes.pri:ANDROID: # outpath = "$$outpath/$${QT_ARCH}" -#### Keys ignored in scope 184:.:mimetypes:mimetypes/mimetypes.pri:(CMAKE_BUILD_TYPE STREQUAL Debug): +#### Keys ignored in scope 185:.:mimetypes:mimetypes/mimetypes.pri:(CMAKE_BUILD_TYPE STREQUAL Debug): # outpath = "$$outpath/debug" -#### Keys ignored in scope 185:.:mimetypes:mimetypes/mimetypes.pri:else: +#### Keys ignored in scope 186:.:mimetypes:mimetypes/mimetypes.pri:else: # outpath = "$$outpath/release" -#### Keys ignored in scope 186:.:mimetypes:mimetypes/mimetypes.pri:MAKEFILE_GENERATOR___equals___MSVC.NET OR MAKEFILE_GENERATOR___equals___MSBUILD OR QMAKE_SH_ISEMPTY: +#### Keys ignored in scope 187:.:mimetypes:mimetypes/mimetypes.pri:MAKEFILE_GENERATOR___equals___MSVC.NET OR MAKEFILE_GENERATOR___equals___MSBUILD OR QMAKE_SH_ISEMPTY: # mimedb.commands = "cmd" "/c" "$$shell_path($$PWD/mime/generate.bat)" # mimedb.depends = "$$PWD/mime/generate.bat" "$$PWD/mime/hexdump.ps1" -#### Keys ignored in scope 187:.:mimetypes:mimetypes/mimetypes.pri:else: +#### Keys ignored in scope 188:.:mimetypes:mimetypes/mimetypes.pri:else: # mimedb.commands = "perl" "$${mimedb.depends}" -#### Keys ignored in scope 188:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_zstd: +#### Keys ignored in scope 189:.:mimetypes:mimetypes/mimetypes.pri:QT_FEATURE_zstd: # mimedb.commands = "--zstd" # Resources: # special case begin diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake index 7f565437cd..21a525bd03 100644 --- a/src/corelib/configure.cmake +++ b/src/corelib/configure.cmake @@ -6,6 +6,10 @@ set(INPUT_doubleconversion "undefined" CACHE STRING "") set_property(CACHE INPUT_doubleconversion PROPERTY STRINGS undefined no qt system) +# input libb2 +set(INPUT_libb2 "undefined" CACHE STRING "") +set_property(CACHE INPUT_libb2 PROPERTY STRINGS undefined no qt system) + #### Libraries @@ -18,6 +22,7 @@ if(QT_FEATURE_dlopen) endif() qt_find_package(Libsystemd PROVIDED_TARGETS PkgConfig::Libsystemd MODULE_NAME core QMAKE_LIB journald) qt_find_package(WrapAtomic PROVIDED_TARGETS WrapAtomic::WrapAtomic MODULE_NAME core QMAKE_LIB libatomic) +qt_find_package(Libb2 PROVIDED_TARGETS PkgConfig::Libb2 MODULE_NAME core QMAKE_LIB libb2) qt_find_package(WrapRt PROVIDED_TARGETS WrapRt::WrapRt MODULE_NAME core QMAKE_LIB librt) qt_find_package(LTTngUST PROVIDED_TARGETS LTTng::UST MODULE_NAME core QMAKE_LIB lttng-ust) qt_add_qmake_lib_dependency(lttng-ust libdl) @@ -607,6 +612,13 @@ qt_feature("journald" PRIVATE AUTODETECT OFF CONDITION Libsystemd_FOUND ) +# Used by QCryptographicHash for the BLAKE2 hashing algorithms +qt_feature("system-libb2" PRIVATE + LABEL "Using system libb2" + CONDITION Libb2_FOUND + ENABLE INPUT_libb2 STREQUAL 'system' + DISABLE INPUT_libb2 STREQUAL 'no' OR INPUT_libb2 STREQUAL 'qt' +) # Currently only used by QTemporaryFile; linkat() exists on Android, but hardlink creation fails due to security rules qt_feature("linkat" PRIVATE LABEL "linkat()" @@ -956,6 +968,7 @@ qt_configure_add_summary_entry(ARGS "doubleconversion") qt_configure_add_summary_entry(ARGS "system-doubleconversion") qt_configure_add_summary_entry(ARGS "glib") qt_configure_add_summary_entry(ARGS "icu") +qt_configure_add_summary_entry(ARGS "system-libb2") qt_configure_add_summary_entry(ARGS "mimetype-database") qt_configure_add_summary_entry( TYPE "firstAvailableFeature" diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 2610392ad1..966bc7684a 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -10,6 +10,7 @@ "icu": "boolean", "inotify": "boolean", "journald": "boolean", + "libb2": { "type": "enum", "values": [ "no", "qt", "system" ] }, "mimetype-database": "boolean", "pcre": { "type": "enum", "values": [ "no", "qt", "system" ] }, "posix-ipc": { "type": "boolean", "name": "ipc_posix" }, @@ -111,6 +112,16 @@ "-latomic" ] }, + "libb2": { + "label": "libb2", + "test": { + "main": "BLAKE2B_BLOCKBYTES;" + }, + "headers": "blake2.h", + "sources": [ + { "type": "pkgConfig", "args": "libb2" } + ] + }, "librt": { "label": "clock_gettime()", "test": { @@ -647,6 +658,14 @@ "condition": "libs.journald", "output": [ "privateFeature" ] }, + "system-libb2": { + "label": "Using system libb2", + "comment": "Used by QCryptographicHash for the BLAKE2 hashing algorithms", + "disable": "input.libb2 == 'no' || input.libb2 == 'qt'", + "enable": "input.libb2 == 'system'", + "condition": "libs.libb2", + "output": [ "privateFeature" ] + }, "linkat": { "label": "linkat()", "comment": "Currently only used by QTemporaryFile; linkat() exists on Android, but hardlink creation fails due to security rules", @@ -1074,6 +1093,7 @@ Note that this is required for plugin loading. Qt GUI needs QPA plugins for basi "system-doubleconversion", "glib", "icu", + "system-libb2", "mimetype-database", { "message": "Tracing backend", diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 9f98475dc0..d5a6c4e5a0 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -165,8 +165,12 @@ static inline int SHA384_512AddLength(SHA512Context *context, unsigned int lengt return SHA384_512AddLengthM(context, length); } +#if QT_CONFIG(system_libb2) +#include +#else #include "../../3rdparty/blake2/src/blake2b-ref.c" #include "../../3rdparty/blake2/src/blake2s-ref.c" +#endif #endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1 QT_BEGIN_NAMESPACE diff --git a/src/corelib/tools/qmessageauthenticationcode.cpp b/src/corelib/tools/qmessageauthenticationcode.cpp index d84b1b0b6c..ada502ecb8 100644 --- a/src/corelib/tools/qmessageauthenticationcode.cpp +++ b/src/corelib/tools/qmessageauthenticationcode.cpp @@ -40,6 +40,8 @@ #include "qmessageauthenticationcode.h" #include "qvarlengtharray.h" +#include "qtcore-config_p.h" + /* These #defines replace the typedefs needed by the RFC6234 code. Normally the typedefs would come from from stdint.h, but since this header is not @@ -75,7 +77,11 @@ // sha1.h - commented out '#include ' on line 74 #include "../../3rdparty/rfc6234/sha.h" +#if QT_CONFIG(system_libb2) +#include +#else #include "../../3rdparty/blake2/src/blake2.h" +#endif #undef uint64_t #undef uint32_t diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 4d3b5e25ff..c8ce79ce36 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -99,6 +99,10 @@ qtConfig(system-doubleconversion) { include($$PWD/../../3rdparty/double-conversion/double-conversion.pri) } +qtConfig(system-libb2) { + QMAKE_USE_PRIVATE += libb2 +} + qtConfig(easingcurve) { HEADERS += \ tools/qeasingcurve.h \ diff --git a/util/cmake/helper.py b/util/cmake/helper.py index 02a241b018..c2aa49168c 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -412,6 +412,7 @@ _library_map = [ LibraryMapping("journald", "Libsystemd", "PkgConfig::Libsystemd"), LibraryMapping("jpeg", "JPEG", "JPEG::JPEG"), # see also libjpeg LibraryMapping("libatomic", "WrapAtomic", "WrapAtomic::WrapAtomic"), + LibraryMapping("libb2", "Libb2", "PkgConfig::Libb2"), LibraryMapping("libclang", "WrapLibClang", "WrapLibClang::WrapLibClang"), LibraryMapping("libdl", None, "${CMAKE_DL_LIBS}"), LibraryMapping("libinput", "Libinput", "Libinput::Libinput"), diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index defadee3f3..a01795a833 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1645,6 +1645,7 @@ def map_condition(condition: str) -> str: and not feature_name.startswith("system_doubleconversion") and not feature_name.startswith("system_sqlite") and not feature_name.startswith("system_hunspell") + and not feature_name.startswith("system_libb2") ): part = "ON" elif feature == "dlopen":