-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconanfile.py
More file actions
113 lines (100 loc) · 4.17 KB
/
Copy pathconanfile.py
File metadata and controls
113 lines (100 loc) · 4.17 KB
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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy
import os
class TrxCppConan(ConanFile):
name = "trx-cpp"
version = "0.1.0"
package_type = "library"
license = "BSD-2-Clause"
url = "https://github.com/tractdata/trx-cpp"
homepage = "https://github.com/tractdata/trx-cpp"
description = "C++ library for reading and writing the TRX tractography format."
topics = ("tractography", "mmap", "neuroimaging")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_tests": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_tests": False,
}
generators = ("CMakeDeps",)
exports_sources = (
"CMakeLists.txt",
"src/*",
"include/*",
"third_party/*",
"cmake/*",
"tests/*",
)
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def requirements(self):
self.requires("libzip/1.10.1")
self.requires("eigen/3.4.0")
def build_requirements(self):
if self.options.with_tests:
# Only needed for building/running tests, not for consumers.
self.test_requires("gtest/1.14.0")
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_CXX_STANDARD"] = 17
tc.variables["CMAKE_CXX_STANDARD_REQUIRED"] = "ON"
tc.variables["CMAKE_CXX_EXTENSIONS"] = "OFF"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure(
variables={
"TRX_BUILD_TESTS": self.options.with_tests,
"TRX_BUILD_EXAMPLES": False,
}
)
cmake.build()
if self.options.with_tests:
cmake.ctest()
def package(self):
cmake = CMake(self)
cmake.install()
# Ensure libzip headers are available to consumers even when the
# libzip Conan package does not expose include dirs via CMakeDeps.
libzip_dep = self.dependencies.get("libzip")
if libzip_dep and libzip_dep.package_folder:
libzip_include = os.path.join(libzip_dep.package_folder, "include")
copy(self, "zip.h", src=libzip_include, dst=os.path.join(self.package_folder, "include"))
copy(self, "zipconf.h", src=libzip_include, dst=os.path.join(self.package_folder, "include"))
eigen_dep = self.dependencies.get("eigen")
if eigen_dep and eigen_dep.package_folder:
eigen_include = os.path.join(eigen_dep.package_folder, "include", "eigen3")
copy(self, "Eigen/*", src=eigen_include, dst=os.path.join(self.package_folder, "include"))
mio_include = os.path.join(self.source_folder, "third_party", "mio", "include")
copy(self, "mio/*", src=mio_include, dst=os.path.join(self.package_folder, "include"))
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "trx-cpp")
self.cpp_info.set_property("cmake_target_name", "trx-cpp::trx")
self.cpp_info.set_property("pkg_config_name", "trx-cpp")
self.cpp_info.components["trx"].set_property("cmake_target_name", "trx-cpp::trx")
self.cpp_info.components["trx"].set_property("pkg_config_name", "trx-cpp")
self.cpp_info.components["trx"].libs = ["trx"]
self.cpp_info.components["trx"].requires = [
"libzip::libzip",
"eigen::Eigen3::Eigen",
]
extra_includes = []
for dep_name in ("eigen",):
dep = self.dependencies.get(dep_name)
if dep and dep.package_folder:
dep_include = os.path.join(dep.package_folder, "include")
if os.path.isdir(dep_include):
extra_includes.append(dep_include)
if extra_includes:
self.cpp_info.components["trx"].includedirs.extend(extra_includes)
if not self.options.shared and self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs.append("pthread")