From b30e2507dff1ebd67eb25da92f79c193f7152484 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 20 Jul 2023 14:44:04 +0300 Subject: [PATCH 1/5] open-simulation-interface: migrate to Conan v2 --- .../all/CMakeLists.txt | 8 -- .../all/conandata.yml | 3 - .../all/conanfile.py | 104 +++++++++--------- .../all/test_package/CMakeLists.txt | 11 +- .../all/test_package/conanfile.py | 21 +++- .../all/test_package/test_package.cpp | 2 +- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 17 +++ 8 files changed, 94 insertions(+), 80 deletions(-) delete mode 100644 recipes/open-simulation-interface/all/CMakeLists.txt create mode 100644 recipes/open-simulation-interface/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/open-simulation-interface/all/test_v1_package/conanfile.py diff --git a/recipes/open-simulation-interface/all/CMakeLists.txt b/recipes/open-simulation-interface/all/CMakeLists.txt deleted file mode 100644 index 5cfb924ad4de7..0000000000000 --- a/recipes/open-simulation-interface/all/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) - diff --git a/recipes/open-simulation-interface/all/conandata.yml b/recipes/open-simulation-interface/all/conandata.yml index e0a816774466a..0a86437ce1ae3 100644 --- a/recipes/open-simulation-interface/all/conandata.yml +++ b/recipes/open-simulation-interface/all/conandata.yml @@ -12,10 +12,7 @@ sources: patches: 3.1.2: - patch_file: "patches/3.1.2_single_lib.patch" - base_path: "source_subfolder" 3.3.1: - patch_file: "patches/3.3.x_single_lib.patch" - base_path: "source_subfolder" 3.4.0: - patch_file: "patches/3.4.0_single_lib.patch" - base_path: "source_subfolder" diff --git a/recipes/open-simulation-interface/all/conanfile.py b/recipes/open-simulation-interface/all/conanfile.py index 971823690f5f9..e8f1204a19591 100644 --- a/recipes/open-simulation-interface/all/conanfile.py +++ b/recipes/open-simulation-interface/all/conanfile.py @@ -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.53.0" + 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], @@ -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.9", transitive_headers=True) + + def validate(self): + if self.settings.compiler.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/3.21.9") 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"] - diff --git a/recipes/open-simulation-interface/all/test_package/CMakeLists.txt b/recipes/open-simulation-interface/all/test_package/CMakeLists.txt index 34497df14111e..27d995312b038 100644 --- a/recipes/open-simulation-interface/all/test_package/CMakeLists.txt +++ b/recipes/open-simulation-interface/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/open-simulation-interface/all/test_package/conanfile.py b/recipes/open-simulation-interface/all/test_package/conanfile.py index 3da371b660e0a..ef5d7042163ec 100644 --- a/recipes/open-simulation-interface/all/test_package/conanfile.py +++ b/recipes/open-simulation-interface/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -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) @@ -12,6 +21,6 @@ def build(self): 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") diff --git a/recipes/open-simulation-interface/all/test_package/test_package.cpp b/recipes/open-simulation-interface/all/test_package/test_package.cpp index 2b6c34045d39d..231a6941a54bb 100644 --- a/recipes/open-simulation-interface/all/test_package/test_package.cpp +++ b/recipes/open-simulation-interface/all/test_package/test_package.cpp @@ -3,7 +3,7 @@ #include int main() { - + osi3::SensorData d; // Version d.mutable_version()->set_version_major(3); diff --git a/recipes/open-simulation-interface/all/test_v1_package/CMakeLists.txt b/recipes/open-simulation-interface/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/open-simulation-interface/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/open-simulation-interface/all/test_v1_package/conanfile.py b/recipes/open-simulation-interface/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..49a3a66ea5bad --- /dev/null +++ b/recipes/open-simulation-interface/all/test_v1_package/conanfile.py @@ -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) From 158c89429e4da889afdc6c9541aee37df4932a2f Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 4 Aug 2023 00:08:03 +0300 Subject: [PATCH 2/5] open-simulation-interface: get_safe("cppstd") --- recipes/open-simulation-interface/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/open-simulation-interface/all/conanfile.py b/recipes/open-simulation-interface/all/conanfile.py index e8f1204a19591..69e8bd8b0e70f 100644 --- a/recipes/open-simulation-interface/all/conanfile.py +++ b/recipes/open-simulation-interface/all/conanfile.py @@ -46,7 +46,7 @@ def requirements(self): self.requires("protobuf/3.21.9", transitive_headers=True) def validate(self): - if self.settings.compiler.cppstd: + if self.settings.compiler.get_safe("cppstd"): check_min_cppstd(self, 11) if self.options.shared and self.settings.os == "Windows": raise ConanInvalidConfiguration( From ebdb8cc79baf7e1baa55a31b4fcb13cc0972923b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 7 Aug 2023 14:26:30 +0300 Subject: [PATCH 3/5] open-simulation-interface: bump deps --- recipes/open-simulation-interface/all/conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/open-simulation-interface/all/conanfile.py b/recipes/open-simulation-interface/all/conanfile.py index 69e8bd8b0e70f..c24c9e16af914 100644 --- a/recipes/open-simulation-interface/all/conanfile.py +++ b/recipes/open-simulation-interface/all/conanfile.py @@ -43,7 +43,7 @@ def layout(self): cmake_layout(self, src_folder="src") def requirements(self): - self.requires("protobuf/3.21.9", transitive_headers=True) + self.requires("protobuf/3.21.12", transitive_headers=True) def validate(self): if self.settings.compiler.get_safe("cppstd"): @@ -54,7 +54,7 @@ def validate(self): ) def build_requirements(self): - self.tool_requires("protobuf/3.21.9") + self.tool_requires("protobuf/") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) From 6a32493bc0d6c02a7b37e23b005921c2fe81fc19 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 20 Sep 2023 15:33:03 +0300 Subject: [PATCH 4/5] open-simulation-interface: update required_conan_version for host_version --- recipes/open-simulation-interface/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/open-simulation-interface/all/conanfile.py b/recipes/open-simulation-interface/all/conanfile.py index c24c9e16af914..dc18795928628 100644 --- a/recipes/open-simulation-interface/all/conanfile.py +++ b/recipes/open-simulation-interface/all/conanfile.py @@ -6,7 +6,7 @@ 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.53.0" +required_conan_version = ">=1.60.0 <2.0 || >=2.0.5" class OpenSimulationInterfaceConan(ConanFile): From 7a9622140c92195a2e863b07e564b2e17a96fd49 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 2 Nov 2023 07:17:47 +0200 Subject: [PATCH 5/5] open-simulation-interface: transitive_libs=True --- recipes/open-simulation-interface/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/open-simulation-interface/all/conanfile.py b/recipes/open-simulation-interface/all/conanfile.py index dc18795928628..b0e3cac24d6f1 100644 --- a/recipes/open-simulation-interface/all/conanfile.py +++ b/recipes/open-simulation-interface/all/conanfile.py @@ -43,7 +43,7 @@ def layout(self): cmake_layout(self, src_folder="src") def requirements(self): - self.requires("protobuf/3.21.12", transitive_headers=True) + self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True) def validate(self): if self.settings.compiler.get_safe("cppstd"):