From 34556192b42a9b222073c829db0e0dd57a5d874d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 15 Apr 2024 11:10:57 +0300 Subject: [PATCH] suitesparse-klu: new recipe --- recipes/suitesparse-klu/all/conandata.yml | 4 + recipes/suitesparse-klu/all/conanfile.py | 122 ++++++++++++++++++ .../all/test_package/CMakeLists.txt | 8 ++ .../all/test_package/conanfile.py | 26 ++++ .../all/test_package/test_package.c | 39 ++++++ recipes/suitesparse-klu/config.yml | 3 + 6 files changed, 202 insertions(+) create mode 100644 recipes/suitesparse-klu/all/conandata.yml create mode 100644 recipes/suitesparse-klu/all/conanfile.py create mode 100644 recipes/suitesparse-klu/all/test_package/CMakeLists.txt create mode 100644 recipes/suitesparse-klu/all/test_package/conanfile.py create mode 100644 recipes/suitesparse-klu/all/test_package/test_package.c create mode 100644 recipes/suitesparse-klu/config.yml diff --git a/recipes/suitesparse-klu/all/conandata.yml b/recipes/suitesparse-klu/all/conandata.yml new file mode 100644 index 0000000000000..de4cef693faff --- /dev/null +++ b/recipes/suitesparse-klu/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.3.3": + url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz" + sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3" diff --git a/recipes/suitesparse-klu/all/conanfile.py b/recipes/suitesparse-klu/all/conanfile.py new file mode 100644 index 0000000000000..f61beab1d370b --- /dev/null +++ b/recipes/suitesparse-klu/all/conanfile.py @@ -0,0 +1,122 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import get, rm, rmdir, copy + +required_conan_version = ">=1.53.0" + + +class SuiteSparseKluConan(ConanFile): + name = "suitesparse-klu" + description = "KLU: Routines for solving sparse linear systems of equations in SuiteSparse" + license = "LGPL-2.1-or-later" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://people.engr.tamu.edu/davis/suitesparse.html" + topics = ("mathematics", "sparse-matrix", "linear-algebra", "linear-systems-solver") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_cholmod": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_cholmod": True, + } + + 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.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + # OpenBLAS and OpenMP are provided via suitesparse-config + self.requires("suitesparse-config/7.7.0", transitive_headers=True, transitive_libs=True) + self.requires("suitesparse-amd/3.3.2", transitive_headers=True, transitive_libs=True) + self.requires("suitesparse-btf/2.3.2", transitive_headers=True, transitive_libs=True) + self.requires("suitesparse-colamd/3.3.3", transitive_headers=True, transitive_libs=True) + if self.options.with_cholmod: + self.requires("suitesparse-cholmod/5.2.1", transitive_headers=True, transitive_libs=True) + + def build_requirements(self): + self.tool_requires("cmake/[>=3.22 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + venv = VirtualBuildEnv(self) + venv.generate() + + tc = CMakeToolchain(self) + tc.variables["BUILD_SHARED_LIBS"] = self.options.shared + tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared + tc.variables["KLU_USE_CHOLMOD"] = self.options.with_cholmod + tc.variables["SUITESPARSE_USE_OPENMP"] = True + tc.variables["SUITESPARSE_USE_CUDA"] = False + tc.variables["SUITESPARSE_DEMOS"] = False + tc.variables["SUITESPARSE_USE_FORTRAN"] = False # Fortran sources are translated to C instead + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, "KLU")) + cmake.build() + + def package(self): + copy(self, "License.txt", os.path.join(self.source_folder, "KLU", "Doc"), os.path.join(self.package_folder, "licenses")) + copy(self, "lesser.txt", os.path.join(self.source_folder, "KLU", "Doc"), os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.pdb", self.package_folder, recursive=True) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "KLU") + + self.cpp_info.components["KLU"].libs = ["klu"] + self.cpp_info.components["KLU"].set_property("cmake_target_name", "SuiteSparse::KLU") + if not self.options.shared: + self.cpp_info.components["KLU"].set_property("cmake_target_aliases", ["SuiteSparse::KLU_static"]) + self.cpp_info.components["KLU"].set_property("pkg_config_name", "KLU") + self.cpp_info.components["KLU"].includedirs.append(os.path.join("include", "suitesparse")) + self.cpp_info.components["KLU"].requires = [ + "suitesparse-config::suitesparse-config", + "suitesparse-amd::suitesparse-amd", + "suitesparse-btf::suitesparse-btf", + "suitesparse-colamd::suitesparse-colamd", + ] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["KLU"].system_libs.append("m") + + if self.options.with_cholmod: + self.cpp_info.components["KLU_CHOLMOD"].libs = ["klu_cholmod"] + self.cpp_info.components["KLU_CHOLMOD"].set_property("cmake_target_name", "SuiteSparse::KLU_CHOLMOD") + if not self.options.shared: + self.cpp_info.components["KLU"].set_property("cmake_target_aliases", ["SuiteSparse::KLU_CHOLMOD_static"]) + self.cpp_info.components["KLU_CHOLMOD"].set_property("pkg_config_name", "KLU_CHOLMOD") + self.cpp_info.components["KLU_CHOLMOD"].includedirs.append(os.path.join("include", "suitesparse")) + self.cpp_info.components["KLU_CHOLMOD"].requires = [ + "KLU", + "suitesparse-cholmod::suitesparse-cholmod", + ] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["KLU_CHOLMOD"].system_libs.append("m") diff --git a/recipes/suitesparse-klu/all/test_package/CMakeLists.txt b/recipes/suitesparse-klu/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..91c223a550d56 --- /dev/null +++ b/recipes/suitesparse-klu/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(KLU REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE SuiteSparse::KLU) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_11) diff --git a/recipes/suitesparse-klu/all/test_package/conanfile.py b/recipes/suitesparse-klu/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/suitesparse-klu/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.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/suitesparse-klu/all/test_package/test_package.c b/recipes/suitesparse-klu/all/test_package/test_package.c new file mode 100644 index 0000000000000..7f3bbae5cfcfb --- /dev/null +++ b/recipes/suitesparse-klu/all/test_package/test_package.c @@ -0,0 +1,39 @@ +// https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/v7.7.0/KLU/Demo/klu_simple.c + +//------------------------------------------------------------------------------ +// KLU/Demo/klu_simple: simple demo program for KLU +//------------------------------------------------------------------------------ + +// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved. +// Authors: Timothy A. Davis and Ekanathan Palamadai. +// SPDX-License-Identifier: LGPL-2.1+ + +//------------------------------------------------------------------------------ + +/* klu_simple: a simple KLU demo; solution is x = (1,2,3,4,5) */ + +#include + +#include + +int n = 5 ; +int Ap [ ] = {0, 2, 5, 9, 10, 12} ; +int Ai [ ] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4} ; +double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ; +double b [ ] = {8., 45., -3., 3., 19.} ; + +int main (void) +{ + klu_symbolic *Symbolic ; + klu_numeric *Numeric ; + klu_common Common ; + int i ; + klu_defaults (&Common) ; + Symbolic = klu_analyze (n, Ap, Ai, &Common) ; + Numeric = klu_factor (Ap, Ai, Ax, Symbolic, &Common) ; + klu_solve (Symbolic, Numeric, 5, 1, b, &Common) ; + klu_free_symbolic (&Symbolic, &Common) ; + klu_free_numeric (&Numeric, &Common) ; + for (i = 0 ; i < n ; i++) printf ("x [%d] = %g\n", i, b [i]) ; + return (0) ; +} diff --git a/recipes/suitesparse-klu/config.yml b/recipes/suitesparse-klu/config.yml new file mode 100644 index 0000000000000..2f70bfab6adbf --- /dev/null +++ b/recipes/suitesparse-klu/config.yml @@ -0,0 +1,3 @@ +versions: + "2.3.3": + folder: all