Skip to content

Commit

Permalink
Install 3rdparty headers for static builds
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Alexey Edelev <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
  • Loading branch information
Michal Klocek committed Feb 19, 2022
1 parent 6944b4d commit be2745e
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 115 deletions.
11 changes: 11 additions & 0 deletions cmake/FindWrapJpeg.cmake
Original file line number Diff line number Diff line change
@@ -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"
)
32 changes: 32 additions & 0 deletions cmake/FindWrapSystemJpeg.cmake
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions cmake/Qt3rdPartyLibraryHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 26 additions & 1 deletion cmake/QtModuleHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ 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}
QMAKE_MODULE_CONFIG
EXTRA_CMAKE_FILES
EXTRA_CMAKE_INCLUDES
NO_PCH_SOURCES
EXTERNAL_HEADERS
${__default_private_args}
${__default_public_args}
${__default_private_module_args}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions libexec/syncqt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,9 @@ ($$)
# 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)
Expand All @@ -1112,7 +1114,13 @@ ($$)
#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:
Expand Down
5 changes: 5 additions & 0 deletions src/3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 5 additions & 8 deletions src/3rdparty/freetype/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ qt_internal_add_3rdparty_library(BundledFreetype
PUBLIC_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_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"
qt_internal_add_3rdparty_header_module(FreetypePrivate
EXTERNAL_HEADERS_DIR include
)

## Scopes:
#####################################################################
qt_disable_warnings(BundledFreetype)
qt_set_symbol_visibility_hidden(BundledFreetype)

qt_internal_extend_target(BundledFreetype CONDITION WIN32
SOURCES
Expand Down
4 changes: 4 additions & 0 deletions src/3rdparty/harfbuzz-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 80 additions & 0 deletions src/3rdparty/libjpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

14 changes: 7 additions & 7 deletions src/3rdparty/libpng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ qt_internal_add_3rdparty_library(BundledLibpng
PUBLIC_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
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/*"
qt_internal_add_3rdparty_header_module(PngPrivate
EXTERNAL_HEADERS
png.h
pngconf.h
)

## Scopes:
#####################################################################
qt_disable_warnings(BundledLibpng)
qt_set_symbol_visibility_hidden(BundledLibpng)

qt_internal_extend_target(BundledLibpng CONDITION QT_FEATURE_system_zlib
LIBRARIES
Expand Down
14 changes: 4 additions & 10 deletions src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/gui/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit be2745e

Please sign in to comment.