-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
155 lines (133 loc) · 6.21 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from conans import ConanFile, CMake, tools
from conan.errors import ConanInvalidConfiguration
import os
class CaffeConan(ConanFile):
name = "caffe"
description = "Caffe: a fast open framework for deep learning"
topics = ("conan", "caffe", "deep-learning", "machine-learning")
url = "https://github.com/bincrafters/conan-caffe"
homepage = "http://caffe.berkeleyvision.org"
license = "BSD-2-Clause"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"fPIC": [True, False],
"with_gpu": [True, False],
"with_cudnn": [True, False],
"with_opencv": [True, False],
"with_leveldb": [True, False],
"with_lmdb": [True, False],
"gpu_arch": ["Fermi", "Kepler", "Maxwell", "Pascal", "All", "Manual"],
# following options are valid when gpu_arch=Manual
"gpu_arch_bin": "ANY",
"gpu_arch_ptx": "ANY"
}
default_options = {"shared": False,
"fPIC": True,
"with_gpu": False,
"with_cudnn": False,
"with_opencv": False,
"with_leveldb": False,
"with_lmdb": False,
# this default ensures build with modern CUDA that omit Fermi
"gpu_arch": "Kepler",
"gpu_arch_bin": "",
"gpu_arch_ptx": ""
}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
def configure(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("This library is not compatible with Windows")
if not self.options.with_gpu:
del self.options.gpu_arch
def requirements(self):
self.requires("boost/1.72.0")
self.requires("glog/0.4.0")
self.requires("gflags/2.2.2")
self.requires("hdf5/1.10.6")
# caffe supports those BLAS implementations: openblas, mkl, accelerate, atlas
# Choose Accelerate for MAC and openblas otherwise
if self.settings.os != "Macos":
self.requires("openblas/0.3.13")
self.requires("protobuf/3.9.1")
if self.options.with_opencv:
self.output.warn("OpenCV may require different protobuf than Caffe")
self.requires("opencv/4.5.2")
def build_requirements(self):
# waiting for an official protoc binary
self.build_requires("protobuf/3.9.1")
def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_python"] = False
cmake.definitions["BUILD_python_layer"] = False
cmake.definitions["BUILD_docs"] = False
cmake.definitions["CPU_ONLY"] = not self.options.with_gpu
cmake.definitions["USE_OPENCV"] = self.options.with_opencv
cmake.definitions["USE_LEVELDB"] = self.options.with_leveldb
cmake.definitions["USE_LMDB"] = self.options.with_lmdb
cmake.definitions["USE_CUDNN"] = self.options.with_cudnn
cmake.definitions["PROTOBUF_PROTOC_EXECUTABLE"] = os.path.join(self.deps_cpp_info['protobuf'].rootpath, 'bin', 'protoc')
if self.options.with_gpu:
cmake.definitions["CUDA_ARCH_NAME"] = self.options.gpu_arch
if self.options.gpu_arch == "Manual":
cmake.definitions["CUDA_ARCH_BIN"] = self.options.gpu_arch_bin
cmake.definitions["CUDA_ARCH_PTX"] = self.options.gpu_arch_ptx
cmake.definitions["CUDA_NVCC_FLAGS"] = '-std=c++11'
if self.settings.os == "Linux":
cmake.definitions["BLAS"] = "open"
cmake.configure(build_folder=self._build_subfolder)
return cmake
def _prepare(self):
# ensure that bundled cmake files are not used
for module in ['Glog', 'GFlags', 'OpenBLAS']:
os.unlink(os.path.join(self._source_subfolder, 'cmake', 'Modules', 'Find'+module+'.cmake'))
# drop autogenerated CMake files for protobuf because they prevent
# `cmake/ProtoBuf.cmake` to detect Protobuf using system FindProtobuf
for module in ['protobuf', 'protoc_installer']:
if os.path.exists('Find'+module+'.cmake'):
os.unlink('Find'+module+'.cmake')
# patch sources
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
def build(self):
self._prepare()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
# remove python bindings
tools.rmdir(os.path.join(self.package_folder, 'python'))
# remove cmake
tools.rmdir(os.path.join(self.package_folder, 'share'))
def package_info(self):
if self.settings.build_type == "Debug":
self.cpp_info.libs = ["caffe-d", "proto-d"]
else:
self.cpp_info.libs = ["caffe", "proto"]
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["m"]
# pass options from Caffe_DEFINITIONS
if not self.options.with_gpu:
self.cpp_info.defines.append("CPU_ONLY")
if self.options.with_opencv:
self.cpp_info.defines.append("USE_OPENCV")
if self.options.with_leveldb:
self.cpp_info.defines.append("USE_LEVELDB")
if self.options.with_lmdb:
self.cpp_info.defines.append("USE_LMDB")
if self.options.with_cudnn:
self.cpp_info.defines.append("USE_CUDNN")
if self.settings.os == "Macos":
# not for all cases but usually works
self.cpp_info.defines.append("USE_ACCELERATE")
# fix export names
self.cpp_info.names["cmake_find_package"] = "Caffe"
self.cpp_info.names["cmake_find_package_multi"] = "Caffe"