Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open-simulation-interface: migrate to Conan v2 #18749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions recipes/open-simulation-interface/all/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/open-simulation-interface/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
sha256: "d492c1686fd82dba7a65a3653335bc71b111f8a760e2fbfaec06b80490027f2c"

patches:
3.1.2:
- patch_file: "patches/3.1.2_single_lib.patch"

Check warning on line 14 in recipes/open-simulation-interface/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/3.1.2_si ... ^ (line: 14)
base_path: "source_subfolder"
3.3.1:
- patch_file: "patches/3.3.x_single_lib.patch"

Check warning on line 16 in recipes/open-simulation-interface/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/3.3.x_si ... ^ (line: 16)
base_path: "source_subfolder"
3.4.0:
- patch_file: "patches/3.4.0_single_lib.patch"

Check warning on line 18 in recipes/open-simulation-interface/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/3.4.0_si ... ^ (line: 18)
base_path: "source_subfolder"
104 changes: 50 additions & 54 deletions recipes/open-simulation-interface/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import shutil

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir

required_conan_version = ">=1.60.0 <2.0 || >=2.0.5"


class OpenSimulationInterfaceConan(ConanFile):
name = "open-simulation-interface"
description = "Generic interface environmental perception of automated driving functions in virtual scenarios"
license = "MPL-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/OpenSimulationInterface/open-simulation-interface"
description = 'Generic interface environmental perception of automated driving functions in virtual scenarios'
topics = ("asam", "adas", "open-simulation", "automated-driving", "openx")
url = "https://github.com/conan-io/conan-center-index"
license = "MPL-2.0"

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -21,77 +27,67 @@ class OpenSimulationInterfaceConan(ConanFile):
"shared": False,
"fPIC": True,
}
generators = "cmake", "cmake_find_package"
_cmake = None
short_paths = True

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
if self.options.shared:
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("Shared Libraries are not supported on windows because of the missing symbol export in the library.")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("protobuf/3.17.1")
self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
if self.options.shared and self.settings.os == "Windows":
raise ConanInvalidConfiguration(
"Shared Libraries are not supported on windows because of the missing symbol export in the library."
)

def build_requirements(self):
self.build_requires("protobuf/3.17.1")
self.tool_requires("protobuf/<host_version>")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
try:
if self.settings.os == "Windows":
shutil.rmtree(os.path.join(self.package_folder, "CMake"))
else:
shutil.rmtree(os.path.join(self.package_folder, "lib", "cmake"))
except:
pass
if self.settings.os == "Windows":
rmdir(self, os.path.join(self.package_folder, "CMake"))
else:
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "open_simulation_interface")
self.cpp_info.set_property("cmake_target_name", "open_simulation_interface::open_simulation_interface")
self.cpp_info.components["libopen_simulation_interface"].libs = ["open_simulation_interface"]
self.cpp_info.components["libopen_simulation_interface"].requires = ["protobuf::libprotobuf"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "open_simulation_interface"
self.cpp_info.names["cmake_find_package_multi"] = "open_simulation_interface"
self.cpp_info.components["libopen_simulation_interface"].names["cmake_find_package"] = "open_simulation_interface"
self.cpp_info.components["libopen_simulation_interface"].names["cmake_find_package_multi"] = "open_simulation_interface"
self.cpp_info.components["libopen_simulation_interface"].libs = ["open_simulation_interface"]
self.cpp_info.components["libopen_simulation_interface"].requires = ["protobuf::libprotobuf"]

Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(open_simulation_interface REQUIRED)
find_package(open_simulation_interface REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)

target_link_libraries(${PROJECT_NAME}
open_simulation_interface::open_simulation_interface
)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)

21 changes: 15 additions & 6 deletions recipes/open-simulation-interface/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>

int main() {

osi3::SensorData d;
// Version
d.mutable_version()->set_version_major(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/open-simulation-interface/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)