Skip to content

Commit da46743

Browse files
committed
vtd: Update vtd-api packages for 2.0 compatibility
BREAKING CHANGE: The VTD_API_2_2_0 define is replaced by VTD_API_VERSION numerical constant for future proofing. This is split into separate defined components: - VTD_API_VERSION_EPOCH - VTD_API_VERSION_MAJOR - VTD_API_VERSION_MINOR - VTD_API_VERSION_PATCH These can be used once the `vtd_version.hpp` header is included. See this header file for documentation.
1 parent 7ec17cc commit da46743

15 files changed

+205
-109
lines changed

optional/vtd/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ add_library(vtd-object-lib STATIC
2424
)
2525
target_link_libraries(vtd-object-lib
2626
PUBLIC
27-
vtd-api::vtd-api
27+
vtd::api
2828
cloe::runtime
2929
cloe::models
3030
Boost::boost
3131
open-simulation-interface::open-simulation-interface
3232
)
33-
message(STATUS "VTD_API_VERSION: ${VTD_API_VERSION}")
34-
if (${VTD_API_VERSION} MATCHES "2.2.0")
35-
add_compile_definitions("VTD_API_2_2_0")
36-
endif()
3733

3834
set_target_properties(vtd-object-lib PROPERTIES
3935
CXX_STANDARD 17

optional/vtd/conanfile.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,8 @@ def layout(self):
104104
cmake.cmake_layout(self)
105105

106106
def generate(self):
107-
vtd_api_version = str(self.requires.get("vtd-api"))
108-
if "vtd-api/2.2.0" in vtd_api_version:
109-
self.vtd_api_version = "2.2.0"
110-
else:
111-
self.vtd_api_version = "2022.3"
112107
tc = cmake.CMakeToolchain(self)
113108
tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
114-
tc.preprocessor_definitions["VTD_API_VERSION"] = self.vtd_api_version
115-
tc.cache_variables["VTD_API_VERSION"] = self.vtd_api_version
116109
tc.cache_variables["CLOE_PROJECT_VERSION"] = self.version
117110
tc.cache_variables["TargetLintingExtended"] = self.options.pedantic
118111
tc.generate()
@@ -124,13 +117,15 @@ def build(self):
124117
cm.test()
125118

126119
def package(self):
120+
vtd_api_version = self.dependencies["vtd-api"].ref.version
121+
127122
cm = cmake.CMake(self)
128123
cm.install()
129124
self.copy("vtd-launch", dst="bin", src=f"{self.source_folder}/bin")
130125
self.copy(
131126
"*.tar",
132127
dst=self._setup_folder,
133-
src=f"{self.source_folder}/{self._setup_folder}/{self.vtd_api_version}"
128+
src=f"{self.source_folder}/{self._setup_folder}/{vtd_api_version}"
134129
)
135130

136131
def package_id(self):

optional/vtd/src/omni_sensor_component.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727

2828
#include <Eigen/Geometry> // for Vector3d, Quaterniond
2929

30-
#ifdef VTD_API_2_2_0
31-
#include <viRDBIcd.h> // for RDB_OBJECT_TYPE_*
32-
#else
33-
#include <VtdToolkit/viRDBIcd.h>
34-
#endif
35-
3630
#include <cloe/component/lane_boundary.hpp> // for LaneBoundary
3731
#include <cloe/component/object.hpp> // for Object
3832
#include <cloe/utility/geometry.hpp> // for quaternion_from_rpy
3933

34+
#include "vtd_version.hpp"
35+
#if (VTD_API_VERSION_EPOCH == 0)
36+
#include <viRDBIcd.h> // for RDB_OBJECT_TYPE_*
37+
#else
38+
#include <VtdToolkit/viRDBIcd.h>
39+
#endif
40+
4041
#include "vtd_logger.hpp" // for lane_logger
4142

4243
namespace vtd {

optional/vtd/src/omni_sensor_component.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include <memory> // for shared_ptr<>, unique_ptr<>
2828
#include <string> // for string, to_string
2929

30-
#ifdef VTD_API_2_2_0
30+
#include "vtd_version.hpp"
31+
#if (VTD_API_VERSION_EPOCH == 0)
3132
#include <viRDBIcd.h> // for RDB_OBJECT_STATE_t, ...
3233
#else
3334
#include <VtdToolkit/viRDBIcd.h>
34-
#endif
35+
#endif
3536

3637
#include "rdb_codec.hpp" // for RdbCodec, RdbTransceiver
3738
#include "vtd_logger.hpp" // for vtd_logger

optional/vtd/src/rdb_codec.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
#include <string> // for string
2828
#include <utility> // for move
2929

30-
// This comes from VTD:
31-
#ifdef VTD_API_2_2_0
30+
#include <cloe/core.hpp> // for Json, Duration
31+
32+
#include "vtd_version.hpp"
33+
#if (VTD_API_VERSION_EPOCH == 0)
3234
#include <RDBHandler.hh> // for RDB_MSG_t
3335
#else
3436
#include <VtdToolkit/RDBHandler.hh>
3537
#endif
36-
#include <cloe/core.hpp> // for Json, Duration
3738

3839
#include "rdb_transceiver.hpp" // for RdbTransceiver
3940

optional/vtd/src/rdb_transceiver.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525

2626
#include <memory> // for shared_ptr<>
2727
#include <vector> // for vector<>
28-
#ifdef VTD_API_2_2_0
28+
29+
#include <cloe/core.hpp> // for Json, Error
30+
31+
#include "vtd_version.hpp"
32+
#if (VTD_API_VERSION_EPOCH == 0)
2933
#include <viRDBIcd.h> // for RDB_MSG_t
3034
#else
3135
#include <VtdToolkit/viRDBIcd.h>
3236
#endif
33-
#include <cloe/core.hpp> // for Json, Error
3437

3538
namespace vtd {
3639

optional/vtd/src/rdb_transceiver_shm.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030

3131
#include <boost/interprocess/xsi_shared_memory.hpp> // for xsi_shared_memory, ...
3232

33-
#ifdef VTD_API_2_2_0
33+
#include "vtd_version.hpp"
34+
#if (VTD_API_VERSION_EPOCH == 0)
3435
#include <RDBHandler.hh> // for RDB_SHM_BUFFER_INFO_t, RDB_MSG_t, ...
3536
#else
3637
#include <VtdToolkit/RDBHandler.hh>
37-
#endif
38+
#endif
3839

3940
#include "vtd_logger.hpp" // for rdb_logger
4041

optional/vtd/src/scp_transceiver.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
#include <iostream> // for snprintf
2525
#include <string> // for string
2626

27-
#ifdef VTD_API_2_2_0
27+
#include <cloe/utility/tcp_transceiver.hpp> // for TcpReadError
28+
29+
#include "vtd_version.hpp"
30+
#if (VTD_API_VERSION_EPOCH == 0)
2831
#include <scpIcd.h> // for SCP_MAGIC_NO, SCP_VERSION, SCP_MSG_HDR_t, ...
2932
#else
3033
#include <VtdToolkit/scpIcd.h>
31-
#endif
32-
33-
#include <cloe/utility/tcp_transceiver.hpp> // for TcpReadError
34+
#endif
3435

3536
namespace vtd {
3637

optional/vtd/src/scp_transceiver.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@
3636
#pragma once
3737

3838
#include <string> // for string
39-
#ifdef VTD_API_2_2_0
39+
40+
#include <cloe/core.hpp> // for Json, Error
41+
#include <cloe/utility/tcp_transceiver.hpp> // for TcpTransceiver
42+
43+
#include "vtd_version.hpp"
44+
#if (VTD_API_VERSION_EPOCH == 0)
4045
#include <scpIcd.h>
4146
#else
4247
#include <VtdToolkit/scpIcd.h>
4348
#endif
44-
#include <cloe/core.hpp> // for Json, Error
45-
#include <cloe/utility/tcp_transceiver.hpp> // for TcpTransceiver
4649

4750
#include "vtd_logger.hpp" // for scp_logger
4851

optional/vtd/src/task_control.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
#include <string> // for string
2626
#include <utility> // for move
2727

28-
#ifdef VTD_API_2_2_0
29-
#include <RDBHandler.hh>
30-
#else
31-
#include <VtdToolkit/RDBHandler.hh>
32-
#endif
33-
3428
#include <cloe/component/object.hpp> // for Object
3529
#include <cloe/core.hpp> // for Json
3630

31+
#include "vtd_version.hpp"
32+
#if (VTD_API_VERSION_EPOCH == 0)
33+
#include <RDBHandler.hh>
34+
#else
35+
#include <VtdToolkit/RDBHandler.hh>
36+
#endif
37+
3738
#include "omni_sensor_component.hpp" // for VtdOmniSensor
3839
#include "rdb_codec.hpp" // for RdbCodec
3940
#include "vtd_logger.hpp" // for vtd_logger

optional/vtd/src/vtd_version.hpp

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file vtd_version.hpp
20+
*
21+
* This file just provides version information for the VTD version we
22+
* are working with.
23+
*
24+
* We expect the vtd-api library to define a constant VTD_API_VERSION,
25+
* which takes the following format:
26+
*
27+
* (EPOCH << 24) | (MAJOR_VERSION << 16) | (MINOR_VERSION << 8) | PATCH_VERSION
28+
*
29+
* Each version consists of at most 8 bits, so 256 potential values, including 0.
30+
* The epoch starts with 0, and is bumped after each version naming scheme.
31+
*
32+
* The following macros are defined from VTD_API_VERSION:
33+
*
34+
* - VTD_API_VERSION_EPOCH
35+
* - VTD_API_VERSION_MAJOR
36+
* - VTD_API_VERSION_MINOR
37+
* - VTD_API_VERSION_PATCH
38+
*
39+
* When years are involved, such as in releases versioned YYYY.MM, use the last
40+
* two years, since the full year will not fit in the 8 bits.
41+
*
42+
* Here are some example versions that could be used with this plugin:
43+
*
44+
* - VTD 2.1.0 -> Epoch = 0
45+
* - VTD 2.2.0
46+
* - VTD 2019.1 -> Epoch = 1
47+
* - VTD 2022.3
48+
*
49+
* So in order to target VTD 2.X, we could use `VTD_API_VERSION_EPOCH==0` or
50+
* `VTD_API_VERSION_MAJOR==2`.
51+
*/
52+
53+
#pragma once
54+
55+
#ifndef VTD_API_VERSION
56+
#error "require VTD_API_VERSION to be defined"
57+
#endif
58+
59+
#define VTD_API_VERSION_EPOCH ((VTD_API_VERSION >> 24) && 0xff)
60+
#define VTD_API_VERSION_MAJOR ((VTD_API_VERSION >> 16) && 0xff)
61+
#define VTD_API_VERSION_MINOR ((VTD_API_VERSION >> 8) && 0xff)
62+
#define VTD_API_VERSION_PATCH ((VTD_API_VERSION >> 0) && 0xff)

optional/vtd/vendor/vtd-api-2.2.0/CMakeLists.txt

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,29 @@ cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
22

33
project(vtd_api LANGUAGES CXX VERSION 2.2.0)
44

5-
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
6-
conan_basic_setup(TARGETS)
7-
8-
set(target vtd_api)
9-
10-
add_library(${target}
5+
add_library(vtd-api
116
src/Develop/Framework/RDBHandler/RDBHandler.cc
127
)
13-
target_include_directories(${target}
8+
add_library(vtd::api ALIAS vtd-api)
9+
target_include_directories(vtd-api
1410
PUBLIC
15-
src/Develop/Framework/inc
16-
src/Develop/Framework/RDBHandler
11+
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src/Develop/Framework/inc>"
12+
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src/Develop/Framework/RDBHandler>"
13+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
1714
)
1815

1916
# Installation -------------------------------------------------------
2017
include(GNUInstallDirs)
21-
install(TARGETS ${target}
18+
install(TARGETS vtd-api
2219
LIBRARY
2320
DESTINATION ${CMAKE_INSTALL_LIBDIR}
2421
ARCHIVE
2522
DESTINATION ${CMAKE_INSTALL_LIBDIR}
2623
)
2724
install(
2825
DIRECTORY
29-
src/Develop/Framework/inc/
30-
src/Develop/Framework/RDBHandler/
26+
${CMAKE_BINARY_DIR}/src/Develop/Framework/inc/
27+
${CMAKE_BINARY_DIR}/src/Develop/Framework/RDBHandler/
3128
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
29+
PATTERN "*.cc" EXCLUDE
3230
)

optional/vtd/vendor/vtd-api-2.2.0/conanfile.py

+38-22
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
from pathlib import Path
55

6-
from conans import CMake, ConanFile, tools
7-
from conans.errors import ConanInvalidConfiguration
6+
from conan import ConanFile
7+
from conan.errors import ConanInvalidConfiguration
8+
from conan.tools import cmake, files
9+
10+
required_conan_version = ">=1.52.0"
811

912

1013
class VtdApiConan(ConanFile):
@@ -31,36 +34,49 @@ class VtdApiConan(ConanFile):
3134
build_requires = [
3235
"vtd/2.2.0@cloe-restricted/stable",
3336
]
34-
generators = "cmake"
35-
36-
_cmake = None
37+
generators = "CMakeDeps", "CMakeToolchain"
3738

3839
def configure(self):
3940
if self.settings.os == "Windows":
4041
raise ConanInvalidConfiguration("VTD binaries do not exist for Windows")
4142

42-
def imports(self):
43-
self.copy("*", dst="src/Develop", src="Develop", root_package="vtd")
43+
def layout(self):
44+
cmake.cmake_layout(self)
4445

45-
def _configure_cmake(self):
46-
if self._cmake:
47-
return self._cmake
48-
self._cmake = CMake(self)
49-
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
50-
self._cmake.configure()
51-
return self._cmake
46+
def generate(self):
47+
files.copy(self, "Develop/*", src=self.dependencies.build["vtd"].package_folder, dst="../src")
5248

5349
def build(self):
54-
cmake = self._configure_cmake()
55-
cmake.build()
50+
cm = cmake.CMake(self)
51+
cm.configure()
52+
cm.build()
5653

5754
def package(self):
58-
cmake = self._configure_cmake()
59-
cmake.install()
60-
self.copy("Develop", src="src", symlinks=True)
55+
cm = cmake.CMake(self)
56+
cm.install()
57+
files.copy(self, "Develop", src="src", dst=".")
6158

6259
def package_info(self):
63-
if self.in_local_cache:
64-
self.cpp_info.libs = tools.collect_libs(self)
65-
else:
60+
self.cpp_info.set_property("cmake_find_mode", "both")
61+
self.cpp_info.set_property("cmake_file_name", "vtd-api")
62+
self.cpp_info.set_property("cmake_target_name", "vtd::api")
63+
self.cpp_info.set_property("pkg_config_name", "vtd-api")
64+
65+
# This define takes the format:
66+
#
67+
# (EPOCH << 24) | (MAJOR_VERSION << 16) | (MINOR_VERSION << 8) | PATCH_VERSION
68+
#
69+
# Each version consists of at most 8 bits, so 256 potential values, including 0.
70+
# The epoch starts with 0, and is bumped after each version naming scheme.
71+
#
72+
# When years are involved, such as in releases versioned YYYY.MM, use the last
73+
# two years, since the full year will not fit in the 8 bits.
74+
#
75+
# VTD VERSION : (0) 2 . 2 . 0
76+
vtd_api_version = (0<<24) | (2<<16) | (2<<8) | 0
77+
self.cpp_info.defines = ["VTD_API_VERSION={vtd_api_version}"]
78+
79+
if not self.in_local_cache:
6680
self.cpp_info.libs = ["vtd_api"]
81+
else:
82+
self.cpp_info.libs = files.collect_libs(self)

0 commit comments

Comments
 (0)