diff --git a/recipes/polymorphic_value/all/conanfile.py b/recipes/polymorphic_value/all/conanfile.py index 35b3d5c67ce80..a500ed7dae408 100644 --- a/recipes/polymorphic_value/all/conanfile.py +++ b/recipes/polymorphic_value/all/conanfile.py @@ -1,7 +1,13 @@ -from conans import ConanFile, tools -from conans.errors import ConanInvalidConfiguration +import os -required_conan_version = ">=1.43.0" +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import copy, get +from conan.tools.layout import basic_layout +from conan.tools.scm import Version + +required_conan_version = ">=1.50.0" class PolymorphictValueConan(ConanFile): @@ -14,10 +20,6 @@ class PolymorphictValueConan(ConanFile): settings = "os", "arch", "compiler", "build_type" no_copy_source = True - @property - def _source_subfolder(self): - return "source_subfolder" - @property def _minimum_cpp_standard(self): return 17 @@ -32,16 +34,16 @@ def _minimum_compilers_version(self): } def validate(self): - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, self._minimum_cpp_standard) + if self.settings.get_safe("compiler.cppstd"): + check_min_cppstd(self, self._minimum_cpp_standard) min_version = self._minimum_compilers_version.get( str(self.settings.compiler)) if not min_version: - self.output.warn("{} recipe lacks information about the {} " - "compiler support.".format( - self.name, self.settings.compiler)) + self.output.warning("{} recipe lacks information about the {} " + "compiler support.".format( + self.name, self.settings.compiler)) else: - if tools.Version(self.settings.compiler.version) < min_version: + if Version(self.settings.compiler.version) < min_version: raise ConanInvalidConfiguration( "{} requires C++{} support. " "The current compiler {} {} does not support it.".format( @@ -50,20 +52,24 @@ def validate(self): self.settings.compiler.version)) def package_id(self): - self.info.header_only() + self.info.clear() + + def layout(self): + basic_layout(self, src_folder="src") 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 package(self): - self.copy(pattern="polymorphic_value.*", dst="include", - src=self._source_subfolder) - self.copy("*LICENSE*", dst="licenses", keep_path=False) + copy(self, "polymorphic_value.*", self.source_folder, + os.path.join(self.package_folder, "include")) + copy(self, "*LICENSE*", self.source_folder, + os.path.join(self.package_folder, "licenses"), keep_path=False) def package_info(self): self.cpp_info.set_property("cmake_file_name", "polymorphic_value") - self.cpp_info.set_property("cmake_target_name", "polymorphic_value::polymorphic_value") + self.cpp_info.set_property( + "cmake_target_name", "polymorphic_value::polymorphic_value") self.cpp_info.names["cmake_find_package"] = "polymorphic_value" self.cpp_info.names["cmake_find_package_multi"] = "polymorphic_value" diff --git a/recipes/polymorphic_value/all/test_package/CMakeLists.txt b/recipes/polymorphic_value/all/test_package/CMakeLists.txt index e5843eef344a8..e6cc8838b8f43 100644 --- a/recipes/polymorphic_value/all/test_package/CMakeLists.txt +++ b/recipes/polymorphic_value/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 3.12) project(test_package CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(polymorphic_value REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) diff --git a/recipes/polymorphic_value/all/test_package/conanfile.py b/recipes/polymorphic_value/all/test_package/conanfile.py index 9b63bd176646b..e418ee7701960 100644 --- a/recipes/polymorphic_value/all/test_package/conanfile.py +++ b/recipes/polymorphic_value/all/test_package/conanfile.py @@ -1,10 +1,20 @@ -from conans import ConanFile, CMake, tools import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout + class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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,5 +22,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/polymorphic_value/all/test_v1_package/CMakeLists.txt b/recipes/polymorphic_value/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..8e2bfa718d864 --- /dev/null +++ b/recipes/polymorphic_value/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.12) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(polymorphic_value REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE polymorphic_value::polymorphic_value) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) diff --git a/recipes/polymorphic_value/all/test_v1_package/conanfile.py b/recipes/polymorphic_value/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..fa6afacf5620e --- /dev/null +++ b/recipes/polymorphic_value/all/test_v1_package/conanfile.py @@ -0,0 +1,20 @@ +import os + +from conan.tools.build import cross_building +from conans import CMake, ConanFile + + +# legacy validation with Conan 1.x +class TestPackageV1Conan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)