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

Update qcustomplot recipe to be compatible with Conan 2 #23645

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions recipes/qcustomplot/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ sources:
"2.1.0":
url: "https://www.qcustomplot.com/release/2.1.0fixed/QCustomPlot-source.tar.gz"
sha256: "357b78be0f52b2d01c17ec3e2e1271255761810af7e8a9476cef51fccf1a0f44"
"1.3.2":
url: "https://www.qcustomplot.com/release/1.3.2/QCustomPlot.tar.gz"
sha256: "ea2ed5712c2020b25f40eacabd0926ef71a7f07e2a3771c32d53ace1f47123eb"
patches:
"2.1.0":
- patch_file: "patches/0001-fix-for-qt6.2.patch"
patch_description: "Fix needed to compile with Qt 6.2"
patch_type: "bugfix"
patch_source: "https://www.qcustomplot.com/index.php/support/forum/2380"
28 changes: 16 additions & 12 deletions recipes/qcustomplot/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualRunEnv
from conan.tools.files import apply_conandata_patches, copy, get, export_conandata_patches, replace_in_file
from conan.tools.scm import Version
import os
Expand All @@ -11,6 +12,7 @@

class QCustomPlotConan(ConanFile):
name = "qcustomplot"
package_type = "library"
description = "QCustomPlot is a Qt C++ widget for plotting and data visualization."
license = "GPL-3.0-only"
topics = ("chart", "data-visualization", "graph", "plot", "qt")
Expand Down Expand Up @@ -39,19 +41,19 @@ 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 requirements(self):
if Version(self.version) >= "2.0.0":
self.requires("qt/6.4.1")
else:
self.requires("qt/5.15.7")
self.requires("qt/6.4.2", transitive_headers=True, transitive_libs=True)

if self.options.with_opengl and self.settings.os == "Windows":
self.requires("opengl/system")

def build_requirements(self):
self.tool_requires("qt/6.4.2")
anton-danielsson marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if self.settings.os == "Macos":
raise ConanInvalidConfiguration(f"{self.ref} Macos not supported at this moment")
Comment on lines +54 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check this on Monday, maybe we can help keep macos support seeing the error the bot reported :)

Copy link
Contributor

@ericLemanissier ericLemanissier Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is actually in qt recipe, which does not properly define frameworks needed by qtgui. It could be solved by my other qt PR #23571, so let's wait for it to be merged before retrying this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates on the #23571 PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some help on how to proceed with this after #23571 was abandoned.

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)
Expand All @@ -68,6 +70,8 @@ def source(self):
destination=self.source_folder, strip_root=True)

def generate(self):
VirtualRunEnv(self).generate(scope="build")

tc = CMakeToolchain(self)
tc.variables["QCUSTOMPLOT_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.variables["QCUSTOMPLOT_VERSION"] = self.version
Expand All @@ -80,11 +84,10 @@ def generate(self):

def _patch_sources(self):
apply_conandata_patches(self)
if Version(self.version) >= "2.0.0":
# allow static qcustomplot with shared qt, and vice versa
replace_in_file(self, os.path.join(self.source_folder, "qcustomplot.h"),
"#if defined(QT_STATIC_BUILD)",
"#if 0" if self.options.shared else "#if 1")
# allow static qcustomplot with shared qt, and vice versa
replace_in_file(self, os.path.join(self.source_folder, "qcustomplot.h"),
"#if defined(QT_STATIC_BUILD)",
"#if 0" if self.options.shared else "#if 1")

def build(self):
self._patch_sources()
Expand All @@ -105,5 +108,6 @@ def package_info(self):
self.cpp_info.defines.append("QCUSTOMPLOT_USE_LIBRARY")
if self.options.with_opengl:
self.cpp_info.defines.append("QCUSTOMPLOT_USE_OPENGL")
self.cpp_info.requires.append("qt::qtOpenGL")
if self.settings.os == "Windows":
self.cpp_info.requires.append("opengl::opengl")
6 changes: 3 additions & 3 deletions recipes/qcustomplot/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ project(test_package LANGUAGES CXX)
add_executable(${PROJECT_NAME} test_package.cpp)

find_package(qcustomplot REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE qcustomplot::qcustomplot)
target_link_libraries(${PROJECT_NAME} PUBLIC 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_link_libraries(${PROJECT_NAME} PUBLIC 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)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} PUBLIC Qt5::Core Qt5::Widgets)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
else()
message(FATAL_ERROR "Qt < 5 not yet supported in this recipe")
Expand Down
3 changes: 1 addition & 2 deletions recipes/qcustomplot/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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")
16 changes: 7 additions & 9 deletions recipes/qcustomplot/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#include <qcustomplot.h>

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

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow window;

void dummy()
{
QCustomPlot customPlot;
window.setCentralWidget(&customPlot);

QVector<double> x(101), y(101);
for (int i = 0; i < 101; ++i) {
for (int i = 0; i < 101; ++i)
{
x[i] = i / 50.0 - 1;
y[i] = x[i] * x[i];
}
Expand All @@ -21,7 +17,9 @@ int main(int argc, char *argv[]) {
customPlot.xAxis->setLabel("x");
customPlot.yAxis->setLabel("y");
customPlot.rescaleAxes();
}

window.setGeometry(100, 100, 500, 400);
int main(int argc, char *argv[])
{
return 0;
}
2 changes: 0 additions & 2 deletions recipes/qcustomplot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ versions:
folder: all
"2.1.0":
folder: all
"1.3.2":
folder: all
Loading