diff options
author | Iikka Eklund <iikka.eklund@qt.io> | 2021-06-29 11:52:49 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-26 06:55:40 +0000 |
commit | d421f565e9190b5e9e3af19b60e67bf85c8eb2cf (patch) | |
tree | 4853b5b942df9edddf62a2ef79ba8f0ceb53ce65 | |
parent | 07d24b969820a97ed60367831d90175cd49333dd (diff) |
Support builds with Conan
Provide conanfile.py recipe to support building this module
with Conan. The conanfile.py recipe inherits the main
functionality from base class located in qt-conan-common.git.
'qt-configure-module(.bat)' and cmake is used for the builds.
Dependencies (Conan requirements) are defined by the base
class implementation which reads those from the
'dependencies.yaml' which is also used by the Coin/CI.
Task-number: QTBUG-94854
Change-Id: Id8a082c850463370278ce072b7e1d00745b374d7
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Toni Saario <toni.saario@qt.io>
(cherry picked from commit 6dc4b8457ce1f49c761dda5ed13d5165e64a9b81)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | .cmake.conf | 1 | ||||
-rw-r--r-- | conanfile.py | 139 |
2 files changed, 43 insertions, 97 deletions
diff --git a/.cmake.conf b/.cmake.conf index 4e73b3d6..4aa8eb1f 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -1 +1,2 @@ set(QT_REPO_MODULE_VERSION "6.2.0") +set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") diff --git a/conanfile.py b/conanfile.py index 7434ced2..aec6f724 100644 --- a/conanfile.py +++ b/conanfile.py @@ -26,112 +26,57 @@ ## ############################################################################# -from conans import ConanFile, tools, CMake -import os +from conans import ConanFile +import re from pathlib import Path +from typing import Dict, Any +_qtcharts_features = [ + "charts-area-chart", + "charts-bar-chart", + "charts-boxplot-chart", + "charts-candlestick-chart", + "charts-datetime-axis", + "charts-line-chart", + "charts-pie-chart", + "charts-scatter-chart", + "charts-spline-chart", +] -class QtConanError(Exception): - pass + +def _parse_qt_version_by_key(key: str) -> str: + with open(Path(__file__).parent.resolve() / ".cmake.conf") as f: + m = re.search(fr'{key} .*"(.*)"', f.read()) + return m.group(1) if m else "" + + +def _get_qt_minor_version() -> str: + return ".".join(_parse_qt_version_by_key("QT_REPO_MODULE_VERSION").split(".")[:2]) class QtCharts(ConanFile): name = "qtcharts" - version = "6.2.0" license = "GPL-3.0+, Commercial Qt License Agreement" author = "The Qt Company <https://www.qt.io/contact-us>" - url = "https://code.qt.io/cgit/qt/qtcharts.git/" - description = "Qt Charts provides UI Components for displaying visually pleasing charts, driven by static or dynamic data models." - topics = ("qt", "qt6", "charts", "qtquick") - settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False, "default"], - "qt6": "ANY"} # this is needed to model unique package_id for the Add-on build per used Qt6 version - default_options = {"shared": "default", # default: Use the value of the Qt build - "qt6": None} + url = "https://code.qt.io/cgit/qt/qtcharts.git" + description = ( + "Qt Charts module provides a set of easy to use chart components. " + "It uses the Qt Graphics View Framework, therefore charts can be easily integrated " + "to modern user interfaces. Qt Charts can be used as QWidgets, QGraphicsWidget, or QML types. " + "Users can easily create impressive graphs by selecting one of the charts themes." + ) + topics = "qt", "qt6", "qtcharts", "charts", "graphs" + settings = "os", "compiler", "arch", "build_type" + # for referencing the version number and prerelease tag and dependencies info + exports = ".cmake.conf", "dependencies.yaml" exports_sources = "*", "!conan*.*" - # use commit ID as the RREV (recipe revision) if this is exported from .git repository - revision_mode = "scm" if Path(Path(__file__).parent.resolve() / ".git").exists() else "hash" - - def source(self): - # sources are installed next to recipe, no need to clone etc. sources here - pass - - def _get_cmake_prefix_path(self): - # 'QTDIR' provided as env variable in profile file which is part of the Qt essential binary - # package(s). Installed under .conan/profiles - cmake_prefix_path = os.environ.get("QTDIR") - if not cmake_prefix_path: - raise QtConanError("'QTDIR' not defined! The 'QTDIR' needs to point to Qt installation directory.") - print(f"CMAKE_PREFIX_PATH for '{self.name}/{self.version}' build is: {cmake_prefix_path}") - return cmake_prefix_path - - def _read_env(self, key): - value = os.environ.get(key) - if not value: - raise QtConanError(f"{self.settings.os} build specified but '{key}' was not defined?") - return value - - def _get_qtcmake(self): - qt_install_path = self._get_cmake_prefix_path() - ext = ".bat" if tools.os_info.is_windows else "" - qtcmake = os.path.abspath(os.path.join(qt_install_path, "bin", "qt-cmake" + ext)) - if not os.path.exists(qtcmake): - raise QtConanError(f"Unable to locate {qtcmake} from 'QTDIR': {qt_install_path}") - return qtcmake - - def _get_cmake_tool(self): - cmake = CMake(self, cmake_program=self._get_qtcmake()) - cmake.verbose = True - - # Qt modules need to be 'installed'. - # We need to direct the 'make install' to some directory under Conan cache, - # place it under the current build directory which is also under the Conan cache. - # Note, the actual 'make install' is called in "package()". - install_dir = os.path.join(os.getcwd(), "_install_tmp") - cmake.definitions["CMAKE_INSTALL_PREFIX"] = install_dir - - # Use the value of the Qt build - if self.options.shared.value == "default": - del cmake.definitions["BUILD_SHARED_LIBS"] - - cmake_toolchain_file = os.environ.get("CMAKE_TOOLCHAIN_FILE") - if cmake_toolchain_file: - cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = cmake_toolchain_file - - if self.settings.os == "Android": - cmake.definitions["ANDROID_SDK_ROOT"] = self._read_env('ANDROID_SDK_ROOT') - cmake.definitions["ANDROID_NDK_ROOT"] = self._read_env('ANDROID_NDK_ROOT') - - if self.settings.os == "iOS": - # Instead of Conan's auto-added 'Darwin', explicitly pass 'iOS'. - cmake.definitions["CMAKE_SYSTEM_NAME"] = "iOS" - - # Remove the explicit sysroot, let CMake detect the sysroots, to ensure - # that multi-arch builds work. - del cmake.definitions["CMAKE_OSX_SYSROOT"] - - # Remove the conan provided architecture, instead rely on the architectures set - # by the Qt toolchain file, which with official Qt packages most likely means - # multi-arch iOS. - del cmake.definitions["CMAKE_OSX_ARCHITECTURES"] - - return cmake - - def build(self): - cmake = self._get_cmake_tool() - self.run('%s "%s" %s' % (self._get_qtcmake(), self.source_folder, cmake.command_line)) - self.run('cmake --build . %s' % cmake.build_config) - return - - def package(self): - install_dir = os.path.join(os.getcwd(), "_install_tmp") # see 'CMAKE_INSTALL_PREFIX' above - self.run('cmake --build . --target install') - self.copy("*", src=install_dir, dst=".") - - def package_info(self): - self.cpp_info.libs = ["Qt6Charts"] # used for the actual library filename, Ordered list with the library names + python_requires = f"qt-conan-common/{_get_qt_minor_version()}@qt/everywhere" + python_requires_extend = "qt-conan-common.QtLeafModule" - def deploy(self): - self.copy("*") # copy from current package - self.copy_deps("*") # copy from dependencies + def get_qt_leaf_module_options(self) -> Dict[str, Any]: + """Implements abstractmethod from qt-conan-common.QtLeafModule""" + return {item.replace("-", "_"): ["yes", "no", None] for item in _qtcharts_features} + def get_qt_leaf_module_default_options(self) -> Dict[str, Any]: + """Implements abstractmethod from qt-conan-common.QtLeafModule""" + return {item.replace("-", "_"): None for item in _qtcharts_features} |