From dda5095ae5aa5edade451fd4e847c821673ba256 Mon Sep 17 00:00:00 2001 From: toge Date: Thu, 26 Jan 2023 07:47:00 +0900 Subject: [PATCH] (#15260) kplot: add recipe * kplot: add recipe * drop support msvc --- recipes/kplot/all/CMakeLists.txt | 64 ++++++++++++++++ recipes/kplot/all/conandata.yml | 4 + recipes/kplot/all/conanfile.py | 73 +++++++++++++++++++ recipes/kplot/all/test_package/CMakeLists.txt | 8 ++ recipes/kplot/all/test_package/conanfile.py | 26 +++++++ recipes/kplot/all/test_package/test_package.c | 14 ++++ .../kplot/all/test_v1_package/CMakeLists.txt | 8 ++ .../kplot/all/test_v1_package/conanfile.py | 18 +++++ recipes/kplot/config.yml | 3 + 9 files changed, 218 insertions(+) create mode 100644 recipes/kplot/all/CMakeLists.txt create mode 100644 recipes/kplot/all/conandata.yml create mode 100644 recipes/kplot/all/conanfile.py create mode 100644 recipes/kplot/all/test_package/CMakeLists.txt create mode 100644 recipes/kplot/all/test_package/conanfile.py create mode 100644 recipes/kplot/all/test_package/test_package.c create mode 100644 recipes/kplot/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/kplot/all/test_v1_package/conanfile.py create mode 100644 recipes/kplot/config.yml diff --git a/recipes/kplot/all/CMakeLists.txt b/recipes/kplot/all/CMakeLists.txt new file mode 100644 index 00000000000000..632b160c486910 --- /dev/null +++ b/recipes/kplot/all/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 3.8) +project(kplot LANGUAGES C) + +find_package(cairo REQUIRED CONFIG) + +set(kplot_src + ${KPLOT_SRC_DIR}/colours.c + ${KPLOT_SRC_DIR}/array.c + ${KPLOT_SRC_DIR}/border.c + ${KPLOT_SRC_DIR}/bucket.c + ${KPLOT_SRC_DIR}/buffer.c + ${KPLOT_SRC_DIR}/draw.c + ${KPLOT_SRC_DIR}/grid.c + ${KPLOT_SRC_DIR}/hist.c + ${KPLOT_SRC_DIR}/label.c + ${KPLOT_SRC_DIR}/kdata.c + ${KPLOT_SRC_DIR}/kplot.c + ${KPLOT_SRC_DIR}/margin.c + ${KPLOT_SRC_DIR}/mean.c + ${KPLOT_SRC_DIR}/plotctx.c + ${KPLOT_SRC_DIR}/reallocarray.c + ${KPLOT_SRC_DIR}/stddev.c + ${KPLOT_SRC_DIR}/tic.c + ${KPLOT_SRC_DIR}/vector.c +) + +set(kplot_inc + ${KPLOT_SRC_DIR}/compat.h + ${KPLOT_SRC_DIR}/extern.h + ${KPLOT_SRC_DIR}/kplot.h +) + +include_directories(KPLOT_SRC_DIR) + +try_run(HAVE_reallocarray COMPIE_reallocarray ${CMAKE_BINARY_DIR} ${KPLOT_SRC_DIR}/test-reallocarray.c) + +file(READ "${KPLOT_SRC_DIR}/compat.pre.h" COMPAT_CONTENTS) +file(WRITE "${KPLOT_SRC_DIR}/compat.h" "${COMPAT_CONTENTS}") +if (${COMPIE_reallocarray} AND NOT ${HAVE_reallocarray}) + file(APPEND "${KPLOT_SRC_DIR}/compat.h" "#define HAVE_REALLOCARRAY") +endif() +file(READ "${KPLOT_SRC_DIR}/compat.post.h" COMPAT_CONTENTS) +file(APPEND "${KPLOT_SRC_DIR}/compat.h" "${COMPAT_CONTENTS}") + +add_library(kplot ${kplot_src}) + +target_compile_features(kplot PRIVATE c_std_99) +set_target_properties(kplot PROPERTIES + PUBLIC_HEADER "${kplot_inc}" + WINDOWS_EXPORT_ALL_SYMBOLS ON + C_EXTENSIONS OFF +) +target_compile_features(kplot PRIVATE c_std_99) +target_link_libraries(kplot PRIVATE cairo::cairo) + +include(GNUInstallDirs) + +install( + TARGETS kplot + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) diff --git a/recipes/kplot/all/conandata.yml b/recipes/kplot/all/conandata.yml new file mode 100644 index 00000000000000..d0e63f3ee2c144 --- /dev/null +++ b/recipes/kplot/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.1.15": + url: "https://github.com/kristapsdz/kplot/archive/refs/tags/VERSION_0_1_15.tar.gz" + sha256: "602ebaac9b67dc7c7e84d8112df887c95ba0a1c4ed71fbab6671f8c5ecf4ba2a" diff --git a/recipes/kplot/all/conanfile.py b/recipes/kplot/all/conanfile.py new file mode 100644 index 00000000000000..47e24a0f5cdf87 --- /dev/null +++ b/recipes/kplot/all/conanfile.py @@ -0,0 +1,73 @@ +from conan import ConanFile +from conan.tools.files import get, copy +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.microsoft import is_msvc +from conan.errors import ConanInvalidConfiguration +import os + +required_conan_version = ">=1.53.0" + +class KplotConan(ConanFile): + name = "kplot" + description = "open source Cairo plotting library" + license = "ISC" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/kristapsdz/kplot/" + topics = ("plot", "cairo", "chart") # no "conan" and project name in topics + settings = "os", "arch", "compiler", "build_type" # even for header only + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def export_sources(self): + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) + + 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") + # for plain C projects only + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") + + def validate(self): + if is_msvc(self): + raise ConanInvalidConfiguration(f"{self.ref} can not be built on Visual Studio and msvc.") + + def requirements(self): + self.requires("cairo/1.17.4") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["KPLOT_SRC_DIR"] = self.source_folder.replace("\\", "/") + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) + cmake.build() + + def package(self): + copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["kplot"] diff --git a/recipes/kplot/all/test_package/CMakeLists.txt b/recipes/kplot/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..e61521b15e2af8 --- /dev/null +++ b/recipes/kplot/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES C) + +find_package(kplot REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE kplot::kplot) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) diff --git a/recipes/kplot/all/test_package/conanfile.py b/recipes/kplot/all/test_package/conanfile.py new file mode 100644 index 00000000000000..a9fb96656f2039 --- /dev/null +++ b/recipes/kplot/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +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", "VirtualRunEnv" + test_type = "explicit" + + 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): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/kplot/all/test_package/test_package.c b/recipes/kplot/all/test_package/test_package.c new file mode 100644 index 00000000000000..2bc672875372a8 --- /dev/null +++ b/recipes/kplot/all/test_package/test_package.c @@ -0,0 +1,14 @@ +#include +#include + +#include "cairo.h" +#include "kplot.h" + +int main() { + struct kpair points1[50]; + struct kdata* d1 = kdata_array_alloc(points1, 50); + + kdata_destroy(d1); + + return 0; +} diff --git a/recipes/kplot/all/test_v1_package/CMakeLists.txt b/recipes/kplot/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..925ecbe19e448d --- /dev/null +++ b/recipes/kplot/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/kplot/all/test_v1_package/conanfile.py b/recipes/kplot/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..5a05af3c2dfd2f --- /dev/null +++ b/recipes/kplot/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +class TestPackageV1Conan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/kplot/config.yml b/recipes/kplot/config.yml new file mode 100644 index 00000000000000..d90a2c03c7832b --- /dev/null +++ b/recipes/kplot/config.yml @@ -0,0 +1,3 @@ +versions: + "0.1.15": + folder: all