-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
173 lines (139 loc) · 6.53 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from os import path
import posixpath
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import check_min_cppstd
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
from conan.tools.files import (
apply_conandata_patches, export_conandata_patches,
get, copy, rename, rm, rmdir
)
from conan.tools.scm import Version
from conan.tools.env import Environment
from conan.tools.env import VirtualRunEnv
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
required_conan_version = ">=1.53.0"
class PackageConan(ConanFile):
name = "fmilib"
description = "C library for importing FMUs"
license = "BSD-3-Clause"
url = "https://github.com/sintef-ocean/conan-fmilibrary"
homepage = "https://github.com/modelon-community/fmi-library"
topics = ("fmi", "fmi-standard", "fmu")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_fmus": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_fmus": False
}
def export_sources(self):
export_conandata_patches(self)
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.libcxx")
self.settings.rm_safe("compiler.cppstd")
def layout(self):
cmake_layout(self, src_folder="src")
def requirements(self):
self.requires("fmi1/1.0.1")
self.requires("fmi2/2.0.4")
if Version(self.version).major > 2:
self.requires("fmi3/3.0.1")
self.requires("expat/2.6.2")
self.requires("minizip/[>=1.2.11 <2]")
self.requires("zlib/[>=1.2.11 <2]")
# c99_snprintf -> should be externalised
def build_requirements(self):
if Version(self.version).major > 2 and self.options.with_fmus:
self.test_requires("catch2/2.13.10")
def validate(self):
# https://github.com/modelon-community/fmi-library/issues/93
if self.settings.arch not in ["x86", "x86_64"] and Version(self.version).major < 3:
raise ConanInvalidConfiguration(
f"{self.ref} does not support architecture "
f"'{self.settings.arch}' on {self.settings.os}")
if Version(self.version).major > 2 and self.options.with_fmus:
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["FMILIB_BUILD_STATIC_LIB"] = not self.options.shared
tc.variables["FMILIB_BUILD_SHARED_LIB"] = self.options.shared
tc.variables["FMILIB_BUILD_TESTS"] = self.options.with_fmus
tc.variables["FMILIB_FMI_STANDARD_HEADERS"] = posixpath.join(self.build_folder, "fmis").replace("\\", "/")
tc.variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False
tc.variables["FMILIB_FIND_PACKAGE_ZLIB"] = True
# The variable is an option only if the following condition is true
if not self.options.shared and not self.settings.os in ["Windows", "Macos"]:
tc.variables["FMILIB_BUILD_FOR_SHARED_LIBS"] = self.options.get_safe("fPIC", False)
if is_msvc(self):
tc.variables["FMILIB_BUILD_WITH_STATIC_RTLIB"] = is_msvc_static_runtime(self)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0026"] = "OLD"
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0045"] = "OLD"
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0046"] = "OLD"
tc.generate()
cd = CMakeDeps(self)
cd.generate()
vre = VirtualRunEnv(self)
vre.generate(scope="build")
def build(self):
apply_conandata_patches(self)
copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0],
path.join(self.build_folder, "fmis", "FMI1"))
copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0],
path.join(self.build_folder, "fmis", "FMI1"))
copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0],
path.join(self.build_folder, "fmis", "FMI1"))
copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0],
path.join(self.build_folder, "fmis", "FMI2"))
if Version(self.version).major > 2:
copy(self, "*.h", self.dependencies["fmi3"].cpp_info.includedirs[0],
path.join(self.build_folder, "fmis", "FMI3"))
cmake = CMake(self)
cmake.configure()
cmake.build()
if not self.conf.get("tools.build:skip_test", default=True) and self.options.with_fmus:
# Tests will now work without fmus
env = Environment()
env.define("CTEST_OUTPUT_ON_FAILURE", "ON")
with env.vars(self).apply():
cmake.test()
def package(self):
copy(self, pattern="LICENSE.md", dst=path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self, pattern="FMILIB_Acknowledgements.txt",
dst=path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self, pattern="*.fmu", dst=path.join(self.package_folder, "res", "fmus"),
src=path.join(self.build_folder, "Testing"), keep_path=False)
cmake = CMake(self)
cmake.install()
copy(self, pattern="*.dll", dst=path.join(self.package_folder, "bin"),
src=path.join(self.package_folder, "lib"), keep_path=False)
rm(self, "*.dll", path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)
rmdir(self, path.join(self.package_folder, "doc"))
def package_info(self):
if self.options.shared:
self.cpp_info.libs = ["fmilib_shared"]
else:
self.cpp_info.libs = ["fmilib"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("dl")
if self.settings.os in ["Windows"]:
self.cpp_info.system_libs.append("shlwapi")
self.cpp_info.resdirs = ["res"]
self.cpp_info.set_property("cmake_target_aliases", ["fmilibrary::fmilibrary"])