Skip to content

Commit 726fbf6

Browse files
committed
vtd: Migrate osi-sensor package to Conan 2.0 compatibility
1 parent 090ff6d commit 726fbf6

File tree

10 files changed

+278
-111
lines changed

10 files changed

+278
-111
lines changed

optional/vtd/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ UNSELECT_VENDOR := ${WITHOUT_VENDOR}
1717
WITH_VENDOR :=
1818
SELECT_VENDOR := $(call uniq, $(filter-out ${UNSELECT_VENDOR}, ${ALL_VENDOR}) ${WITH_VENDOR})
1919

20-
vendor/osi-sensor-1.0.0-vtd2.2: vendor/vtd-2.2.0 vendor/open-simulation-interface-3.0.1
20+
vendor/osi-sensor-1.0.0: vendor/vtd-2.2.0 vendor/open-simulation-interface-3.0.1
2121
vendor/open-simulation-interface-3.0.1: vendor/protobuf-2.6.1
2222
vendor/open-simulation-interface-3.2.0: vendor/protobuf-2.6.1
2323

optional/vtd/tests/conanfile_with_vtd-2.2.0.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def requirements(self):
4343
self.requires("incbin/cci.20211107", override=True)
4444

4545
# Runtime requirements for VTD.
46-
self.requires("osi-sensor/1.0.0-vtd2.2@cloe/stable")
46+
self.requires("osi-sensor/1.0.0@cloe/stable")
4747
self.requires("vtd/2.2.0@cloe-restricted/stable")
4848

4949
# Overrides:

optional/vtd/vendor/osi-sensor-1.0.0-vtd2.2/conanfile.py

-94
This file was deleted.

optional/vtd/vendor/osi-sensor-1.0.0-vtd2.2/CMakeLists.txt renamed to optional/vtd/vendor/osi-sensor-1.0.0/CMakeLists.txt

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
cmake_minimum_required(VERSION 3.7)
1+
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
22

3-
project(OSMPDummySensor
4-
LANGUAGES CXX
5-
)
3+
project(OSMPDummySensor LANGUAGES CXX)
64

7-
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
8-
conan_basic_setup(TARGETS NO_OUTPUT_DIRS)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
96

10-
# Compiler definitions
11-
string(TIMESTAMP FMUTIMESTAMP UTC)
12-
string(MD5 FMUGUID modelDescription.in.xml)
13-
configure_file(modelDescription.in.xml modelDescription.xml @ONLY)
7+
# Input Variables
8+
set(VTD_ROOT "" CACHE STRING "Path to VTD root directory")
9+
10+
# Dependencies
11+
find_package(open_simulation_interface REQUIRED)
12+
find_package(protobuf CONFIG REQUIRED)
1413
find_library(VTD_OSI_LIBRARY NAME libopen_simulation_interface.so
15-
PATHS "${CONAN_VTD_ROOT}/Data/Setups/Standard.OSI3/Bin/"
14+
PATHS "${VTD_ROOT}/Data/Setups/Standard.OSI3/Bin/"
1615
NO_DEFAULT_PATH
1716
)
1817
if(NOT VTD_OSI_LIBRARY)
19-
message(WARNING "VTD OSI library not found. Using Conan package..")
20-
set(VTD_OSI_LIBRARY CONAN_PKG::open-simulation-interface)
18+
message(WARNING "VTD OSI library not found. Using external package.")
19+
set(VTD_OSI_LIBRARY open_simulation_interface::libopen_simulation_interface)
2120
endif()
21+
22+
# Configuration
23+
string(TIMESTAMP FMUTIMESTAMP UTC)
24+
string(MD5 FMUGUID modelDescription.in.xml)
25+
configure_file(modelDescription.in.xml modelDescription.xml @ONLY)
26+
2227
# Library ------------------------------------------------------------
2328
add_library(${PROJECT_NAME} SHARED
2429
OSMPDummySensor.cpp
@@ -28,14 +33,17 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
2833
CXX_STANDARD_REQUIRED ON
2934
PREFIX ""
3035
)
36+
message(STATUS "protobuf_FOUND: ${protobuf_FOUND}")
37+
message(STATUS "protobuf_INCLUDE_DIRS: ${protobuf_INCLUDE_DIRS}")
3138
target_include_directories(${PROJECT_NAME}
3239
PUBLIC
3340
../includes
34-
$<BUILD_INTERFACE:${CONAN_INCLUDE_DIRS_PROTOBUF}>
35-
$<BUILD_INTERFACE:${CONAN_INCLUDE_DIRS_OPEN-SIMULATION-INTERFACE}>
41+
${open_simulation_interface_INCLUDE_DIRS}
42+
${protobuf_INCLUDE_DIR}
3643
)
3744
target_link_libraries(${PROJECT_NAME}
3845
PUBLIC
46+
protobuf::libprotobuf
3947
${VTD_OSI_LIBRARY}
4048
)
4149
target_compile_definitions(${PROJECT_NAME}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
sources:
3+
"1.0.0":
4+
url: "https://github.com/OpenSimulationInterface/osi-sensor-model-packaging/archive/refs/tags/v1.0.0.tar.gz"
5+
sha256: "6c9617608e815419f5c9b7b3359a0573082e7068dfcfc0f42c059c8094265fd6"
6+
patches:
7+
"1.0.0":
8+
- patch_file: "patches/fix-osi-includes.patch"
9+
- patch_file: "patches/osmp_vtd_v2.2.patch"
10+
- patch_file: "patches/cmakelists.patch"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# mypy: ignore-errors
2+
# pylint: skip-file
3+
4+
import os
5+
import shutil
6+
from pathlib import Path
7+
8+
from conan import ConanFile
9+
from conan.tools import cmake, files
10+
11+
required_conan_version = ">=1.52.0"
12+
13+
14+
class VtdSensorConan(ConanFile):
15+
name = "osi-sensor"
16+
version = "1.0.0"
17+
license = "Mozilla Public License 2.0"
18+
url = "https://github.com/OpenSimulationInterface/osi-sensor-model-packaging"
19+
description = "Example of a sensor model using OSI with FMI 2.0."
20+
topics = ("Sensor Simulation", "HAD")
21+
settings = "os", "compiler", "build_type", "arch"
22+
generators = "CMakeDeps", "VirtualRunEnv"
23+
options = {
24+
"simulator": ["vtd-2.2.0"],
25+
}
26+
default_options = {
27+
"simulator": "vtd-2.2.0",
28+
}
29+
30+
def export_sources(self):
31+
files.export_conandata_patches(self)
32+
33+
def requirements(self):
34+
self.requires("open-simulation-interface/3.0.1@cloe/stable", private=True)
35+
self.requires(
36+
"protobuf/2.6.1@cloe/stable",
37+
transitive_headers=True,
38+
transitive_libs=True,
39+
private=True,
40+
)
41+
self.requires("vtd/2.2.0@cloe-restricted/stable")
42+
43+
def source(self):
44+
files.get(
45+
self,
46+
**self.conan_data["sources"][self.version],
47+
destination=".",
48+
strip_root=True,
49+
)
50+
51+
def configure(self):
52+
# requirement options
53+
self.options["open-simulation-interface"].shared = True
54+
# package options
55+
self.settings.compiler.cppstd = "11"
56+
self.settings.compiler.libcxx = "libstdc++"
57+
58+
def layout(self):
59+
cmake.cmake_layout(self)
60+
61+
def generate(self):
62+
tc = cmake.CMakeToolchain(self)
63+
tc.cache_variables["VTD_ROOT"] = self.deps_env_info["vtd"].VTD_ROOT
64+
tc.generate()
65+
66+
def build(self):
67+
vtd_root = Path(self.deps_env_info["vtd"].VTD_ROOT)
68+
osi_lib = (
69+
vtd_root / "/Data/Setups/Standard.OSI3/Bin/libopen_simulation_interface.so"
70+
)
71+
if not osi_lib.is_file():
72+
self.output.warn(f"VTD OSI library not found: {osi_lib}")
73+
74+
cm = cmake.CMake(self)
75+
if self.should_configure:
76+
files.apply_conandata_patches(self)
77+
cm.configure(
78+
build_script_folder=os.path.join(
79+
self.source_folder, "examples", "OSMPDummySensor"
80+
)
81+
)
82+
if self.should_build:
83+
cm.build()
84+
85+
def package(self):
86+
cm = cmake.CMake(self)
87+
if self.should_install:
88+
cm.install()
89+
90+
def package_info(self):
91+
self.runenv_info.append(
92+
"VTD_EXTERNAL_MODELS",
93+
os.path.join(self.package_folder, "lib", "OSMPDummySensor.so"),
94+
)

0 commit comments

Comments
 (0)