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 <alexandru.croitor@qt.io>
This commit is contained in:
Linus Jahn 2019-12-13 21:19:26 +01:00
parent 5d69aa3ee1
commit c19bafc60c
10 changed files with 85 additions and 19 deletions

7
cmake/FindLibb2.cmake Normal file
View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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",

View File

@ -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 <blake2.h>
#else
#include "../../3rdparty/blake2/src/blake2b-ref.c"
#include "../../3rdparty/blake2/src/blake2s-ref.c"
#endif
#endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1
QT_BEGIN_NAMESPACE

View File

@ -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 <stdint.h>' on line 74
#include "../../3rdparty/rfc6234/sha.h"
#if QT_CONFIG(system_libb2)
#include <blake2.h>
#else
#include "../../3rdparty/blake2/src/blake2.h"
#endif
#undef uint64_t
#undef uint32_t

View File

@ -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 \

View File

@ -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"),

View File

@ -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":