This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
conanfile.py
131 lines (112 loc) · 5.29 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake, tools
from glob import glob
import os
class openblasConan(ConanFile):
name = "openblas"
version = "0.3.5"
url = "https://github.com/xianyi/OpenBLAS"
homepage = "http://www.openblas.net/"
description = "OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version."
license = "BSD 3-Clause"
exports_sources = ["CMakeLists.txt", "LICENSE"]
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"USE_MASS": [True, False],
"USE_OPENMP": [True, False],
"NO_LAPACKE": [True, False],
"NOFORTRAN": [True, False]}
default_options = "shared=True", "USE_MASS=False", "USE_OPENMP=False", "NO_LAPACKE=False", "NOFORTRAN=True"
def _get_make_arch(self):
return "32" if self.settings.arch == "x86" else "64"
def _get_make_build_type_debug(self):
return "0" if self.settings.build_type == "Release" else "1"
@staticmethod
def _get_make_option_value(option):
return "1" if option else "0"
def build_requirements(self):
if self.settings.os == "Windows":
self.build_requires("strawberryperl/5.26.0@conan/stable")
def configure(self):
if self.settings.compiler == "Visual Studio":
if not self.options.shared:
raise Exception("Static build not supported in Visual Studio: "
"https://github.com/xianyi/OpenBLAS/blob/v0.3.5/CMakeLists.txt#L152")
if self.settings.os == "Windows":
if self.options.NOFORTRAN:
self.output.warn("NOFORTRAN option is disabled for Windows. Setting to false")
self.options.NOFORTRAN = False
def source(self):
self.output.info("source()")
source_url = "https://sourceforge.net/projects/openblas"
file_name = ("{0} {1} version".format("OpenBLAS", self.version))
tools.get("{0}/files/v{1}/{2}.tar.gz".format(source_url, self.version, file_name))
os.rename(glob("xianyi-OpenBLAS-*")[0], "sources")
@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"
def _configure_cmake(self):
self.output.warn("Building with CMake: Some options won't make any effect")
cmake = CMake(self)
cmake.definitions["USE_MASS"] = self.options.USE_MASS
cmake.definitions["USE_OPENMP"] = self.options.USE_OPENMP
cmake.definitions["NO_LAPACKE"] = self.options.NO_LAPACKE
cmake.definitions["NOFORTRAN"] = self.options.NOFORTRAN
cmake.configure(source_dir="sources")
return cmake
def _build_cmake(self):
cmake = self._configure_cmake()
cmake.build()
def _build_make(self, args=None):
make_options = ["DEBUG=%s" % self._get_make_build_type_debug(),
"NO_SHARED=%s" % self._get_make_option_value(not self.options.shared),
"BINARY=%s" % self._get_make_arch(),
"NO_LAPACKE=%s" % self._get_make_option_value(self.options.NO_LAPACKE),
"USE_MASS=%s" % self._get_make_option_value(self.options.USE_MASS),
"USE_OPENMP=%s" % self._get_make_option_value(self.options.USE_OPENMP),
"NOFORTRAN=%s" % self._get_make_option_value(self.options.NOFORTRAN)]
# https://github.com/xianyi/OpenBLAS/wiki/How-to-build-OpenBLAS-for-Android
target = {"armv6": "ARMV6",
"armv7": "ARMV7",
"armv7hf": "ARMV7",
"armv8": "ARMV8",
"sparc": "SPARC"}.get(str(self.settings.arch))
if tools.cross_building(self.settings):
if "CC_FOR_BUILD" in os.environ:
hostcc = os.environ["CC_FOR_BUILD"]
else:
hostcc = tools.which("cc") or tools.which("gcc") or tools.which("clang")
make_options.append("HOSTCC=%s" % hostcc)
if target:
make_options.append("TARGET=%s" % target)
if "CC" in os.environ:
make_options.append("CC=%s" % os.environ["CC"])
if "AR" in os.environ:
make_options.append("AR=%s" % os.environ["AR"])
if args:
make_options.extend(args)
self.run("cd sources && make %s" % ' '.join(make_options), cwd=self.source_folder)
def build(self):
if self._is_msvc:
self._build_cmake()
else:
self._build_make()
def package(self):
if not self._is_msvc:
self._build_make(args=['PREFIX=%s' % self.package_folder, 'install'])
else:
cmake = self._configure_cmake()
cmake.install()
with tools.chdir("sources"):
self.copy(pattern="LICENSE", dst="licenses", src="sources",
ignore_case=True, keep_path=False)
def package_info(self):
self.env_info.OpenBLAS_HOME = self.package_folder
self.cpp_info.libs = tools.collect_libs(self)
if self._is_msvc:
self.cpp_info.includedirs.append(os.path.join("include", "openblas"))
if self.settings.os == "Linux":
self.cpp_info.libs.append("pthread")
if not self.options.NOFORTRAN:
self.cpp_info.libs.append("gfortran")