-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconanfile.py
158 lines (132 loc) · 5.83 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
156
157
158
from os import path
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.scm import Git, Version
from conan.tools.env import Environment
from conan.tools.files import copy, load, save, update_conandata
required_conan_version = ">=2.0.0"
class DdsFmuConan(ConanFile):
name = "dds-fmu"
author = "Joakim Haugen"
description = "DDS-FMU mediator"
license = "MPL-2.0"
url = "https://github.com/dnv-opensource/dds-fmu"
topics = ("Co-simulation", "FMU", "DDS", "OMG-DDS")
package_type = "shared-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"with_tools": [True, False],
"with_doc": [True, False]
}
default_options = {
"fPIC": True,
"with_tools": True,
"with_doc": False
}
@property
def _min_cppstd(self):
return 17
@property
def _compilers_minimum_version(self):
return {
"msvc": "14.1",
"gcc": "8.1",
"clang": "7",
"apple-clang": "10",
}
@property
def _with_tests(self):
return not self.conf.get("tools.build:skip_test", default=True)
def export(self):
git = Git(self, self.recipe_folder)
scm_url, scm_commit = git.get_url_and_commit()
update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})
def set_version(self):
self.version = \
load(self, path.join(self.recipe_folder, "version.txt").strip())
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("cppfmu/1.0.0@sintef/stable")
self.requires("fast-dds/2.11.2")
self.requires("stduuid/1.2.3")
self.requires("rapidxml/1.13")
self.requires("eprosima-xtypes/cci.20230615@sintef/stable")
if self.options.with_tools:
self.requires("kuba-zip/0.3.2")
self.requires("taywee-args/6.4.6")
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
def build_requirements(self):
self.tool_requires("cmake/[>=3.18.0 <4]")
self.tool_requires("fmu-build-helper/1.0.0@sintef/stable")
if self._with_tests:
self.tool_requires("fmu-compliance-checker/2.0.4@sintef/stable")
self.test_requires("gtest/1.13.0")
if self.options.with_doc:
self.tool_requires("doxygen/1.9.4")
if self.settings.os == "Windows":
self.tool_requires("strawberryperl/5.32.1.1")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["DDSFMU_WITH_TOOLS"] = self.options.with_tools
tc.variables["DDSFMU_WITH_DOC"] = self.options.with_doc
tc.generate()
deps = CMakeDeps(self)
deps.build_context_activated = ["fmu-build-helper"]
deps.build_context_build_modules = ["fmu-build-helper"]
if self._with_tests:
deps.build_context_activated.append("fmu-compliance-checker")
deps.build_context_build_modules.append("fmu-compliance-checker")
deps.generate()
deplist = []
for require, dep in self.dependencies.items():
if require.build or require.test:
continue
deplist.append((dep.ref.name, dep.license))
if dep.package_folder and path.exists(path.join(dep.package_folder, "licenses")):
copy(self, "*", path.join(dep.package_folder, "licenses"),
path.join(self.build_folder, "licenses", dep.ref.name), keep_path=True)
if dep.ref.name == "cppfmu" and len(dep.cpp_info.srcdirs) > 0:
copy(self, "fmi_functions.cpp", dep.cpp_info.srcdirs[0],
path.join(self.build_folder, dep.ref.name), keep_path=False)
license_txt = path.join(self.build_folder, "licenses", "licenses.txt")
save(self, license_txt,
"Licenses for `dds-fmu` and its dependencies are listed below.\n\n")
cols1 = 20
cols2 = 30
save(self, license_txt, f"| Library{' '*(cols1-7)}"
f"| License{' '*(cols2-7)}|\n|{'-'*(cols1+1)}|{'-'*(cols2+1)}|\n", append=True)
save(self, license_txt, f"| {self.name}{' '*(max(cols1-len(self.name),0))}|"
f" {self.license}{' '*(max(cols2-len(self.license),0))}|\n", append=True)
copy(self, "LICENSE", self.recipe_folder, path.join(self.build_folder, "licenses"))
for dep, lic in sorted(deplist):
len_lic_str = len(lic) if type(lic) is str else cols2-2
save(self, license_txt, f"| {dep}{' '*(max(cols1-len(dep),0))}|"
f" {lic}{' '*(max(cols2-len_lic_str,0))}|\n", append=True)
license_md = path.join(self.build_folder, "gen_md", "licenses.md")
save(self, license_md, f"# Licenses {{#sec_licenses}}\n{load(self, license_txt)}")
def build(self):
cmake = CMake(self)
cmake.configure()
if self.options.with_doc:
cmake.build(target="doc")
cmake.install(component="doc")
cmake.build()
if self._with_tests:
env = Environment()
env.define("CTEST_OUTPUT_ON_FAILURE", "ON")
with env.vars(self).apply():
cmake.test()