Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qcustomplot] Use version range for Qt #25423

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
36 changes: 20 additions & 16 deletions recipes/qcustomplot/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QCustomPlotConan(ConanFile):
topics = ("chart", "data-visualization", "graph", "plot", "qt")
homepage = "https://www.qcustomplot.com"
url = "https://github.com/conan-io/conan-center-index"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -39,26 +40,26 @@ def config_options(self):
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
# FIXME: we shouldn't have to force shared in qt, but config file
# generated by conan in qt static is likely broken, or maybe env vars.
self.options["qt"].shared = True

def build_requirements(self):
self.tool_requires("qt/<host_version>")
self.tool_requires("cmake/[>=3.27 <4]") # to be able to use CMAKE_AUTOMOC_EXECUTABLE

def requirements(self):
if Version(self.version) >= "2.0.0":
self.requires("qt/6.4.1")
# INFO: Public header qcustomplot.h includes QObject
self.requires("qt/[>=6.5 <7]", transitive_headers=True, options={"widgets": True, "gui": True})
else:
self.requires("qt/5.15.7")
# INFO: Public header qcustomplot.h includes QObject
self.requires("qt/[~5.15]", transitive_headers=True, options={"widgets": True, "gui": True})
if self.options.with_opengl and self.settings.os == "Windows":
self.requires("opengl/system")

def validate(self):
if self.info.settings.compiler.cppstd:
min_cppstd = "11" if Version(self.dependencies["qt"].ref.version) < "6.0.0" else "17"
check_min_cppstd(self, min_cppstd)
if not (self.dependencies["qt"].options.gui and self.dependencies["qt"].options.widgets):
raise ConanInvalidConfiguration(f"{self.ref} requires qt gui and widgets")
min_cppstd = "11" if Version(self.dependencies["qt"].ref.version) < "6" else "17"
check_min_cppstd(self, min_cppstd)
if self.info.options.with_opengl and self.dependencies["qt"].options.opengl == "no":
raise ConanInvalidConfiguration(f"{self.ref} with opengl requires Qt with opengl enabled")
raise ConanInvalidConfiguration(f"{self.ref} with opengl requires Qt with opengl enabled: -o 'qt/*:opengl=desktop/dynamic'")

def layout(self):
cmake_layout(self, src_folder="src")
Expand All @@ -69,11 +70,14 @@ def source(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["QCUSTOMPLOT_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.variables["QCUSTOMPLOT_VERSION"] = self.version
tc.variables["QCUSTOMPLOT_VERSION_MAJOR"] = str(Version(self.version).major)
tc.variables["QT_VERSION"] = self.dependencies["qt"].ref.version
tc.variables["QCUSTOMPLOT_USE_OPENGL"] = self.options.with_opengl
tc.cache_variables["QCUSTOMPLOT_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.cache_variables["QCUSTOMPLOT_VERSION"] = str(self.version)
tc.cache_variables["QCUSTOMPLOT_VERSION_MAJOR"] = str(Version(self.version).major)
tc.cache_variables["QT_VERSION"] = str(self.dependencies["qt"].ref.version)
tc.cache_variables["QCUSTOMPLOT_USE_OPENGL"] = self.options.with_opengl
qt_tools_rootdir = self.conf.get("user.qt:tools_directory", self.dependencies["qt"].cpp_info.bindirs[0])
tc.cache_variables["CMAKE_AUTOMOC_EXECUTABLE"] = os.path.join(qt_tools_rootdir, "moc.exe" if self.settings_build.os == "Windows" else "moc")
tc.cache_variables["CMAKE_AUTORCC_EXECUTABLE"] = os.path.join(qt_tools_rootdir, "rcc.exe" if self.settings_build.os == "Windows" else "rcc")
tc.generate()
deps = CMakeDeps(self)
deps.generate()
Expand Down
20 changes: 9 additions & 11 deletions recipes/qcustomplot/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

add_executable(${PROJECT_NAME} test_package.cpp)

find_package(qcustomplot REQUIRED CONFIG)
find_package(Qt5 QUIET COMPONENTS Core Widgets)
find_package(Qt6 QUIET COMPONENTS Core Widgets)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE qcustomplot::qcustomplot)

if(QT_VERSION VERSION_GREATER_EQUAL "6.0.0")
find_package(Qt6 COMPONENTS Core Widgets REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
elseif(QT_VERSION VERSION_GREATER_EQUAL "5.0.0")
find_package(Qt5 COMPONENTS Core Widgets REQUIRED CONFIG)
if (Qt5_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Widgets)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
elseif(Qt6_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets)
else()
message(FATAL_ERROR "Qt < 5 not yet supported in this recipe")
message(FATAL_ERROR "Could not find Qt5 or Qt6. Please, check your Conan requirements.")
endif()
10 changes: 5 additions & 5 deletions recipes/qcustomplot/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
generators = "CMakeDeps"

def requirements(self):
self.requires(self.tested_reference_str)
self.requires("qt/[*]")

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["QT_VERSION"] = self.dependencies["qt"].ref.version
qcustomplot_ver = str(self.dependencies[self.tested_reference_str].ref.version.major)
tc.preprocessor_definitions["QCUSTOMPLOT_MAJOR_VERSION"] = qcustomplot_ver
tc.generate()

def build(self):
Expand All @@ -26,7 +27,6 @@ def build(self):
cmake.build()

def test(self):
# can't run in Linux agents (headless)
if can_run(self) and self.settings.os != "Linux":
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
35 changes: 15 additions & 20 deletions recipes/qcustomplot/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
#include <cstdlib>
#include <iostream>
#include <qcustomplot.h>

#include <QApplication>
#include <QMainWindow>
#include <QVector>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow window;
int main(void) {
#if QCUSTOMPLOT_MAJOR_VERSION > 1
QCPVector2D qcp_vector(2, 4);
#else
QCPRange qcp_vector(2, 4);
#endif

QCustomPlot customPlot;
window.setCentralWidget(&customPlot);
qcp_vector.normalize();

QVector<double> x(101), y(101);
for (int i = 0; i < 101; ++i) {
x[i] = i / 50.0 - 1;
y[i] = x[i] * x[i];
}
customPlot.addGraph();
customPlot.graph(0)->setData(x, y);
customPlot.xAxis->setLabel("x");
customPlot.yAxis->setLabel("y");
customPlot.rescaleAxes();
#if QCUSTOMPLOT_MAJOR_VERSION > 1
std::cout << "QCustomPlot - vector 2D length: " << qcp_vector.length() << std::endl;
#else
std::cout << "QCustomPlot - range size: " << qcp_vector.size() << std::endl;
#endif

window.setGeometry(100, 100, 500, 400);
return 0;
return EXIT_SUCCESS;
}
8 changes: 0 additions & 8 deletions recipes/qcustomplot/all/test_v1_package/CMakeLists.txt

This file was deleted.

20 changes: 0 additions & 20 deletions recipes/qcustomplot/all/test_v1_package/conanfile.py

This file was deleted.