-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"7.7.0": | ||
url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz" | ||
sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
import re | ||
|
||
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, load, save | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class SuiteSparseConfigConan(ConanFile): | ||
name = "suitesparse-config" | ||
description = "Configuration for SuiteSparse libraries" | ||
license = "BSD-3-Clause" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://people.engr.tamu.edu/davis/suitesparse.html" | ||
topics = ("mathematics", "sparse-matrix", "linear-algebra") | ||
|
||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": 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): | ||
self.requires("openblas/0.3.26", transitive_headers=True, transitive_libs=True) | ||
self.requires("llvm-openmp/17.0.6", 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["SUITESPARSE_USE_OPENMP"] = True | ||
tc.variables["SUITESPARSE_USE_CUDA"] = False | ||
tc.variables["BLA_VENDOR"] = "OpenBLAS" | ||
tc.variables["SUITESPARSE_DEMOS"] = False | ||
tc.variables["SUITESPARSE_USE_STRICT"] = True # don't allow implicit dependencies | ||
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, "SuiteSparse_config")) | ||
cmake.build() | ||
|
||
def _copy_license(self): | ||
# Extract the license applicable to SuiteSparse_config from all licenses in SuiteSparse | ||
full_license_info = load(self, os.path.join(self.source_folder, "LICENSE.txt")) | ||
bsd3 = re.search(r"==> Example License <==\n\n(.+?)\n==> ParU License <==", full_license_info, re.DOTALL).group(1) | ||
save(self, os.path.join(self.package_folder, "licenses", "LICENSE.txt"), bsd3) | ||
|
||
def package(self): | ||
self._copy_license() | ||
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", "SuiteSparse_config") | ||
self.cpp_info.set_property("cmake_target_name", "SuiteSparse::SuiteSparseConfig") | ||
if not self.options.shared: | ||
self.cpp_info.set_property("cmake_target_aliases", ["SuiteSparse::SuiteSparseConfig_static"]) | ||
self.cpp_info.set_property("pkg_config_name", "SuiteSparse_config") | ||
|
||
self.cpp_info.libs = ["suitesparseconfig"] | ||
self.cpp_info.includedirs.append(os.path.join("include", "suitesparse")) | ||
|
||
if self.settings.os in ["Linux", "FreeBSD"]: | ||
self.cpp_info.system_libs.append("m") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES C) | ||
|
||
find_package(SuiteSparse_config REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE SuiteSparse::SuiteSparseConfig) | ||
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <SuiteSparse_config.h> | ||
|
||
int main() { | ||
void* x = SuiteSparse_config_malloc(10); | ||
SuiteSparse_config_free(x); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"7.7.0": | ||
folder: all |