|
2 | 2 | # pylint: skip-file
|
3 | 3 |
|
4 | 4 | import os
|
5 |
| -import shutil |
6 | 5 |
|
7 |
| -from conans import CMake, ConanFile, tools |
| 6 | +from conan import ConanFile |
| 7 | +from conan.errors import ConanInvalidConfiguration |
| 8 | +from conan.tools import build, cmake, files |
| 9 | + |
| 10 | +required_conan_version = ">=1.60.0 <2.0 || >=2.0.5" |
8 | 11 |
|
9 | 12 |
|
10 | 13 | class OpenSimulationInterfaceConan(ConanFile):
|
11 | 14 | name = "open-simulation-interface"
|
12 | 15 | version = "3.0.1"
|
13 |
| - license = "Mozilla Public License 2.0" |
14 |
| - url = "https://github.com/OpenSimulationInterface/open-simulation-interface" |
15 |
| - description = "A generic interface for the environmental perception of automated driving functions in virtual scenarios." |
16 |
| - topics = ("Sensor Simulation", "HAD") |
17 |
| - settings = "os", "compiler", "build_type", "arch" |
| 16 | + description = "Generic interface environmental perception of automated driving functions in virtual scenarios" |
| 17 | + license = "MPL-2.0" |
| 18 | + url = "https://github.com/conan-io/conan-center-index" |
| 19 | + homepage = "https://github.com/OpenSimulationInterface/open-simulation-interface" |
| 20 | + topics = ("asam", "adas", "open-simulation", "automated-driving", "openx") |
| 21 | + package_type = "library" |
| 22 | + generators = "CMakeDeps", "CMakeToolchain" |
| 23 | + settings = "os", "arch", "compiler", "build_type" |
18 | 24 | options = {
|
19 | 25 | "shared": [True, False],
|
20 | 26 | "fPIC": [True, False],
|
21 | 27 | }
|
22 | 28 | default_options = {
|
23 |
| - "shared": True, |
| 29 | + "shared": False, |
24 | 30 | "fPIC": True,
|
25 | 31 | }
|
26 |
| - generators = "cmake" |
27 |
| - build_policy = "missing" |
28 |
| - no_copy_source = False |
29 |
| - exports_sources = [ |
30 |
| - "CMakeLists.txt", |
31 |
| - ] |
32 |
| - requires = [ |
33 |
| - "protobuf/2.6.1@cloe/stable" |
34 |
| - ] |
35 |
| - |
36 |
| - _git_url = ( |
37 |
| - "https://github.com/OpenSimulationInterface/open-simulation-interface.git" |
38 |
| - ) |
39 |
| - _git_dir = "osi" |
40 |
| - _git_ref = f"v{version}" |
41 |
| - |
42 |
| - _cmake = None |
| 32 | + |
| 33 | + def export_sources(self): |
| 34 | + files.export_conandata_patches(self) |
| 35 | + |
| 36 | + def config_options(self): |
| 37 | + if self.settings.os == "Windows": |
| 38 | + del self.options.fPIC |
| 39 | + |
| 40 | + def configure(self): |
| 41 | + if self.options.shared: |
| 42 | + self.options.rm_safe("fPIC") |
| 43 | + |
| 44 | + def layout(self): |
| 45 | + cmake.cmake_layout(self) |
| 46 | + |
| 47 | + def requirements(self): |
| 48 | + self.requires("protobuf/2.6.1@cloe/stable", transitive_headers=True, transitive_libs=True) |
| 49 | + |
| 50 | + def validate(self): |
| 51 | + if self.settings.compiler.get_safe("cppstd"): |
| 52 | + build.check_min_cppstd(self, 11) |
| 53 | + if self.options.shared and self.settings.os == "Windows": |
| 54 | + raise ConanInvalidConfiguration( |
| 55 | + "Shared Libraries are not supported on windows because of the missing symbol export in the library." |
| 56 | + ) |
| 57 | + |
| 58 | + def build_requirements(self): |
| 59 | + self.tool_requires("protobuf/<host_version>") |
43 | 60 |
|
44 | 61 | def source(self):
|
45 |
| - git = tools.Git(folder=self._git_dir) |
46 |
| - git.clone(self._git_url, self._git_ref, shallow=True) |
47 |
| - dst = os.path.join(self.source_folder, self._git_dir) |
48 |
| - shutil.copy("CMakeLists.txt", dst) |
49 |
| - |
50 |
| - def _configure_cmake(self): |
51 |
| - if self._cmake: |
52 |
| - return self._cmake |
53 |
| - self._cmake = CMake(self) |
54 |
| - self._cmake.definitions["CMAKE_PROJECT_VERSION"] = self.version |
55 |
| - self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True |
56 |
| - self._cmake.configure(source_folder=self._git_dir) |
57 |
| - return self._cmake |
| 62 | + files.get(self, **self.conan_data["sources"][self.version], strip_root=True) |
58 | 63 |
|
59 | 64 | def build(self):
|
60 |
| - cmake = self._configure_cmake() |
61 |
| - cmake.build() |
| 65 | + files.apply_conandata_patches(self) |
| 66 | + cm = cmake.CMake(self) |
| 67 | + if self.should_configure: |
| 68 | + cm.configure() |
| 69 | + if self.should_build: |
| 70 | + cm.build() |
62 | 71 |
|
63 | 72 | def package(self):
|
64 |
| - cmake = self._configure_cmake() |
65 |
| - cmake.install() |
| 73 | + if not self.should_install: |
| 74 | + return |
| 75 | + cm = cmake.CMake(self) |
| 76 | + cm.install() |
| 77 | + files.copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) |
| 78 | + if self.settings.os == "Windows": |
| 79 | + files.rmdir(self, os.path.join(self.package_folder, "CMake")) |
| 80 | + else: |
| 81 | + files.rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) |
66 | 82 |
|
67 | 83 | def package_info(self):
|
68 |
| - self.cpp_info.libs = tools.collect_libs(self) |
| 84 | + self.cpp_info.set_property("cmake_file_name", "open_simulation_interface") |
| 85 | + self.cpp_info.set_property("cmake_target_name", "open_simulation_interface::open_simulation_interface") |
| 86 | + self.cpp_info.components["libopen_simulation_interface"].libs = ["open_simulation_interface"] |
| 87 | + self.cpp_info.components["libopen_simulation_interface"].requires = ["protobuf::libprotobuf"] |
| 88 | + |
| 89 | + # TODO: to remove in conan v2 once cmake_find_package_* generators removed |
| 90 | + self.cpp_info.names["cmake_find_package"] = "open_simulation_interface" |
| 91 | + self.cpp_info.names["cmake_find_package_multi"] = "open_simulation_interface" |
| 92 | + self.cpp_info.components["libopen_simulation_interface"].names["cmake_find_package"] = "open_simulation_interface" |
| 93 | + self.cpp_info.components["libopen_simulation_interface"].names["cmake_find_package_multi"] = "open_simulation_interface" |
0 commit comments