From 16ea0d13e2954a2efc132bf111a0619a285e69d8 Mon Sep 17 00:00:00 2001 From: toge Date: Mon, 30 Jan 2023 11:07:34 +0900 Subject: [PATCH 1/2] argtable3: add version 3.2.2, support conan v2 --- recipes/argtable3/all/CMakeLists.txt | 11 --- recipes/argtable3/all/conandata.yml | 9 +- recipes/argtable3/all/conanfile.py | 84 +++++++++---------- .../argtable3/all/test_package/CMakeLists.txt | 9 +- .../argtable3/all/test_package/conanfile.py | 22 +++-- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 17 ++++ recipes/argtable3/config.yml | 2 + 8 files changed, 94 insertions(+), 68 deletions(-) delete mode 100644 recipes/argtable3/all/CMakeLists.txt create mode 100644 recipes/argtable3/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/argtable3/all/test_v1_package/conanfile.py diff --git a/recipes/argtable3/all/CMakeLists.txt b/recipes/argtable3/all/CMakeLists.txt deleted file mode 100644 index d3f1ab5676542..0000000000000 --- a/recipes/argtable3/all/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - link_libraries(m) -endif() - -add_subdirectory(source_subfolder) diff --git a/recipes/argtable3/all/conandata.yml b/recipes/argtable3/all/conandata.yml index 103508c1e8a96..3dfcb090995fa 100644 --- a/recipes/argtable3/all/conandata.yml +++ b/recipes/argtable3/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "3.2.2": + url: "https://github.com/argtable/argtable3/archive/refs/tags/v3.2.2.f25c624.tar.gz" + sha256: "a5c66d819fa0be0435f37ed2fb3f23e371091722ff74219de97b65f6b9914e51" "3.2.1": url: "https://github.com/argtable/argtable3/releases/download/v3.2.1.52f24e5/argtable-v3.2.1.52f24e5.tar.gz" sha256: "bf02394a21378fdca95937fc4e3aeff8af63a2bfed7e3f87b1c1eda8bf9227dc" @@ -11,7 +14,9 @@ sources: patches: "3.2.0": - patch_file: "patches/3.2.0-0001-cmake-fixes.patch" - base_path: "source_subfolder" + patch_description: "disable example build, make shared/static build separated" + patch_type: "conan" "3.1.5": - patch_file: "patches/3.1.5-0001-cmake-fixes.patch" - base_path: "source_subfolder" + patch_description: "disable example build, make shared/static build separated" + patch_type: "conan" diff --git a/recipes/argtable3/all/conanfile.py b/recipes/argtable3/all/conanfile.py index 64ccba9e5506f..c61d32f5875c9 100644 --- a/recipes/argtable3/all/conanfile.py +++ b/recipes/argtable3/all/conanfile.py @@ -1,17 +1,23 @@ -from conans import CMake, ConanFile, tools +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file, save +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv import os import textwrap -required_conan_version = ">=1.33.0" - +required_conan_version = ">=1.53.0" class Argtable3Conan(ConanFile): name = "argtable3" description = "A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options." - topics = ("conan", "argtable3", "command", "line", "argument", "parse", "parsing", "getopt") license = "BSD-3-clause" - homepage = "https://www.argtable.org/" url = "https://github.com/conan-io/conan-center-index" + homepage = "https://www.argtable.org/" + topics = ("conan", "argtable3", "command", "line", "argument", "parse", "parsing", "getopt") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -22,14 +28,8 @@ class Argtable3Conan(ConanFile): "fPIC": True, } - exports_sources = "CMakeLists.txt", "patches/*" - generators = "cmake" - - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" + def export_sources(self): + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -37,27 +37,27 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") def source(self): - tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["ARGTABLE3_ENABLE_TESTS"] = False - self._cmake.configure() - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ARGTABLE3_ENABLE_TESTS"] = False + tc.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + apply_conandata_patches(self) # The initial space is important (the cmake script does OFFSET 0) - tools.save(os.path.join(self._source_subfolder, "version.tag"), " {}.0\n".format(self.version)) - cmake = self._configure_cmake() + save(self, os.path.join(self.build_folder, f"version.tag"), " {self.version}.0\n") + cmake = CMake(self) + cmake.configure() cmake.build() @property @@ -69,8 +69,7 @@ def _module_file_rel_path(self): return os.path.join(self._module_subfolder, "conan-official-{}-targets.cmake".format(self.name)) - @staticmethod - def _create_cmake_module_alias_targets(module_file, targets): + def _create_cmake_module_alias_targets(self, module_file, targets): content = "" for alias, aliased in targets.items(): content += textwrap.dedent("""\ @@ -79,15 +78,15 @@ def _create_cmake_module_alias_targets(module_file, targets): set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) endif() """.format(alias=alias, aliased=aliased)) - tools.save(module_file, content) + save(self, module_file, content) def package(self): - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") - cmake = self._configure_cmake() + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "cmake")) - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) # These targets were for versions <= 3.2.0 (newer create argtable3::argtable3) target_name = "argtable3" if self.options.shared else "argtable3_static" @@ -100,18 +99,19 @@ def package_info(self): suffix = "" if not self.options.shared: suffix += "_static" - if tools.Version(self.version) >= "3.2.1" and self.settings.build_type == "Debug": + if Version(self.version) >= "3.2.1" and self.settings.build_type == "Debug": suffix += "d" - self.cpp_info.libs = ["argtable3{}".format(suffix)] - if not self.options.shared: - if self.settings.os in ("FreeBSD", "Linux"): - self.cpp_info.system_libs.append("m") + self.cpp_info.libs = [f"argtable3{suffix}"] + if self.settings.os in ("FreeBSD", "Linux"): + self.cpp_info.system_libs.append("m") + + self.cpp_info.set_property("cmake_file_name", "Argtable3") + self.cpp_info.set_property("cmake_target_name", "argtable3") + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "Argtable3" self.cpp_info.filenames["cmake_find_package_multi"] = "Argtable3" self.cpp_info.names["cmake_find_package"] = "argtable3" self.cpp_info.names["cmake_find_package_multi"] = "argtable3" - - self.cpp_info.builddirs.append(self._module_subfolder) self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] diff --git a/recipes/argtable3/all/test_package/CMakeLists.txt b/recipes/argtable3/all/test_package/CMakeLists.txt index fab7dc3090af1..0e2b5ff2ca7a9 100644 --- a/recipes/argtable3/all/test_package/CMakeLists.txt +++ b/recipes/argtable3/all/test_package/CMakeLists.txt @@ -1,14 +1,11 @@ cmake_minimum_required(VERSION 3.1) -project(test_package C) - -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS) +project(test_package LANGUAGES C) find_package(Argtable3 REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) if(TARGET argtable3) - target_link_libraries(${PROJECT_NAME} argtable3) + target_link_libraries(${PROJECT_NAME} PRIVATE argtable3) else() - target_link_libraries(${PROJECT_NAME} argtable3_static) + target_link_libraries(${PROJECT_NAME} PRIVATE argtable3_static) endif() diff --git a/recipes/argtable3/all/test_package/conanfile.py b/recipes/argtable3/all/test_package/conanfile.py index fcd48798a6df1..0ab6dbb34f3d6 100644 --- a/recipes/argtable3/all/test_package/conanfile.py +++ b/recipes/argtable3/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -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_multi" + 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 +20,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("{} --help".format(bin_path), run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(f"{bin_path} --help", run_environment=True) diff --git a/recipes/argtable3/all/test_v1_package/CMakeLists.txt b/recipes/argtable3/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..be00a8c7f57c7 --- /dev/null +++ b/recipes/argtable3/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +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/argtable3/all/test_v1_package/conanfile.py b/recipes/argtable3/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..b36b4025b8a6a --- /dev/null +++ b/recipes/argtable3/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + +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(f"{bin_path} --help", run_environment=True) diff --git a/recipes/argtable3/config.yml b/recipes/argtable3/config.yml index 2f3c419dfc7ff..70453d7b259cf 100644 --- a/recipes/argtable3/config.yml +++ b/recipes/argtable3/config.yml @@ -1,4 +1,6 @@ versions: + "3.2.2": + folder: "all" "3.2.1": folder: "all" "3.2.0": From 60450e61b496a10c4e856da553faf5034acf5282 Mon Sep 17 00:00:00 2001 From: toge Date: Wed, 1 Feb 2023 01:11:54 +0900 Subject: [PATCH 2/2] fix conan v2 linter errors --- recipes/argtable3/all/conanfile.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/recipes/argtable3/all/conanfile.py b/recipes/argtable3/all/conanfile.py index c61d32f5875c9..a913e29c92185 100644 --- a/recipes/argtable3/all/conanfile.py +++ b/recipes/argtable3/all/conanfile.py @@ -1,11 +1,7 @@ from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file, save -from conan.tools.build import check_min_cppstd +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, save from conan.tools.scm import Version -from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.env import VirtualBuildEnv +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import os import textwrap @@ -55,7 +51,7 @@ def generate(self): def build(self): apply_conandata_patches(self) # The initial space is important (the cmake script does OFFSET 0) - save(self, os.path.join(self.build_folder, f"version.tag"), " {self.version}.0\n") + save(self, os.path.join(self.build_folder, "version.tag"), f" {self.version}.0\n") cmake = CMake(self) cmake.configure() cmake.build()