qtbase/util/cmake/helper.py

274 lines
9.5 KiB
Python
Raw Normal View History

#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the plugins of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
import re
def featureName(input: str) -> str:
return re.sub(r'[^a-zA-Z0-9_]', '_', input)
def map_qt_base_library(lib: str) -> str:
library_map = {
'global': 'Qt::Core', # manually added special case
'accessibility_support': 'Qt::AccessibilitySupport',
'androidextras': 'Qt::AndroidExtras',
'animation': 'Qt::3DAnimation',
'application-lib': 'Qt::AppManApplication',
'bluetooth': 'Qt::Bluetooth',
'bootstrap-dbus': 'Qt::BootstrapDBus',
'bootstrap': 'Qt::Bootstrap',
'client': 'Qt::WaylandClient',
'clipboard_support': 'Qt::ClipboardSupport',
'common-lib': 'Qt::AppManCommon',
'compositor': 'Qt::WaylandCompositor',
'concurrent': 'Qt::Concurrent',
'container': 'Qt::AxContainer',
'control': 'Qt::AxServer',
'core_headers': 'Qt::WebEngineCore',
'core': 'Qt::Core',
'coretest': 'Qt::3DCoreTest',
'crypto-lib': 'Qt::AppManCrypto',
'dbus': 'Qt::DBus',
'devicediscovery': 'Qt::DeviceDiscoverySupport',
'devicediscovery_support': 'Qt::DeviceDiscoverySupport',
'edid': 'Qt::EdidSupport',
'eglconvenience': 'Qt::EglSupport',
'eglfsdeviceintegration': 'Qt::EglFSDeviceIntegration',
'eglfs_kms_support': 'Qt::EglFsKmsSupport',
'egl_support': 'Qt::EglSupport',
'enginio_client': 'Enginio',
'eventdispatchers': 'Qt::EventDispatcherSupport',
'extras': 'Qt::3DExtras',
'fb_support': 'Qt::FbSupport',
'fbconvenience': 'Qt::FbSupport',
'fontdatabase_support': 'Qt::FontDatabaseSupport',
'gamepad': 'Qt::Gamepad',
'glx_support': 'Qt::GlxSupport',
'graphics_support': 'Qt::GraphicsSupport',
'gsttools': 'Qt::MultimediaGstTools',
'gui': 'Qt::Gui',
'help': 'Qt::Help',
'hunspellinputmethod': 'Qt::HunspellInputMethod',
'input': 'Qt::InputSupport',
'input_support': 'Qt::InputSupport',
'installer-lib': 'Qt::AppManInstaller',
'kmsconvenience': 'Qt::KmsSupport',
'kms_support': 'Qt::KmsSupport',
'launcher-lib': 'Qt::AppManLauncher',
'lib': 'Qt::Designer',
'linuxaccessibility_support': 'Qt::LinuxAccessibilitySupport',
'location': 'Qt::Location',
'logic': 'Qt::3DLogic',
'macextras': 'Qt::MacExtras',
'main-lib': 'Qt::AppManMain',
'manager-lib': 'Qt::AppManManager',
'monitor-lib': 'Qt::AppManMonitor',
'multimedia': 'Qt::Multimedia',
'multimediawidgets': 'Qt::MultimediaWidgets',
'network': 'Qt::Network',
'nfc': 'Qt::Nfc',
'oauth': 'Qt::NetworkAuth',
'openglextensions': 'Qt::OpenGLExtensions',
'opengl': 'Qt::OpenGL',
'package-lib': 'Qt::AppManPackage',
'packetprotocol': 'Qt::PacketProtocol',
'particles': 'Qt::QuickParticles',
'platformcompositor': 'Qt::PlatformCompositorSupport',
'platformcompositor_support': 'Qt::PlatformCompositorSupport',
'plugin-interfaces': 'Qt::AppManPluginInterfaces',
'positioning': 'Qt::Positioning',
'positioningquick': 'Qt::PositioningQuick',
'printsupport': 'Qt::PrintSupport',
'purchasing': 'Qt::Purchasing',
'qmldebug': 'Qt::QmlDebug',
'qmldevtools': 'Qt::QmlDevTools',
'qml': 'Qt::Qml',
'qmltest': 'Qt::QuickTest',
'qtmultimediaquicktools': 'Qt::MultimediaQuick',
'qtzlib': 'Qt::Zlib',
'quick3danimation': 'Qt::3DQuickAnimation',
'quick3dextras': 'Qt::3DQuickExtras',
'quick3dinput': 'Qt::3DQuickInput',
'quick3d': 'Qt::3DQuick',
'quick3drender': 'Qt::3DQuickRender',
'quick3dscene2d': 'Qt::3DQuickScene2D',
'quickcontrols2': 'Qt::QuickControls2',
'quick': 'Qt::Quick',
'quickshapes': 'Qt::QuickShapes',
'quicktemplates2': 'Qt::QuickTemplates2',
'quickwidgets': 'Qt::QuickWidgets',
'render': 'Qt::3DRender',
'script': 'Qt::Script',
'scripttools': 'Qt::ScriptTools',
'sensors': 'Qt::Sensors',
'serialport': 'Qt::SerialPort',
'services': 'Qt::ServiceSupport',
'sql': 'Qt::Sql',
'svg': 'Qt::Svg',
'testlib': 'Qt::Test',
'theme_support': 'Qt::ThemeSupport',
'service_support': 'Qt::ServiceSupport',
'eventdispatcher_support': 'Qt::EventDispatcherSupport',
'edid_support': 'Qt::EdidSupport',
'tts': 'Qt::TextToSpeech',
'uiplugin': 'Qt::UiPlugin',
'uitools': 'Qt::UiTools',
'virtualkeyboard': 'Qt::VirtualKeyboard',
'vulkan_support': 'Qt::VulkanSupport',
'webchannel': 'Qt::WebChannel',
'webengine': 'Qt::WebEngine',
'webenginewidgets': 'Qt::WebEngineWidgets',
'websockets': 'Qt::WebSockets',
'webview': 'Qt::WebView',
'widgets': 'Qt::Widgets',
'window-lib': 'Qt::AppManWindow',
'windowsuiautomation_support': 'Qt::WindowsUIAutomationSupport',
'winextras': 'Qt::WinExtras',
'x11extras': 'Qt::X11Extras',
'xcb_qpa_lib': 'Qt::XcbQpa',
'xkbcommon_support': 'Qt::XkbCommonSupport',
'xmlpatterns': 'Qt::XmlPatterns',
'xml': 'Qt::Xml',
}
return library_map.get(lib, lib)
def map_qt_library(lib: str) -> str:
private = False
if lib.endswith('-private'):
private = True
lib = lib[:-8]
mapped = map_qt_base_library(lib)
if private:
mapped += 'Private'
return mapped
platform_mapping = {
'win32': 'WIN32',
'unix': 'UNIX',
'darwin': 'APPLE',
'linux': 'LINUX',
'integrity': 'INTEGRITY',
'qnx': 'QNX',
'vxworks': 'VXWORKS',
'hpux': 'HPUX',
'nacl': 'NACL',
'android': 'ANDROID',
'android-embedded': 'ANDROID_EMBEDDED',
'uikit': 'APPLE_UIKIT',
'tvos': 'APPLE_TVOS',
'watchos': 'APPLE_WATCHOS',
'winrt': 'WINRT',
'wasm': 'WASM',
'msvc': 'MSVC',
'clang': 'CLANG',
'gcc': 'GCC',
'icc': 'ICC',
'intel_icc': 'ICC',
'osx': 'APPLE_OSX',
'ios': 'APPLE_IOS',
'freebsd': 'FREEBSD',
'openbsd': 'OPENBSD',
'netbsd': 'NETBSD',
'haiku': 'HAIKU',
'netbsd': 'NETBSD',
'mac': 'APPLE_OSX',
'macx': 'APPLE_OSX',
'macos': 'APPLE_OSX',
'macx-icc': '(APPLE_OSX AND ICC)',
}
def substitute_platform(platform: str) -> str:
""" Return the qmake platform as cmake platform or the unchanged string. """
return platform_mapping.get(platform, platform)
Write find_dependency() calls in Qt Module config files This change introduces a new function called qt_find_package() which can take an extra option called PROVIDED_TARGETS, which associates targets with the package that defines those targets. This is done by setting the INTERFACE_QT_PACKAGE_NAME and INTERFACE_QT_PACKAGE_VERSION properties on the imported targets. This information allows us to generate appropriate find_dependency() calls in a module's Config file for third party libraries. For example when an application links against QtCore, it should also link against zlib and atomic libraries. In order to do that, the library locations first have to be found by CMake. This is achieved by embedding find_dependency(ZLIB) and find_dependency(Atomic) in Qt5CoreDependencies.cmake which is included by Qt5CoreConfig.cmake. The latter is picked up when an application project contains find_package(Qt5Core), and thus all linking dependencies are resolved. The information 'which package provides which targets' is contained in the python json2cmake conversion script. The generated output of the script contains qt_find_package() calls that represent that information. The Qt5CoreDependencies.cmake file and which which dependencies it contains is generated at the QtPostProcess stop. Note that for non-static Qt builds, we only need to propagate public 3rd party libraries. For static builds, we need all third party libraries. In order for the INTERFACE_QT_PACKAGE_NAME property to be read in any scope, the targets on which the property is set, have to be GLOBAL. Also for applications and other modules to find all required third party libraries, we have to install all our custom Find modules, and make sure they define INTERFACE IMPORTED libraries, and not just IMPORTED libraries. Change-Id: I694d6e32d05b96d5e241df0156fc79d0029426aa Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-24 15:14:25 +00:00
qmake_library_to_cmake_target_mapping = {
'atspi': 'PkgConfig::ATSPI2',
'cups': 'Cups::Cups',
'drm': 'Libdrm::Libdrm',
'doubleconversion': 'double-conversion',
'fontconfig': 'Fontconfig::Fontconfig',
'freetype': 'Freetype::Freetype',
'gbm': 'gbm::gbm',
'glib': 'GLIB2::GLIB2',
'glx_support': 'Qt::GlxSupport',
'glx_supportPrivate': 'Qt::GlxSupportPrivate',
'harfbuzz': 'harfbuzz::harfbuzz',
'icu': 'ICU::i18n ICU::uc ICU::data',
'libatomic': 'Atomic',
'libdl': '${CMAKE_DL_LIBS}',
'libinput': 'Libinput::Libinput',
'libpng' : 'PNG::PNG',
Write find_dependency() calls in Qt Module config files This change introduces a new function called qt_find_package() which can take an extra option called PROVIDED_TARGETS, which associates targets with the package that defines those targets. This is done by setting the INTERFACE_QT_PACKAGE_NAME and INTERFACE_QT_PACKAGE_VERSION properties on the imported targets. This information allows us to generate appropriate find_dependency() calls in a module's Config file for third party libraries. For example when an application links against QtCore, it should also link against zlib and atomic libraries. In order to do that, the library locations first have to be found by CMake. This is achieved by embedding find_dependency(ZLIB) and find_dependency(Atomic) in Qt5CoreDependencies.cmake which is included by Qt5CoreConfig.cmake. The latter is picked up when an application project contains find_package(Qt5Core), and thus all linking dependencies are resolved. The information 'which package provides which targets' is contained in the python json2cmake conversion script. The generated output of the script contains qt_find_package() calls that represent that information. The Qt5CoreDependencies.cmake file and which which dependencies it contains is generated at the QtPostProcess stop. Note that for non-static Qt builds, we only need to propagate public 3rd party libraries. For static builds, we need all third party libraries. In order for the INTERFACE_QT_PACKAGE_NAME property to be read in any scope, the targets on which the property is set, have to be GLOBAL. Also for applications and other modules to find all required third party libraries, we have to install all our custom Find modules, and make sure they define INTERFACE IMPORTED libraries, and not just IMPORTED libraries. Change-Id: I694d6e32d05b96d5e241df0156fc79d0029426aa Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-24 15:14:25 +00:00
'libproxy': 'PkgConfig::Libproxy',
'librt': 'WrapRt',
'libudev': 'PkgConfig::Libudev',
'mtdev': 'PkgConfig::Mtdev',
'odbc': 'ODBC::ODBC',
'openssl': 'OpenSSL::SSL',
'pcre2': 'PCRE2',
'psql': 'PostgreSQL::PostgreSQL',
'sqlite': 'SQLite::SQLite3',
'SQLite3': 'SQLite::SQLite3',
'tslib': 'PkgConfig::Tslib',
'x11sm': '${X11_SM_LIB} ${X11_ICE_LIB}',
'xcb_glx': 'XCB::GLX',
'xcb_icccm': 'XCB::ICCCM',
'xcb_image': 'XCB::IMAGE',
'xcb_keysyms': 'XCB::KEYSYMS',
'xcb_randr': 'XCB::RANDR',
'xcb_renderutil': 'XCB::RENDERUTIL',
'xcb_render': 'XCB::RENDER',
'xcb_shape': 'XCB::SHAPE',
'xcb_shm': 'XCB::SHM',
'xcb_sync': 'XCB::SYNC',
'xcb': 'XCB::XCB',
'xcb_xfixes': 'XCB::XFIXES',
'xcb_xinerama': 'XCB::XINERAMA',
'xcb_xinput': 'XCB::XINPUT',
'xcb_xkb': 'XCB::XKB',
'xcb_xlib': 'X11::XCB',
'xkbcommon_evdev': 'XKB::XKB',
'xkbcommon_x11': 'XKB::XKB',
'xkbcommon': 'XKB::XKB',
'xrender': 'XCB::RENDER',
'zlib': 'ZLIB::ZLIB',
'zstd': 'ZSTD::ZSTD',
}
def substitute_libs(lib: str) -> str:
libpostfix = ''
if lib.endswith('/nolink'):
lib = lib[:-7]
libpostfix = '_nolink'
Write find_dependency() calls in Qt Module config files This change introduces a new function called qt_find_package() which can take an extra option called PROVIDED_TARGETS, which associates targets with the package that defines those targets. This is done by setting the INTERFACE_QT_PACKAGE_NAME and INTERFACE_QT_PACKAGE_VERSION properties on the imported targets. This information allows us to generate appropriate find_dependency() calls in a module's Config file for third party libraries. For example when an application links against QtCore, it should also link against zlib and atomic libraries. In order to do that, the library locations first have to be found by CMake. This is achieved by embedding find_dependency(ZLIB) and find_dependency(Atomic) in Qt5CoreDependencies.cmake which is included by Qt5CoreConfig.cmake. The latter is picked up when an application project contains find_package(Qt5Core), and thus all linking dependencies are resolved. The information 'which package provides which targets' is contained in the python json2cmake conversion script. The generated output of the script contains qt_find_package() calls that represent that information. The Qt5CoreDependencies.cmake file and which which dependencies it contains is generated at the QtPostProcess stop. Note that for non-static Qt builds, we only need to propagate public 3rd party libraries. For static builds, we need all third party libraries. In order for the INTERFACE_QT_PACKAGE_NAME property to be read in any scope, the targets on which the property is set, have to be GLOBAL. Also for applications and other modules to find all required third party libraries, we have to install all our custom Find modules, and make sure they define INTERFACE IMPORTED libraries, and not just IMPORTED libraries. Change-Id: I694d6e32d05b96d5e241df0156fc79d0029426aa Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-24 15:14:25 +00:00
return qmake_library_to_cmake_target_mapping.get(lib, lib) + libpostfix