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

matplotplusplus: new recipe #22257

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions recipes/matplotplusplus/all/conan_deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Replace vendored libraries with Conan versions
find_package(CImg REQUIRED CONFIG)
find_package(nodesoup REQUIRED CONFIG)
4 changes: 4 additions & 0 deletions recipes/matplotplusplus/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.2.0":
url: "https://github.com/alandefreitas/matplotplusplus/archive/refs/tags/v1.2.0.tar.gz"
sha256: "42e24edf717741fcc721242aaa1fdb44e510fbdce4032cdb101c2258761b2554"
124 changes: 124 additions & 0 deletions recipes/matplotplusplus/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import os

from conan import ConanFile
from conan.tools.build import check_min_cppstd, check_max_cppstd
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout, CMake
from conan.tools.files import copy, get, rmdir, rm, save, replace_in_file
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class MatplotplusplusCppConan(ConanFile):
name = "matplotplusplus"
description = "Matplot++: A C++ Graphics Library for Data Visualization"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/alandefreitas/matplotplusplus"
topics = ("visualization", "charts", "data-science", "charting-library", "plots", "graphics", "graphs",
"data-visualization", "scientific-visualization", "scientific-computing", "data-analysis",
"graphics-library", "matplot", "plot-categories", "contour-plots", "polar-plots")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def export_sources(self):
copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

self.options["cimg"].enable_curl = False
self.options["cimg"].enable_display = False
self.options["cimg"].enable_ffmpeg = False
self.options["cimg"].enable_fftw = False
self.options["cimg"].enable_heif = True
self.options["cimg"].enable_jpeg = "libjpeg"
self.options["cimg"].enable_magick = False
self.options["cimg"].enable_opencv = False
self.options["cimg"].enable_openexr = False
self.options["cimg"].enable_openmp = True
self.options["cimg"].enable_png = True
self.options["cimg"].enable_tiff = True
self.options["cimg"].enable_tinyexr = False
self.options["cimg"].enable_zlib = False

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("cimg/3.3.5")
self.requires("nodesoup/cci.20200905")
self.requires("opengl/system")
self.requires("glfw/3.4")
self.requires("glad/0.1.36")
# Matplot++ also requires gnuplot to run, which is not available on CCI

def validate(self):
check_min_cppstd(self, 17)
# u8 string literals break in C++20 as of v1.2.0
check_max_cppstd(self, 17)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_PROJECT_Matplot++_INCLUDE"] = "conan_deps.cmake"
tc.variables["MATPLOTPP_BUILD_EXAMPLES"] = False
tc.variables["MATPLOTPP_BUILD_TESTS"] = False
tc.variables["MATPLOTPP_BUILD_INSTALLER"] = True
tc.variables["MATPLOTPP_BUILD_PACKAGE"] = False
tc.variables["MATPLOTPP_BUILD_WITH_SANITIZERS"] = False
tc.variables["MATPLOTPP_BUILD_WITH_PEDANTIC_WARNINGS"] = False
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()
deps = CMakeDeps(self)
deps.set_property("cimg", "cmake_target_name", "cimg")
deps.set_property("nodesoup", "cmake_target_name", "nodesoup")
deps.set_property("glad", "cmake_file_name", "GLAD")
deps.generate()

def _patch_sources(self):
rmdir(self, os.path.join(self.source_folder, "source", "3rd_party"))
save(self, os.path.join(self.source_folder, "source", "3rd_party", "CMakeLists.txt"), "")
if Version(self.version) <= "1.2.0":
replace_in_file(self, os.path.join(self.source_folder, "source", "matplot", "CMakeLists.txt"),
"find_package(GLAD QUIET)", "find_package(GLAD REQUIRED CONFIG)")
else:
replace_in_file(self, os.path.join(self.source_folder, "source", "matplot", "CMakeLists.txt"),
"find_package(glad CONFIG)", "find_package(GLAD REQUIRED CONFIG)")
def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Matplot++")
self.cpp_info.set_property("cmake_target_name", "Matplot++::matplot++")

self.cpp_info.libs = ["matplot"]
if self.settings.os == "Windows":
self.cpp_info.defines.append("NOMINMAX")
8 changes: 8 additions & 0 deletions recipes/matplotplusplus/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(Matplot++ REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Matplot++::matplot++)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
30 changes: 30 additions & 0 deletions recipes/matplotplusplus/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import shutil

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
if not shutil.which("gnuplot"):
self.output.warn("gnuplot not found. Skipping test_package.")
return
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
20 changes: 20 additions & 0 deletions recipes/matplotplusplus/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://github.com/alandefreitas/matplotplusplus/blob/master/examples/surfaces/mesh/mesh_1.cpp

#include <cmath>
#include <matplot/matplot.h>

int main() {
using namespace matplot;
auto fig = figure(true);

auto [X, Y] = meshgrid(iota(-8, .5, +8));
auto Z = transform(X, Y, [](double x, double y) {
double eps = std::nextafter(0.0, 1.0);
double R = sqrt(pow(x, 2) + pow(y, 2)) + eps;
return sin(R) / R;
});
mesh(X, Y, Z);

fig->save("test.png");
return 0;
}
3 changes: 3 additions & 0 deletions recipes/matplotplusplus/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.2.0":
folder: all