diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-02-14 14:53:28 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-02-25 15:43:16 +0100 |
commit | 26059d1b9b84bbaaa6c5a50a7dea88ffa9051c5a (patch) | |
tree | 8fb5694a33a28771f241db97c8b777ca0f5b9156 /util/cmake/pro2cmake.py | |
parent | 1b474118326d0cc7a69b20d22d1e52d9ed42c07e (diff) |
CMake: Allow building bundled 3rd party libraries in qtbase
A few things are needed to accomplish that:
- the python scripts do not ignore certain system_foo features anymore
(it is a hardcoded list for now just to be safe)
- configurejson2cmake now outputs
qt_find_package(WrapSystemFoo) calls for bundled libraries
(see below)
- the harfbuzz .pro file is modified to accommodate pro2cmake
not being able to correctly parse some conditional scopes
- the freetype .pro file is modified to make sure linking of the
library succeeds without duplicate symbol errors, which qmake
doesn't encounter due to magical exclusion of cpp files that are
included in other cpp files (presumably for include moc_foo.cpp
support)
- feature evaluation for Core, Gui, Network now happens in the
qtbase/src directory, so that bundled libraries can be conditionally
built
- for each bundled library there are now two FindWrap scripts:
- FindWrapSystemFoo which finds an installed library in the system
- FindWrapFoo which either uses the system installed library or
the built bundled one depending on a condition
- projects that intend to use bundled libraries need to link against
WrapFoo::WrapFoo instead of WrapSystemFoo::WrapSystemFoo targets
(this is handled by pro2cmake).
Unfortunately manually added qt_find_package(WrapFoo) calls might
still be needed as is the case for WrapFreetype and others.
- a new cmake/QtFindWrapHelper.cmake file is added that provides
a macro to simplify creation of WrapFoo targets that link against
a bundled or system library. The implementation is fairly ugly
due to CMake macro constraints, but it was deemed better than
copy-pasting a bunch of almost identical code across all
FindWrapFoo.cmake files.
- a qtzlib header-only module is now created when using bundled
zlib, to provide public syncqt created headers for consumers
that need them. These are projects that have
'QT_PRIVATE += zlib-private' in their .pro files
(e.g. qtimageformats, qtlocation, qt3d, etc.)
This is unfortunately needed due to QtNetwork using zlib
types in its private C++ API.
The change includes support for building the following bundled
libraries:
- zlib
- libpng
- libjpeg
- Freetype
- Harfbuzz-ng
- PCRE2
The following 3rd party libraries are still using an old
implementation within the CMake build system, and should be migrated
to the new one in the near future:
- double-conversion
- Old harfbuzz
The are a few libraries that are not yet ported:
- system-sqlite
- systemxcb
- maybe others
Among other things, this change allows building qtbase on Windows
without requiring vcpkg.
Task-number: QTBUG-82167
Change-Id: I35ecea0d832f66c1943c82e618de4a51440971a5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Diffstat (limited to 'util/cmake/pro2cmake.py')
-rwxr-xr-x | util/cmake/pro2cmake.py | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index b46985e582..fca5d4fceb 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1556,8 +1556,11 @@ def map_condition(condition: str) -> str: part = f"TARGET {map_qt_library(feature.group(2))}" else: feature_name = featureName(feature.group(2)) - if feature_name.startswith("system_") and is_known_3rd_party_library( - feature_name[7:] + if ( + feature_name.startswith("system_") + and is_known_3rd_party_library(feature_name[7:]) + and not feature_name.startswith("system_jpeg") + and not feature_name.startswith("system_zlib") ): part = "ON" elif feature == "dlopen": @@ -1955,14 +1958,46 @@ def write_defines( write_list(cm_fh, defines, cmake_parameter, indent, footer=footer) -def write_include_paths( +def write_3rd_party_defines( cm_fh: IO[str], scope: Scope, cmake_parameter: str, *, indent: int = 0, footer: str = "" ): - includes = [i.rstrip("/") or ("/") for i in scope.get_files("INCLUDEPATH")] + defines = scope.expand("MODULE_DEFINES") + write_list(cm_fh, defines, cmake_parameter, indent, footer=footer) + +def get_include_paths_helper(scope: Scope, include_var_name: str) -> List[str]: + includes = [i.rstrip("/") or ("/") for i in scope.get_files(include_var_name)] + return includes + + +def write_include_paths( + cm_fh: IO[str], scope: Scope, cmake_parameter: str, *, indent: int = 0, footer: str = "" +): + includes = get_include_paths_helper(scope, "INCLUDEPATH") write_list(cm_fh, includes, cmake_parameter, indent, footer=footer) +def write_3rd_party_include_paths( + cm_fh: IO[str], scope: Scope, cmake_parameter: str, *, indent: int = 0, footer: str = "" +): + # Used in qt_helper_lib.prf. + includes = get_include_paths_helper(scope, "MODULE_INCLUDEPATH") + + # Wrap the includes in BUILD_INTERFACE generator expression, because + # the include paths point to a source dir, and CMake will error out + # when trying to create consumable exported targets. + processed_includes = [] + for i in includes: + # CMake generator expressions don't seem to like relative paths. + # Make them absolute relative to the source dir. + if not os.path.isabs(i) and not i.startswith("$"): + i = f"${{CMAKE_CURRENT_SOURCE_DIR}}/{i}" + i = f"$<BUILD_INTERFACE:{i}>" + processed_includes.append(i) + + write_list(cm_fh, processed_includes, cmake_parameter, indent, footer=footer) + + def write_compile_options( cm_fh: IO[str], scope: Scope, cmake_parameter: str, *, indent: int = 0, footer: str = "" ): @@ -2051,8 +2086,12 @@ def write_sources_section( write_defines(cm_fh, scope, "DEFINES", indent=indent + 1) + write_3rd_party_defines(cm_fh, scope, "PUBLIC_DEFINES", indent=indent + 1) + write_include_paths(cm_fh, scope, "INCLUDE_DIRECTORIES", indent=indent + 1) + write_3rd_party_include_paths(cm_fh, scope, "PUBLIC_INCLUDE_DIRECTORIES", indent=indent + 1) + write_library_section(cm_fh, scope, indent=indent, known_libraries=known_libraries) write_compile_options(cm_fh, scope, "COMPILE_OPTIONS", indent=indent + 1) @@ -2332,6 +2371,11 @@ def write_repc_files(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0) cm_fh.write(")\n") +def write_generic_cmake_command(cm_fh: IO[str], command_name: str, arguments: List[str]): + arguments_str = " ".join(arguments) + cm_fh.write(f"{command_name}({arguments_str})\n") + + def expand_project_requirements(scope: Scope, skip_message: bool = False) -> str: requirements = "" for requirement in scope.get("_REQUIREMENTS"): @@ -2785,6 +2829,12 @@ def write_main_part( write_wayland_part(cm_fh, name, scopes[0], indent) + if "warn_off" in scope.get("CONFIG"): + write_generic_cmake_command(cm_fh, "qt_disable_warnings", [name]) + + if "hide_symbols" in scope.get("CONFIG"): + write_generic_cmake_command(cm_fh, "qt_set_symbol_visibility_hidden", [name]) + ignored_keys_report = write_ignored_keys(scopes[0], spaces(indent)) if ignored_keys_report: cm_fh.write(ignored_keys_report) @@ -2808,14 +2858,18 @@ def write_main_part( def write_3rdparty_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str: - # Remove default QT libs. scope._append_operation("QT", RemoveOperation(["core", "gui"])) target_name = re.sub(r"^qt", "", scope.TARGET) target_name = target_name.replace("-", "_") - library_type = "" + # Capitalize the first letter for a nicer name. + target_name = target_name.title() + + # Prefix with Bundled, to avoid possible duplicate target names + # e.g. "BundledFreetype" instead of "freetype". + target_name = f"Bundled{target_name}" if "dll" in scope.get("CONFIG"): library_type = "SHARED" @@ -2827,6 +2881,9 @@ def write_3rdparty_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> if library_type: extra_lines.append(library_type) + if "installed" in scope.get("CONFIG"): + extra_lines.append("INSTALL") + write_main_part( cm_fh, target_name, |