Install 3rdparty headers for static builds

For static builds we need 3rdparty headers to be installed.
Leaf modules like qtwebengine needs 3rdparty libs and header for
zlib, freetype, harfbuzz, png, jpeg. Without those the Chromium bundled
versions are used, however it might end up badly if qt has already
bundled one.

Introduce new header only modules with additional arguments for
qt_internal_add_module:

 * EXTERNAL_HEADERS to pick exactly which headers are public
 * EXTERNAL_HEADERS_DIR to include whole directory preserving the
   files directory structure

Fix qtsync so it keep directory structure for all non-qt modules when
syncing headers and do not generate warnings for headers files.

Task-number: QTBUG-87154
Task-number: QTBUG-88614
Change-Id: If1c27bf8608791cd4e0a21839d6316a445a96e9f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Michal Klocek 2021-12-14 09:54:33 +01:00
parent 6944b4df7b
commit be2745e478
14 changed files with 221 additions and 115 deletions

11
cmake/FindWrapJpeg.cmake Normal file
View File

@ -0,0 +1,11 @@
include(QtFindWrapHelper NO_POLICY_SCOPE)
qt_find_package_system_or_bundled(wrap_jpeg
FRIENDLY_PACKAGE_NAME "Jpeg"
WRAP_PACKAGE_TARGET "WrapJpeg::WrapJpeg"
WRAP_PACKAGE_FOUND_VAR_NAME "WrapJpeg_FOUND"
BUNDLED_PACKAGE_NAME "BundledLibjpeg"
BUNDLED_PACKAGE_TARGET "BundledLibjpeg"
SYSTEM_PACKAGE_NAME "WrapSystemJpeg"
SYSTEM_PACKAGE_TARGET "WrapSystemJpeg::WrapSystemJpeg"
)

View File

@ -0,0 +1,32 @@
if(TARGET WrapSystemJpeg::WrapSystemJpeg)
set(WrapSystemJpeg_FOUND TRUE)
return()
endif()
set(WrapSystemJpeg_REQUIRED_VARS __jpeg_found)
find_package(JPEG ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET)
set(__jpeg_target_name "JPEG::JPEG")
if(JPEG_FOUND AND TARGET "${__jpeg_target_name}")
set(__jpeg_found TRUE)
endif()
if(JPEG_LIBRARIES)
list(PREPEND WrapSystemJpeg_REQUIRED_VARS JPEG_LIBRARIES)
endif()
if(JPEG_VERSION)
set(WrapSystemJpeg_VERSION "${JPEG_VERSION}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(WrapSystemJpeg
REQUIRED_VARS ${WrapSystemJpeg_REQUIRED_VARS}
VERSION_VAR WrapSystemJpeg_VERSION)
if(WrapSystemJpeg_FOUND)
add_library(WrapSystemJpeg::WrapSystemJpeg INTERFACE IMPORTED)
target_link_libraries(WrapSystemJpeg::WrapSystemJpeg
INTERFACE "${__jpeg_target_name}")
endif()
unset(__jpeg_target_name)
unset(__jpeg_found)

View File

@ -312,3 +312,27 @@ function(qt_install_3rdparty_library_wrap_config_extra_file target)
COMPONENT Devel
)
endfunction()
# This function implements qmake's qt_helper_lib MODULE_EXT_HEADERS and MODULE_EXT_HEADERS_DIR features.
# It creates a header-only module exposing a subset or all headers of a 3rd-party library.
function(qt_internal_add_3rdparty_header_module target)
set(single_args
EXTERNAL_HEADERS_DIR
)
set(multi_args
EXTERNAL_HEADERS
)
qt_parse_all_arguments(arg "qt_internal_add_header_module"
"${option_args}"
"${single_args}"
"${multi_args}"
${ARGN}
)
qt_internal_add_module(${target}
INTERNAL_MODULE
HEADER_MODULE
NO_CONFIG_HEADER_FILE
EXTERNAL_HEADERS ${arg_EXTERNAL_HEADERS}
EXTERNAL_HEADERS_DIR ${arg_EXTERNAL_HEADERS_DIR}
)
endfunction()

View File

@ -23,6 +23,7 @@ macro(qt_internal_get_internal_add_module_keywords option_args single_args multi
PRECOMPILED_HEADER
CONFIGURE_FILE_PATH
CPP_EXPORT_HEADER_BASE_NAME
EXTERNAL_HEADERS_DIR
${__default_target_info_args}
)
set(${multi_args}
@ -30,6 +31,7 @@ macro(qt_internal_get_internal_add_module_keywords option_args single_args multi
EXTRA_CMAKE_FILES
EXTRA_CMAKE_INCLUDES
NO_PCH_SOURCES
EXTERNAL_HEADERS
${__default_private_args}
${__default_public_args}
${__default_private_module_args}
@ -69,6 +71,16 @@ endmacro()
# Creates a static library instead of following the Qt configuration default. Mutually
# exclusive with HEADER_MODULE.
#
# EXTERNAL_HEADERS
# A explicit list of non qt headers (like 3rdparty) to be installed.
# Note this option overrides install headers used as PUBLIC_HEADER by cmake install(TARGET)
# otherwise set by syncqt.
#
# EXTERNAL_HEADERS_DIR
# A module directory with non qt headers (like 3rdparty) to be installed.
# Note this option overrides install headers used as PUBLIC_HEADER by cmake install(TARGET)
# otherwise set by syncqt.
function(qt_internal_add_module target)
qt_internal_get_internal_add_module_keywords(
module_option_args
@ -317,6 +329,10 @@ function(qt_internal_add_module target)
### FIXME: Can we replace headers.pri?
qt_read_headers_pri("${module_build_interface_include_dir}" "module_headers")
if(arg_EXTERNAL_HEADERS)
set(module_headers_public ${arg_EXTERNAL_HEADERS})
endif()
set_property(TARGET ${target} APPEND PROPERTY
_qt_module_timestamp_dependencies "${module_headers_public}")
@ -680,14 +696,23 @@ set(QT_LIBINFIX \"${QT_LIBINFIX}\")")
list(APPEND exported_targets ${target_private})
endif()
set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}Targets")
if(arg_EXTERNAL_HEADERS_DIR)
qt_install(DIRECTORY "${arg_EXTERNAL_HEADERS_DIR}/"
DESTINATION "${module_install_interface_include_dir}"
)
unset(public_header_destination)
else()
set(public_header_destination PUBLIC_HEADER DESTINATION "${module_install_interface_include_dir}")
endif()
qt_install(TARGETS ${exported_targets}
EXPORT ${export_name}
RUNTIME DESTINATION ${INSTALL_BINDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${module_install_interface_include_dir}"
PRIVATE_HEADER DESTINATION "${module_install_interface_private_include_dir}"
${public_header_destination}
)
if(BUILD_SHARED_LIBS)

View File

@ -1095,7 +1095,9 @@ foreach my $lib (@modules_to_sync) {
# We need both $public_header and $private_header because QPA headers count as neither
my $private_header = !$public_header && !$qpa_header
&& $header =~ /_p\.h$/ && $subdir !~ /3rdparty/;
check_header($lib, $header, $iheader, $public_header, $private_header);
if ($is_qt) { # skip check since this header is not qt header
check_header($lib, $header, $iheader, $public_header, $private_header);
}
}
my @classes = ();
push @classes, classNames($iheader, \$clean_header, \$requires)
@ -1112,7 +1114,13 @@ foreach my $lib (@modules_to_sync) {
#find out all the places it goes..
my $oheader;
if ($public_header) {
$oheader = "$out_basedir/include/$lib/$header";
if ($is_qt || $headers_dir eq $subdir) { # this is qt header or header is not in subdirectory
$oheader = "$out_basedir/include/$lib/$header";
} else {
my $subdirname = $subdir;
$subdirname =~ s/^$headers_dir//;
$oheader = "$out_basedir/include/$lib/$subdirname/$header"; # keep subdirectory name
}
foreach my $full_class (@classes) {
my $header_base = basename($header);
# Strip namespaces:

View File

@ -6,6 +6,11 @@ if(QT_FEATURE_gui AND QT_FEATURE_png AND NOT QT_FEATURE_system_png)
endif()
qt_install_3rdparty_library_wrap_config_extra_file(BundledLibpng)
if(QT_FEATURE_gui AND QT_FEATURE_jpeg AND NOT QT_FEATURE_system_jpeg)
add_subdirectory(libjpeg)
endif()
qt_install_3rdparty_library_wrap_config_extra_file(BundledLibjpeg)
if(QT_FEATURE_gui AND QT_FEATURE_freetype AND NOT QT_FEATURE_system_freetype)
add_subdirectory(freetype)
endif()

View File

@ -46,17 +46,14 @@ qt_internal_add_3rdparty_library(BundledFreetype
PUBLIC_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
qt_internal_add_3rdparty_header_module(FreetypePrivate
EXTERNAL_HEADERS_DIR include
)
qt_disable_warnings(BundledFreetype)
qt_set_symbol_visibility_hidden(BundledFreetype)
#### Keys ignored in scope 1:.:.:freetype.pro:<TRUE>:
# MODULE_EXT_HEADERS_DIR = "$$PWD/include"
# OTHER_FILES = "$$PWD/src/autofit/afangles.c" "$$PWD/src/autofit/afglobal.c" "$$PWD/src/autofit/afloader.c" "$$PWD/src/autofit/afmodule.c"
# QT_FOR_CONFIG = "gui-private"
## Scopes:
#####################################################################
qt_internal_extend_target(BundledFreetype CONDITION WIN32
SOURCES
src/base/ftsystem.c

View File

@ -170,3 +170,7 @@ qt_internal_extend_target(BundledHarfbuzz CONDITION SHAPERS_ISEMPTY OR SHAPERS__
DEFINES
HAVE_FALLBACK
)
qt_internal_add_3rdparty_header_module(HarfbuzzPrivate
EXTERNAL_HEADERS_DIR include
)

80
src/3rdparty/libjpeg/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,80 @@
qt_internal_add_3rdparty_library(BundledLibjpeg
QMAKE_LIB_NAME libjpeg
STATIC
INSTALL
SOURCES
src/jaricom.c
src/jcapimin.c
src/jcapistd.c
src/jcarith.c
src/jccoefct.c
src/jccolor.c
src/jcdctmgr.c
src/jchuff.c
src/jcinit.c
src/jcmainct.c
src/jcmarker.c
src/jcmaster.c
src/jcomapi.c
src/jcparam.c
src/jcphuff.c
src/jcprepct.c
src/jcsample.c
src/jctrans.c
src/jdapimin.c
src/jdapistd.c
src/jdarith.c
src/jdatadst.c
src/jdatasrc.c
src/jdcoefct.c
src/jdcolor.c
src/jddctmgr.c
src/jdhuff.c
src/jdinput.c
src/jdmainct.c
src/jdmarker.c
src/jdmaster.c
src/jdmerge.c
src/jdphuff.c
src/jdpostct.c
src/jdsample.c
src/jdtrans.c
src/jerror.c
src/jfdctflt.c
src/jfdctfst.c
src/jfdctint.c
src/jidctflt.c
src/jidctfst.c
src/jidctint.c
src/jidctred.c
src/jmemmgr.c
src/jmemnobs.c
src/jquant1.c
src/jquant2.c
src/jsimd_none.c
src/jutils.c
INCLUDE_DIRECTORIES
src
PUBLIC_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
qt_internal_add_3rdparty_header_module(JpegPrivate
EXTERNAL_HEADERS
src/jpeglib.h
src/jerror.h
)
qt_disable_warnings(BundledLibjpeg)
qt_set_symbol_visibility_hidden(BundledLibjpeg)
qt_internal_extend_target(BundledLibjpeg CONDITION MSVC
DEFINES
_CRT_SECURE_NO_WARNINGS
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(BundledLibjpeg PRIVATE "-Wno-unused-parameter")
endif()

View File

@ -30,16 +30,16 @@ qt_internal_add_3rdparty_library(BundledLibpng
PUBLIC_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
qt_internal_add_3rdparty_header_module(PngPrivate
EXTERNAL_HEADERS
png.h
pngconf.h
)
qt_disable_warnings(BundledLibpng)
qt_set_symbol_visibility_hidden(BundledLibpng)
#### Keys ignored in scope 1:.:.:libpng.pro:<TRUE>:
# MODULE_EXT_HEADERS = "png.h" "pngconf.h"
# TR_EXCLUDE = "$$PWD/*"
## Scopes:
#####################################################################
qt_internal_extend_target(BundledLibpng CONDITION QT_FEATURE_system_zlib
LIBRARIES
WrapZLIB::WrapZLIB

View File

@ -1326,16 +1326,10 @@ qt_internal_add_docs(Core
doc/qtcore.qdocconf
)
# special case begin
# Handle qtzlib.pro to create headers for the
# QtZlibPrivate target, equivalent to Qt += zlib-private
if(NOT QT_FEATURE_system_zlib)
qt_internal_add_module(ZlibPrivate
INTERNAL_MODULE
HEADER_MODULE
NO_CONFIG_HEADER_FILE
)
endif()
qt_internal_add_3rdparty_header_module(ZlibPrivate
EXTERNAL_HEADERS
../3rdparty/zlib/src/zlib.h
)
qt_internal_add_optimize_full_flags()

View File

@ -40,7 +40,7 @@ qt_add_qmake_lib_dependency(fontconfig freetype)
qt_find_package(gbm PROVIDED_TARGETS gbm::gbm MODULE_NAME gui QMAKE_LIB gbm)
qt_find_package(WrapSystemHarfbuzz 2.6.0 PROVIDED_TARGETS WrapSystemHarfbuzz::WrapSystemHarfbuzz MODULE_NAME gui QMAKE_LIB harfbuzz)
qt_find_package(Libinput PROVIDED_TARGETS Libinput::Libinput MODULE_NAME gui QMAKE_LIB libinput)
qt_find_package(JPEG PROVIDED_TARGETS JPEG::JPEG MODULE_NAME gui QMAKE_LIB libjpeg)
qt_find_package(WrapSystemJpeg PROVIDED_TARGETS WrapSystemJpeg::WrapSystemJpeg MODULE_NAME gui QMAKE_LIB libjpeg)
qt_find_package(WrapSystemMd4c PROVIDED_TARGETS WrapSystemMd4c::WrapSystemMd4c MODULE_NAME gui QMAKE_LIB libmd4c)
qt_find_package(WrapSystemPNG PROVIDED_TARGETS WrapSystemPNG::WrapSystemPNG MODULE_NAME gui QMAKE_LIB libpng)
if(QT_FEATURE_system_zlib)

View File

@ -1,6 +1,6 @@
# Generated from jpeg.pro.
qt_find_package(JPEG) # special case
qt_find_package(WrapJpeg PROVIDED_TARGETS WrapJpeg::WrapJpeg)
#####################################################################
## QJpegPlugin Plugin:
@ -17,6 +17,7 @@ qt_internal_add_plugin(QJpegPlugin
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
WrapJpeg::WrapJpeg
)
# Fails to build on Windows with a static Qt, PCH enabled and
@ -25,86 +26,3 @@ qt_internal_add_plugin(QJpegPlugin
if(WIN32 AND NOT BUILD_SHARED_LIBS)
qt_update_ignore_pch_source(QJpegPlugin "qjpeghandler.cpp")
endif()
#### Keys ignored in scope 1:.:.:jpeg.pro:<TRUE>:
# OTHER_FILES = "jpeg.json"
## Scopes:
#####################################################################
qt_internal_extend_target(QJpegPlugin CONDITION QT_FEATURE_system_jpeg
LIBRARIES
JPEG::JPEG
)
qt_internal_extend_target(QJpegPlugin CONDITION NOT QT_FEATURE_system_jpeg
SOURCES
../../../3rdparty/libjpeg/src/jaricom.c
../../../3rdparty/libjpeg/src/jcapimin.c
../../../3rdparty/libjpeg/src/jcapistd.c
../../../3rdparty/libjpeg/src/jcarith.c
../../../3rdparty/libjpeg/src/jccoefct.c
../../../3rdparty/libjpeg/src/jccolor.c
../../../3rdparty/libjpeg/src/jcdctmgr.c
../../../3rdparty/libjpeg/src/jchuff.c
../../../3rdparty/libjpeg/src/jcinit.c
../../../3rdparty/libjpeg/src/jcmainct.c
../../../3rdparty/libjpeg/src/jcmarker.c
../../../3rdparty/libjpeg/src/jcmaster.c
../../../3rdparty/libjpeg/src/jcomapi.c
../../../3rdparty/libjpeg/src/jcparam.c
../../../3rdparty/libjpeg/src/jcphuff.c
../../../3rdparty/libjpeg/src/jcprepct.c
../../../3rdparty/libjpeg/src/jcsample.c
../../../3rdparty/libjpeg/src/jctrans.c
../../../3rdparty/libjpeg/src/jdapimin.c
../../../3rdparty/libjpeg/src/jdapistd.c
../../../3rdparty/libjpeg/src/jdarith.c
../../../3rdparty/libjpeg/src/jdatadst.c
../../../3rdparty/libjpeg/src/jdatasrc.c
../../../3rdparty/libjpeg/src/jdcoefct.c
../../../3rdparty/libjpeg/src/jdcolor.c
../../../3rdparty/libjpeg/src/jddctmgr.c
../../../3rdparty/libjpeg/src/jdhuff.c
../../../3rdparty/libjpeg/src/jdinput.c
../../../3rdparty/libjpeg/src/jdmainct.c
../../../3rdparty/libjpeg/src/jdmarker.c
../../../3rdparty/libjpeg/src/jdmaster.c
../../../3rdparty/libjpeg/src/jdmerge.c
../../../3rdparty/libjpeg/src/jdphuff.c
../../../3rdparty/libjpeg/src/jdpostct.c
../../../3rdparty/libjpeg/src/jdsample.c
../../../3rdparty/libjpeg/src/jdtrans.c
../../../3rdparty/libjpeg/src/jerror.c
../../../3rdparty/libjpeg/src/jfdctflt.c
../../../3rdparty/libjpeg/src/jfdctfst.c
../../../3rdparty/libjpeg/src/jfdctint.c
../../../3rdparty/libjpeg/src/jidctflt.c
../../../3rdparty/libjpeg/src/jidctfst.c
../../../3rdparty/libjpeg/src/jidctint.c
../../../3rdparty/libjpeg/src/jidctred.c
../../../3rdparty/libjpeg/src/jmemmgr.c
../../../3rdparty/libjpeg/src/jmemnobs.c
../../../3rdparty/libjpeg/src/jquant1.c
../../../3rdparty/libjpeg/src/jquant2.c
../../../3rdparty/libjpeg/src/jsimd_none.c
../../../3rdparty/libjpeg/src/jutils.c
INCLUDE_DIRECTORIES
../../../3rdparty/libjpeg/src
)
# special case begin
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(QJpegPlugin PRIVATE "-Wno-unused-parameter")
endif()
# special case end
#### Keys ignored in scope 5:.:../../../3rdparty:../../../3rdparty/libjpeg.pri:GCC:
# QMAKE_CFLAGS_WARN_ON = "-Wno-unused-parameter" "-Wno-main"
qt_internal_extend_target(QJpegPlugin CONDITION MSVC AND NOT QT_FEATURE_system_jpeg
DEFINES
_CRT_SECURE_NO_WARNINGS
)

View File

@ -1,4 +1,8 @@
%modules = ( # path to module name map
%modules = (
# path to module name map
# "module_name" => "path to look for headers"
# ! - for non qt module
# > - points to directory where module was defined in cmake file
"QtGui" => "$basedir/src/gui",
"QtWidgets" => "$basedir/src/widgets",
"QtPrintSupport" => "$basedir/src/printsupport",
@ -15,7 +19,11 @@
"QtInputSupport" => "$basedir/src/platformsupport/input",
"QtFbSupport" => "$basedir/src/platformsupport/fbconvenience",
"QtKmsSupport" => "$basedir/src/platformsupport/kmsconvenience",
"QtZlib" => "!>$basedir/src/corelib;$basedir/src/3rdparty/zlib",
"QtZlib" => "!>$basedir/src/corelib;$basedir/src/3rdparty/zlib/src",
"QtPng" => "!>$basedir/src/3rdparty/libpng;$basedir/src/3rdparty/libpng",
"QtJpeg" => "!>$basedir/src/3rdparty/libjpeg;$basedir/src/3rdparty/libjpeg/src",
"QtHarfbuzz" => "!>$basedir/src/3rdparty/harfbuzz-ng;$basedir/src/3rdparty/harfbuzz-ng/include",
"QtFreetype" => "!>$basedir/src/3rdparty/freetype;$basedir/src/3rdparty/freetype/include",
"QtEglFSDeviceIntegration" => "$basedir/src/plugins/platforms/eglfs",
"QtEglFsKmsSupport" => "$basedir/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support",
"QtEglFsKmsGbmSupport" => "$basedir/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms",