From 759da6742a513fa3fb85bb6db569cff5a53a47d6 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 22 Apr 2020 21:01:32 +0200 Subject: [PATCH] CMake: Generate information about 3rdparty libs in module .pri files For modules that are not yet ported to CMake and that use QMAKE_USE += libfoo we need to provide the information about libfoo in the qt_lib_XXX.pri files. Also, we now generate qt_ext_XXX.pri files for bundled 3rdparty libs. Task-number: QTBUG-75666 Change-Id: I9e4b057a197554ecb37c294c0bf09e2a2b3aa053 Reviewed-by: Alexandru Croitor --- cmake/QtBaseGlobalTargets.cmake | 1 + cmake/QtBuild.cmake | 153 ++++++++++++++++- cmake/QtGenerateExtPri.cmake | 47 ++++++ configure.cmake | 8 +- src/3rdparty/freetype/CMakeLists.txt | 1 + src/3rdparty/harfbuzz-ng/.prev_CMakeLists.txt | 1 + src/3rdparty/harfbuzz-ng/CMakeLists.txt | 1 + src/3rdparty/libpng/CMakeLists.txt | 1 + src/3rdparty/pcre2/CMakeLists.txt | 1 + src/corelib/configure.cmake | 26 +-- src/gui/configure.cmake | 159 ++++++++++-------- src/network/configure.cmake | 8 +- src/plugins/sqldrivers/configure.cmake | 15 +- src/printsupport/configure.cmake | 2 +- src/widgets/configure.cmake | 2 +- util/cmake/configurejson2cmake.py | 20 +++ util/cmake/helper.py | 9 +- util/cmake/pro2cmake.py | 3 +- 18 files changed, 357 insertions(+), 101 deletions(-) create mode 100644 cmake/QtGenerateExtPri.cmake diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index ea765847eb..366b23c6c1 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -321,6 +321,7 @@ qt_copy_or_install(FILES cmake/QtFindWrapHelper.cmake cmake/QtFindWrapConfigExtra.cmake.in cmake/QtFileConfigure.txt.in + cmake/QtGenerateExtPri.cmake cmake/QtPlatformSupport.cmake cmake/QtPlatformAndroid.cmake cmake/QtPostProcess.cmake diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 7b4ca49f97..f8f7169f97 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -604,6 +604,88 @@ function(qt_is_imported_target target out_var) set(${out_var} "${is_imported}" PARENT_SCOPE) endfunction() +# Creates a regular expression that exactly matches the given string +# Found in https://gitlab.kitware.com/cmake/cmake/issues/18580 +function(qt_re_escape out_var str) + string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" regex "${str}") + set(${out_var} ${regex} PARENT_SCOPE) +endfunction() + +# Extracts the 3rdparty libraries for the module ${module_name} in module .pri file format +# and stores the content in ${out_var}. +# +# This function "follows" INTERFACE_LIBRARY targets to "real" targets +# and collects defines, include dirs and lib dirs on the way. +function(qt_get_qmake_libraries_pri_content out_var module_name) + set(content "") + + # Set up a regular expression that matches all implicit include dirs + set(implicit_include_dirs_regex "") + foreach(dir ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + qt_re_escape(regex "${dir}") + list(APPEND implicit_include_dirs_regex ${regex}) + endforeach() + list(JOIN implicit_include_dirs_regex "|" implicit_include_dirs_regex) + + foreach(lib ${QT_QMAKE_LIBS_FOR_${module_name}}) + set(lib_targets ${QT_QMAKE_LIB_TARGETS_${lib}}) + string(TOUPPER ${lib} uclib) + set(lib_defines "") + set(lib_incdir "") + set(lib_libdir "") + set(lib_libs "") + while(lib_targets) + list(POP_BACK lib_targets lib_target) + if(TARGET ${lib_target}) + get_target_property(lib_target_type ${lib_target} TYPE) + if(lib_target_type STREQUAL "INTERFACE_LIBRARY") + get_target_property(iface_libs ${lib_target} INTERFACE_LINK_LIBRARIES) + if(iface_libs) + list(PREPEND lib_targets ${iface_libs}) + endif() + else() + list(APPEND lib_libs "$") + endif() + list(APPEND lib_libdir "$") + list(APPEND lib_incdir "$") + list(APPEND lib_defines "$") + else() + list(APPEND lib_libs "${lib_target}") + endif() + endwhile() + + # Wrap in $ but not the libs, because + # we would have to preserve the right order for the linker. + foreach(sfx libdir incdir defines) + string(PREPEND lib_${sfx} "$") + endforeach() + + # Filter out implicit include directories + string(PREPEND lib_incdir "$") + + # Wrap in $ to create qmake-style lists. + foreach(sfx libs libdir incdir defines) + string(PREPEND lib_${sfx} "$") + endforeach() + + string(APPEND content "QMAKE_LIBS_${uclib} = ${lib_libs} +QMAKE_LIBDIR_${uclib} = ${lib_libdir} +QMAKE_INCDIR_${uclib} = ${lib_incdir} +QMAKE_DEFINES_${uclib} = ${lib_defines} +") + if(QT_QMAKE_LIB_DEPS_${lib}) + list(JOIN QT_QMAKE_LIB_DEPS_${lib} " " deps) + string(APPEND content "QMAKE_DEPENDS_${uclib}_CC = ${deps} +QMAKE_DEPENDS_${uclib}_LD = ${deps} +") + endif() + endforeach() + set(${out_var} "${content}" PARENT_SCOPE) +endfunction() + # Generates module .pri files for consumption by qmake function(qt_generate_module_pri_file target target_path config_module_name pri_files_var) set(flags INTERNAL_MODULE HEADER_MODULE) @@ -703,6 +785,8 @@ QT_MODULES += ${config_module_name} qt_path_join(private_pri_file "${target_path}" "qt_lib_${config_module_name}_private.pri") list(APPEND pri_files "${private_pri_file}") + qt_get_qmake_libraries_pri_content(libraries_content ${config_module_name}) + file(GENERATE OUTPUT "${private_pri_file}" CONTENT @@ -717,12 +801,54 @@ QT.${config_module_name}_private.uses = QT.${config_module_name}_private.module_config = ${joined_module_internal_config} QT.${config_module_name}_private.enabled_features = ${enabled_private_features} QT.${config_module_name}_private.disabled_features = ${disabled_private_features} -" +${libraries_content}" ) set("${pri_files_var}" "${pri_files}" PARENT_SCOPE) endfunction() +# Generates qt_ext_XXX.pri files for consumption by qmake +function(qt_generate_3rdparty_lib_pri_file target lib pri_file_var) + if(NOT lib) + # Don't write a pri file for projects that don't set QMAKE_LIB_NAME yet. + return() + endif() + + if(QT_GENERATOR_IS_MULTI_CONFIG) + set(configs ${CMAKE_CONFIGURATION_TYPES}) + else() + set(configs ${CMAKE_BUILD_TYPE}) + endif() + + file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$/qt_ext_${lib}.cmake" + CONTENT "set(cfg $) +set(incdir $) +set(defines $) +set(libs $) +") + + set(inputs "") + foreach(cfg ${configs}) + list(APPEND inputs "${CMAKE_CURRENT_BINARY_DIR}/${cfg}/qt_ext_${lib}.cmake") + endforeach() + + qt_path_join(pri_target_path ${QT_BUILD_DIR} ${INSTALL_MKSPECSDIR}/modules) + qt_path_join(pri_file "${pri_target_path}" "qt_ext_${lib}.pri") + qt_path_join(qt_build_libdir ${QT_BUILD_DIR} ${INSTALL_LIBDIR}) + add_custom_command( + OUTPUT "${pri_file}" + DEPENDS ${inputs} + COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${pri_file}" -DLIB=${lib} + "-DCONFIGS=${configs}" + "-DQT_BUILD_LIBDIR=${qt_build_libdir}" + -P "${QT_CMAKE_DIR}/QtGenerateExtPri.cmake" + VERBATIM) + add_custom_target(${target}_ext_pri DEPENDS "${pri_file}") + add_dependencies(${target} ${target}_ext_pri) + set(${pri_file_var} ${pri_file} PARENT_SCOPE) +endfunction() + function(qt_cmake_build_type_to_qmake_build_config out_var build_type) if(build_type STREQUAL "Debug") set(cfg debug) @@ -893,6 +1019,9 @@ CONFIG += ${private_config_joined} string(REPLACE ";" " " build_parts "${build_parts}") string(APPEND content "QT_BUILD_PARTS = ${build_parts}\n") + qt_get_qmake_libraries_pri_content(libraries_content global) + string(APPEND content "${libraries_content}") + file(GENERATE OUTPUT "${qmodule_pri_target_path}" CONTENT "${content}" @@ -3661,7 +3790,7 @@ function(qt_add_3rdparty_library target) # Process arguments: qt_parse_all_arguments(arg "qt_add_3rdparty_library" "SHARED;MODULE;STATIC;INTERFACE;EXCEPTIONS;INSTALL;SKIP_AUTOMOC" - "OUTPUT_DIRECTORY" + "OUTPUT_DIRECTORY;QMAKE_LIB_NAME" "${__default_private_args};${__default_public_args}" ${ARGN} ) @@ -3738,6 +3867,11 @@ function(qt_add_3rdparty_library target) qt_internal_set_no_exceptions_flags("${target}") endif() + qt_generate_3rdparty_lib_pri_file("${target}" "${arg_QMAKE_LIB_NAME}" pri_file) + if(pri_file) + qt_install(FILES "${pri_file}" DESTINATION "${INSTALL_MKSPECSDIR}/modules") + endif() + qt_extend_target("${target}" SOURCES ${arg_SOURCES} INCLUDE_DIRECTORIES @@ -4398,7 +4532,7 @@ endfunction() macro(qt_find_package) # Get the target names we expect to be provided by the package. set(options CONFIG NO_MODULE MODULE REQUIRED) - set(oneValueArgs) + set(oneValueArgs MODULE_NAME QMAKE_LIB) set(multiValueArgs PROVIDED_TARGETS COMPONENTS) cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -4519,9 +4653,22 @@ macro(qt_find_package) endif() endforeach() + + if(arg_MODULE_NAME AND arg_QMAKE_LIB + AND (NOT arg_QMAKE_LIB IN_LIST QT_QMAKE_LIBS_FOR_${arg_MODULE_NAME})) + set(QT_QMAKE_LIBS_FOR_${arg_MODULE_NAME} + ${QT_QMAKE_LIBS_FOR_${arg_MODULE_NAME}};${arg_QMAKE_LIB} CACHE INTERNAL "") + set(QT_QMAKE_LIB_TARGETS_${arg_QMAKE_LIB} ${arg_PROVIDED_TARGETS} CACHE INTERNAL "") + endif() endif() endmacro() +macro(qt_add_qmake_lib_dependency lib dep) + string(REPLACE "-" "_" dep ${dep}) + string(TOUPPER "${dep}" ucdep) + list(APPEND QT_QMAKE_LIB_DEPS_${lib} ${ucdep}) +endmacro() + macro(qt_find_apple_system_frameworks) if(APPLE) find_library(FWAppKit AppKit) diff --git a/cmake/QtGenerateExtPri.cmake b/cmake/QtGenerateExtPri.cmake new file mode 100644 index 0000000000..02ac675d4e --- /dev/null +++ b/cmake/QtGenerateExtPri.cmake @@ -0,0 +1,47 @@ +# Generate a qt_ext_XXX.pri file. +# +# - Replaces occurrences of the build libdir with $$[QT_INSTALL_LIBDIR/get]. +# +# This file is to be used in CMake script mode with the following variables set: +# IN_FILES: path to the qt_ext_XXX.cmake files +# OUT_FILE: path to the generated qt_ext_XXX.pri file +# QT_BUILD_LIBDIR: path to Qt's libdir when building (those paths get replaced) +set(content "") +string(TOUPPER "${LIB}" uclib) +set(first_iteration TRUE) +list(LENGTH CONFIGS number_of_configs) +foreach(in_file ${IN_FILES}) + include(${in_file}) + if(first_iteration) + # Add configuration-independent variables + set(first_iteration FALSE) + list(JOIN incdir " " incdir) + list(JOIN defines " " defines) + string(APPEND content "QMAKE_INCDIR_${uclib} = ${incdir} +QMAKE_DEFINES_${uclib} = ${defines} +") + endif() + set(config_suffix "") + if(number_of_configs GREATER "1") + # We're in multi-config mode. Use a _DEBUG or _RELEASE suffix for libs. + # qmake_use.prf does not support other configurations. + string(TOUPPER "${cfg}" config_suffix) + if(config_suffix STREQUAL "DEBUG") + set(config_suffix _DEBUG) + else() + set(config_suffix _RELEASE) + endif() + endif() + + # Replace the build libdir + set(fixed_libs "") + foreach(lib ${libs}) + string(REPLACE "${QT_BUILD_LIBDIR}" "$$[QT_INSTALL_LIBS/get]" lib "${lib}") + list(APPEND fixed_libs "${lib}") + endforeach() + + list(JOIN fixed_libs " " libs) + string(APPEND content "QMAKE_LIBS_${uclib}${config_suffix} = ${libs} +") +endforeach() +file(WRITE "${OUT_FILE}" "${content}") diff --git a/configure.cmake b/configure.cmake index a3a8669d27..456999cf37 100644 --- a/configure.cmake +++ b/configure.cmake @@ -6,10 +6,10 @@ #### Libraries -qt_find_package(ZLIB PROVIDED_TARGETS ZLIB::ZLIB) -qt_find_package(ZSTD PROVIDED_TARGETS ZSTD::ZSTD) -qt_find_package(WrapDBus1 PROVIDED_TARGETS dbus-1) -qt_find_package(Libudev PROVIDED_TARGETS PkgConfig::Libudev) +qt_find_package(ZLIB PROVIDED_TARGETS ZLIB::ZLIB MODULE_NAME global QMAKE_LIB zlib) +qt_find_package(ZSTD PROVIDED_TARGETS ZSTD::ZSTD MODULE_NAME global QMAKE_LIB zstd) +qt_find_package(WrapDBus1 PROVIDED_TARGETS dbus-1 MODULE_NAME global QMAKE_LIB dbus) +qt_find_package(Libudev PROVIDED_TARGETS PkgConfig::Libudev MODULE_NAME global QMAKE_LIB libudev) #### Tests diff --git a/src/3rdparty/freetype/CMakeLists.txt b/src/3rdparty/freetype/CMakeLists.txt index 622b488c34..728e9371c7 100644 --- a/src/3rdparty/freetype/CMakeLists.txt +++ b/src/3rdparty/freetype/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### qt_add_3rdparty_library(BundledFreetype + QMAKE_LIB_NAME freetype STATIC INSTALL SOURCES diff --git a/src/3rdparty/harfbuzz-ng/.prev_CMakeLists.txt b/src/3rdparty/harfbuzz-ng/.prev_CMakeLists.txt index c2b1b6c9ae..f8d1a77a75 100644 --- a/src/3rdparty/harfbuzz-ng/.prev_CMakeLists.txt +++ b/src/3rdparty/harfbuzz-ng/.prev_CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### qt_add_3rdparty_library(BundledHarfbuzz + QMAKE_LIB_NAME harfbuzz STATIC SOURCES hb-dummy.cc diff --git a/src/3rdparty/harfbuzz-ng/CMakeLists.txt b/src/3rdparty/harfbuzz-ng/CMakeLists.txt index 967aac353d..a76cc629c8 100644 --- a/src/3rdparty/harfbuzz-ng/CMakeLists.txt +++ b/src/3rdparty/harfbuzz-ng/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### qt_add_3rdparty_library(BundledHarfbuzz + QMAKE_LIB_NAME harfbuzz STATIC SKIP_AUTOMOC # special case SOURCES diff --git a/src/3rdparty/libpng/CMakeLists.txt b/src/3rdparty/libpng/CMakeLists.txt index d1c5cea164..24fca5d925 100644 --- a/src/3rdparty/libpng/CMakeLists.txt +++ b/src/3rdparty/libpng/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### qt_add_3rdparty_library(BundledLibpng + QMAKE_LIB_NAME libpng STATIC INSTALL SOURCES diff --git a/src/3rdparty/pcre2/CMakeLists.txt b/src/3rdparty/pcre2/CMakeLists.txt index b73f0bff9e..9c70d712e3 100644 --- a/src/3rdparty/pcre2/CMakeLists.txt +++ b/src/3rdparty/pcre2/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### qt_add_3rdparty_library(BundledPcre2 + QMAKE_LIB_NAME pcre2 STATIC SOURCES src/config.h diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake index 4c36877c32..a601ebb437 100644 --- a/src/corelib/configure.cmake +++ b/src/corelib/configure.cmake @@ -14,19 +14,23 @@ set_property(CACHE INPUT_iconv PROPERTY STRINGS undefined no yes posix sun gnu) #### Libraries -qt_find_package(WrapDoubleConversion PROVIDED_TARGETS WrapDoubleConversion::WrapDoubleConversion) -qt_find_package(GLIB2 PROVIDED_TARGETS GLIB2::GLIB2) -qt_find_package(ICU COMPONENTS i18n uc data PROVIDED_TARGETS ICU::i18n ICU::uc ICU::data) -qt_find_package(Libsystemd PROVIDED_TARGETS PkgConfig::Libsystemd) -qt_find_package(WrapAtomic PROVIDED_TARGETS WrapAtomic::WrapAtomic) -qt_find_package(WrapRt PROVIDED_TARGETS WrapRt::WrapRt) -qt_find_package(LTTngUST PROVIDED_TARGETS LTTng::UST) -qt_find_package(WrapSystemPCRE2 PROVIDED_TARGETS WrapSystemPCRE2::WrapSystemPCRE2) +qt_find_package(WrapDoubleConversion PROVIDED_TARGETS WrapDoubleConversion::WrapDoubleConversion MODULE_NAME core QMAKE_LIB doubleconversion) +qt_find_package(GLIB2 PROVIDED_TARGETS GLIB2::GLIB2 MODULE_NAME core QMAKE_LIB glib) +qt_find_package(ICU COMPONENTS i18n uc data PROVIDED_TARGETS ICU::i18n ICU::uc ICU::data MODULE_NAME core QMAKE_LIB icu) +if(QT_FEATURE_dlopen) + qt_add_qmake_lib_dependency(icu libdl) +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(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) +qt_find_package(WrapSystemPCRE2 PROVIDED_TARGETS WrapSystemPCRE2::WrapSystemPCRE2 MODULE_NAME core QMAKE_LIB pcre2) set_package_properties(WrapPCRE2 PROPERTIES TYPE REQUIRED) if((QNX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(PPS PROVIDED_TARGETS PPS::PPS) + qt_find_package(PPS PROVIDED_TARGETS PPS::PPS MODULE_NAME core QMAKE_LIB pps) endif() -qt_find_package(Slog2 PROVIDED_TARGETS Slog2::Slog2) +qt_find_package(Slog2 PROVIDED_TARGETS Slog2::Slog2 MODULE_NAME core QMAKE_LIB slog2) #### Tests @@ -209,7 +213,7 @@ futimens(-1, 0); /* END TEST: */ return 0; } -"# FIXME: qmake: ["# Block futimens() on Apple platforms unless it's available on ALL", '# deployment targets. This simplifies the logic at the call site', "# dramatically, as it isn't strictly needed compared to futimes().", 'darwin: QMAKE_CXXFLAGS += -Werror=unguarded-availability'] +"# FIXME: qmake: ["# Block futimens() on Apple platforms unless it's available on ALL", '# deployment targets. This simplifies the logic at the call site', "# dramatically, as it isn't strictly needed compared to futimes().", 'darwin: QMAKE_CXXFLAGS += -Werror=unguarded-availability -Werror=unguarded-availability-new', 'CONFIG += warn_on'] ) # futimes diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 4354fea8bb..efefda11bd 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -26,89 +26,112 @@ set_property(CACHE INPUT_libpng PROPERTY STRINGS undefined no qt system) #### Libraries -qt_find_package(ATSPI2 PROVIDED_TARGETS PkgConfig::ATSPI2) -qt_find_package(DirectFB PROVIDED_TARGETS PkgConfig::DirectFB) -qt_find_package(Libdrm PROVIDED_TARGETS Libdrm::Libdrm) -qt_find_package(EGL PROVIDED_TARGETS EGL::EGL) -qt_find_package(WrapSystemFreetype PROVIDED_TARGETS WrapSystemFreetype::WrapSystemFreetype) +qt_find_package(ATSPI2 PROVIDED_TARGETS PkgConfig::ATSPI2 MODULE_NAME gui QMAKE_LIB atspi) +qt_find_package(DirectFB PROVIDED_TARGETS PkgConfig::DirectFB MODULE_NAME gui QMAKE_LIB directfb) +qt_find_package(Libdrm PROVIDED_TARGETS Libdrm::Libdrm MODULE_NAME gui QMAKE_LIB drm) +qt_find_package(EGL PROVIDED_TARGETS EGL::EGL MODULE_NAME gui QMAKE_LIB egl) +qt_find_package(WrapSystemFreetype PROVIDED_TARGETS WrapSystemFreetype::WrapSystemFreetype MODULE_NAME gui QMAKE_LIB freetype) set_package_properties(WrapFreetype PROPERTIES TYPE REQUIRED) -qt_find_package(Fontconfig PROVIDED_TARGETS Fontconfig::Fontconfig) -qt_find_package(gbm PROVIDED_TARGETS gbm::gbm) -qt_find_package(WrapSystemHarfbuzz PROVIDED_TARGETS WrapSystemHarfbuzz::WrapSystemHarfbuzz) -qt_find_package(Libinput PROVIDED_TARGETS Libinput::Libinput) -qt_find_package(JPEG PROVIDED_TARGETS JPEG::JPEG) -qt_find_package(WrapSystemPNG PROVIDED_TARGETS WrapSystemPNG::WrapSystemPNG) -qt_find_package(Mtdev PROVIDED_TARGETS PkgConfig::Mtdev) -qt_find_package(OpenGL PROVIDED_TARGETS OpenGL::GL) -qt_find_package(GLESv2 PROVIDED_TARGETS GLESv2::GLESv2) -qt_find_package(Tslib PROVIDED_TARGETS PkgConfig::Tslib) -qt_find_package(Vulkan PROVIDED_TARGETS Vulkan::Vulkan) +if(QT_FEATURE_system_zlib) + qt_add_qmake_lib_dependency(freetype zlib) +endif() +qt_find_package(Fontconfig PROVIDED_TARGETS Fontconfig::Fontconfig MODULE_NAME gui QMAKE_LIB fontconfig) +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 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(WrapSystemPNG PROVIDED_TARGETS WrapSystemPNG::WrapSystemPNG MODULE_NAME gui QMAKE_LIB libpng) +if(QT_FEATURE_system_zlib) + qt_add_qmake_lib_dependency(libpng zlib) +endif() +qt_find_package(Mtdev PROVIDED_TARGETS PkgConfig::Mtdev MODULE_NAME gui QMAKE_LIB mtdev) +qt_find_package(OpenGL PROVIDED_TARGETS OpenGL::GL MODULE_NAME gui QMAKE_LIB opengl) +qt_find_package(GLESv2 PROVIDED_TARGETS GLESv2::GLESv2 MODULE_NAME gui QMAKE_LIB opengl_es2) +qt_find_package(Tslib PROVIDED_TARGETS PkgConfig::Tslib MODULE_NAME gui QMAKE_LIB tslib) +qt_find_package(Vulkan PROVIDED_TARGETS Vulkan::Vulkan MODULE_NAME gui QMAKE_LIB vulkan) if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(Wayland PROVIDED_TARGETS Wayland::Server) + qt_find_package(Wayland PROVIDED_TARGETS Wayland::Server MODULE_NAME gui QMAKE_LIB wayland_server) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(X11 PROVIDED_TARGETS X11::X11) + qt_find_package(X11 PROVIDED_TARGETS X11::X11 MODULE_NAME gui QMAKE_LIB xlib) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(X11 PROVIDED_TARGETS ${X11_SM_LIB} ${X11_ICE_LIB}) + qt_find_package(X11 PROVIDED_TARGETS ${X11_SM_LIB} ${X11_ICE_LIB} MODULE_NAME gui QMAKE_LIB x11sm) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB 1.9 PROVIDED_TARGETS XCB::XCB) + qt_find_package(XCB 1.9 PROVIDED_TARGETS XCB::XCB MODULE_NAME gui QMAKE_LIB xcb) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS ICCCM PROVIDED_TARGETS XCB::ICCCM) + qt_find_package(XCB COMPONENTS ICCCM PROVIDED_TARGETS XCB::ICCCM MODULE_NAME gui QMAKE_LIB xcb_icccm) +endif() +qt_add_qmake_lib_dependency(xcb_icccm xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS IMAGE PROVIDED_TARGETS XCB::IMAGE MODULE_NAME gui QMAKE_LIB xcb_image) +endif() +qt_add_qmake_lib_dependency(xcb_image xcb_shm xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS KEYSYMS PROVIDED_TARGETS XCB::KEYSYMS MODULE_NAME gui QMAKE_LIB xcb_keysyms) +endif() +qt_add_qmake_lib_dependency(xcb_keysyms xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS RENDERUTIL PROVIDED_TARGETS XCB::RENDERUTIL MODULE_NAME gui QMAKE_LIB xcb_renderutil) +endif() +qt_add_qmake_lib_dependency(xcb_renderutil xcb xcb_render) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS RANDR PROVIDED_TARGETS XCB::RANDR MODULE_NAME gui QMAKE_LIB xcb_randr) +endif() +qt_add_qmake_lib_dependency(xcb_randr xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS SHAPE PROVIDED_TARGETS XCB::SHAPE MODULE_NAME gui QMAKE_LIB xcb_shape) +endif() +qt_add_qmake_lib_dependency(xcb_shape xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS SHM PROVIDED_TARGETS XCB::SHM MODULE_NAME gui QMAKE_LIB xcb_shm) +endif() +qt_add_qmake_lib_dependency(xcb_shm xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS SYNC PROVIDED_TARGETS XCB::SYNC MODULE_NAME gui QMAKE_LIB xcb_sync) +endif() +qt_add_qmake_lib_dependency(xcb_sync xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS XFIXES PROVIDED_TARGETS XCB::XFIXES MODULE_NAME gui QMAKE_LIB xcb_xfixes) +endif() +qt_add_qmake_lib_dependency(xcb_xfixes xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS XINERAMA PROVIDED_TARGETS XCB::XINERAMA MODULE_NAME gui QMAKE_LIB xcb_xinerama) +endif() +qt_add_qmake_lib_dependency(xcb_xinerama xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(X11_XCB PROVIDED_TARGETS X11::XCB MODULE_NAME gui QMAKE_LIB xcb_xlib) +endif() +qt_add_qmake_lib_dependency(xcb_xlib xcb xlib) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS XKB PROVIDED_TARGETS XCB::XKB MODULE_NAME gui QMAKE_LIB xcb_xkb) +endif() +qt_add_qmake_lib_dependency(xcb_xkb xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS RENDER PROVIDED_TARGETS XCB::RENDER MODULE_NAME gui QMAKE_LIB xcb_render) +endif() +qt_add_qmake_lib_dependency(xcb_render xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS GLX PROVIDED_TARGETS XCB::GLX MODULE_NAME gui QMAKE_LIB xcb_glx) +endif() +qt_add_qmake_lib_dependency(xcb_glx xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XCB COMPONENTS XINPUT PROVIDED_TARGETS XCB::XINPUT MODULE_NAME gui QMAKE_LIB xcb_xinput) +endif() +qt_add_qmake_lib_dependency(xcb_xinput xcb) +if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) + qt_find_package(XKB 0.4.1 PROVIDED_TARGETS XKB::XKB MODULE_NAME gui QMAKE_LIB xkbcommon) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS IMAGE PROVIDED_TARGETS XCB::IMAGE) + qt_find_package(XKB_COMMON_X11 0.4.1 PROVIDED_TARGETS PkgConfig::XKB_COMMON_X11 MODULE_NAME gui QMAKE_LIB xkbcommon_x11) endif() if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS KEYSYMS PROVIDED_TARGETS XCB::KEYSYMS) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS RENDERUTIL PROVIDED_TARGETS XCB::RENDERUTIL) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS RANDR PROVIDED_TARGETS XCB::RANDR) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS SHAPE PROVIDED_TARGETS XCB::SHAPE) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS SHM PROVIDED_TARGETS XCB::SHM) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS SYNC PROVIDED_TARGETS XCB::SYNC) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS XFIXES PROVIDED_TARGETS XCB::XFIXES) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS XINERAMA PROVIDED_TARGETS XCB::XINERAMA) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(X11_XCB PROVIDED_TARGETS X11::XCB) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS XKB PROVIDED_TARGETS XCB::XKB) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS RENDER PROVIDED_TARGETS XCB::RENDER) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS GLX PROVIDED_TARGETS XCB::GLX) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XCB COMPONENTS XINPUT PROVIDED_TARGETS XCB::XINPUT) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XKB 0.4.1 PROVIDED_TARGETS XKB::XKB) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XKB_COMMON_X11 0.4.1 PROVIDED_TARGETS PkgConfig::XKB_COMMON_X11) -endif() -if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) - qt_find_package(XRender PROVIDED_TARGETS PkgConfig::XRender) + qt_find_package(XRender PROVIDED_TARGETS PkgConfig::XRender MODULE_NAME gui QMAKE_LIB xrender) endif() +qt_add_qmake_lib_dependency(xrender xlib) #### Tests diff --git a/src/network/configure.cmake b/src/network/configure.cmake index ae9deb79ed..924ecb89da 100644 --- a/src/network/configure.cmake +++ b/src/network/configure.cmake @@ -6,8 +6,8 @@ #### Libraries -qt_find_package(Libproxy PROVIDED_TARGETS PkgConfig::Libproxy) -qt_find_package(WrapOpenSSLHeaders PROVIDED_TARGETS WrapOpenSSLHeaders::WrapOpenSSLHeaders) +qt_find_package(Libproxy PROVIDED_TARGETS PkgConfig::Libproxy MODULE_NAME network QMAKE_LIB libproxy) +qt_find_package(WrapOpenSSLHeaders PROVIDED_TARGETS WrapOpenSSLHeaders::WrapOpenSSLHeaders MODULE_NAME network QMAKE_LIB openssl_headers) # openssl_headers qt_config_compile_test(openssl_headers LIBRARIES @@ -32,7 +32,7 @@ int main(int argc, char **argv) } ") -qt_find_package(WrapOpenSSL PROVIDED_TARGETS WrapOpenSSL::WrapOpenSSL) +qt_find_package(WrapOpenSSL PROVIDED_TARGETS WrapOpenSSL::WrapOpenSSL MODULE_NAME network QMAKE_LIB openssl) # openssl qt_config_compile_test(openssl LIBRARIES @@ -57,7 +57,7 @@ SSL_free(SSL_new(0)); } ") -qt_find_package(GSSAPI PROVIDED_TARGETS GSSAPI::GSSAPI) +qt_find_package(GSSAPI PROVIDED_TARGETS GSSAPI::GSSAPI MODULE_NAME network QMAKE_LIB gssapi) #### Tests diff --git a/src/plugins/sqldrivers/configure.cmake b/src/plugins/sqldrivers/configure.cmake index 3733afc859..d742018b9f 100644 --- a/src/plugins/sqldrivers/configure.cmake +++ b/src/plugins/sqldrivers/configure.cmake @@ -10,12 +10,15 @@ set_property(CACHE INPUT_sqlite PROPERTY STRINGS undefined qt system) #### Libraries -qt_find_package(DB2 PROVIDED_TARGETS DB2::DB2) -qt_find_package(MySQL PROVIDED_TARGETS MySQL::MySQL) -qt_find_package(PostgreSQL PROVIDED_TARGETS PostgreSQL::PostgreSQL) -qt_find_package(Oracle PROVIDED_TARGETS Oracle::OCI) -qt_find_package(ODBC PROVIDED_TARGETS ODBC::ODBC) -qt_find_package(SQLite3 PROVIDED_TARGETS SQLite::SQLite3) +qt_find_package(DB2 PROVIDED_TARGETS DB2::DB2 MODULE_NAME sqldrivers QMAKE_LIB db2) +qt_find_package(MySQL PROVIDED_TARGETS MySQL::MySQL MODULE_NAME sqldrivers QMAKE_LIB mysql) +qt_find_package(PostgreSQL PROVIDED_TARGETS PostgreSQL::PostgreSQL MODULE_NAME sqldrivers QMAKE_LIB psql) +qt_find_package(Oracle PROVIDED_TARGETS Oracle::OCI MODULE_NAME sqldrivers QMAKE_LIB oci) +qt_find_package(ODBC PROVIDED_TARGETS ODBC::ODBC MODULE_NAME sqldrivers QMAKE_LIB odbc) +qt_find_package(SQLite3 PROVIDED_TARGETS SQLite::SQLite3 MODULE_NAME sqldrivers QMAKE_LIB sqlite3) +if(NOT WIN32 AND QT_FEATURE_system_zlib) + qt_add_qmake_lib_dependency(sqlite3 zlib) +endif() #### Tests diff --git a/src/printsupport/configure.cmake b/src/printsupport/configure.cmake index d9f63140af..3339d351d3 100644 --- a/src/printsupport/configure.cmake +++ b/src/printsupport/configure.cmake @@ -6,7 +6,7 @@ #### Libraries -qt_find_package(Cups PROVIDED_TARGETS Cups::Cups) +qt_find_package(Cups PROVIDED_TARGETS Cups::Cups MODULE_NAME printsupport QMAKE_LIB cups) #### Tests diff --git a/src/widgets/configure.cmake b/src/widgets/configure.cmake index 7c8f712889..c50f3d7b77 100644 --- a/src/widgets/configure.cmake +++ b/src/widgets/configure.cmake @@ -6,7 +6,7 @@ #### Libraries -qt_find_package(GTK3 PROVIDED_TARGETS PkgConfig::GTK3) +qt_find_package(GTK3 PROVIDED_TARGETS PkgConfig::GTK3 MODULE_NAME widgets QMAKE_LIB gtk3) #### Tests diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index f1bbcaca3e..7f7a103ef6 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -225,9 +225,29 @@ def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set): # configure.cmake is interested in finding the system library # for the purpose of enabling or disabling a system_foo feature. find_package_kwargs["use_system_package_name"] = True + find_package_kwargs["module"] = ctx["module"] cm_fh.write(generate_find_package_info(newlib, **find_package_kwargs)) + if "use" in data["libraries"][lib]: + use_entry = data["libraries"][lib]["use"] + if isinstance(use_entry, str): + print(f"1use: {use_entry}") + cm_fh.write(f"qt_add_qmake_lib_dependency({newlib.soName} {use_entry})\n") + else: + for use in use_entry: + print(f"2use: {use}") + indentation = "" + has_condition = False + if "condition" in use: + has_condition = True + indentation = " " + condition = map_condition(use['condition']) + cm_fh.write(f"if({condition})\n") + cm_fh.write(f"{indentation}qt_add_qmake_lib_dependency({newlib.soName} {use['lib']})\n") + if has_condition: + cm_fh.write("endif()\n") + run_library_test = False mapped_library = find_3rd_party_library_mapping(lib) if mapped_library: diff --git a/util/cmake/helper.py b/util/cmake/helper.py index 5dce5b2bf0..4930b0d1a2 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -778,6 +778,7 @@ def generate_find_package_info( indent: int = 0, emit_if: str = "", use_system_package_name: bool = False, + module: str = "", ) -> str: isRequired = False @@ -801,8 +802,12 @@ def generate_find_package_info( package_name = package_name.replace(*replace_args) cmake_target_name = cmake_target_name.replace(*replace_args) - if cmake_target_name and use_qt_find_package: - extra += ["PROVIDED_TARGETS", cmake_target_name] + if use_qt_find_package: + if cmake_target_name: + extra += ["PROVIDED_TARGETS", cmake_target_name] + if module: + extra += ["MODULE_NAME", module] + extra += ["QMAKE_LIB", lib.soName] result = "" one_ind = " " diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 1638fede08..71ef931800 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -2965,6 +2965,7 @@ def write_3rdparty_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> target_name = re.sub(r"^qt", "", scope.TARGET) target_name = target_name.replace("-", "_") + qmake_lib_name = target_name # Capitalize the first letter for a nicer name. target_name = target_name.title() @@ -2978,7 +2979,7 @@ def write_3rdparty_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> else: library_type = "STATIC" - extra_lines = [] + extra_lines = [f"QMAKE_LIB_NAME {qmake_lib_name}"] if library_type: extra_lines.append(library_type)