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

argtable3: add version 3.2.2, support conan v2 #15548

Merged
merged 2 commits into from
Feb 3, 2023
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
11 changes: 0 additions & 11 deletions recipes/argtable3/all/CMakeLists.txt

This file was deleted.

9 changes: 7 additions & 2 deletions recipes/argtable3/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
80 changes: 38 additions & 42 deletions recipes/argtable3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from conans import CMake, ConanFile, tools
from conan import ConanFile
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, CMakeToolchain, cmake_layout
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],
Expand All @@ -22,42 +24,36 @@ 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":
del self.options.fPIC

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, "version.tag"), f" {self.version}.0\n")
cmake = CMake(self)
cmake.configure()
cmake.build()

@property
Expand All @@ -69,8 +65,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("""\
Expand All @@ -79,15 +74,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"
Expand All @@ -100,18 +95,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")
Copy link
Contributor

@SpaceIm SpaceIm Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's incorrect, there is a comment in this recipe explaining what are official target names:

These targets were for versions <= 3.2.0 (newer create argtable3::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]
9 changes: 3 additions & 6 deletions recipes/argtable3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 15 additions & 7 deletions recipes/argtable3/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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)
cmake.configure()
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)
8 changes: 8 additions & 0 deletions recipes/argtable3/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/argtable3/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
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)
2 changes: 2 additions & 0 deletions recipes/argtable3/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"3.2.2":
folder: "all"
"3.2.1":
folder: "all"
"3.2.0":
Expand Down