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

cxxopts: conan v2 support #13922

Merged
merged 2 commits into from
Nov 3, 2022
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
22 changes: 11 additions & 11 deletions recipes/cxxopts/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
sources:
"1.4.4":
url: https://github.com/jarro2783/cxxopts/archive/v1.4.4.zip
sha256: 7c8ec885fcc58e10a8268b57ae04d5cbeac895d150d3a09c15605ff7ef05cf87
"2.2.0":
url: https://github.com/jarro2783/cxxopts/archive/v2.2.0.zip
sha256: f9640c00d9938bedb291a21f9287902a3a8cee38db6910b905f8eba4a6416204
"2.2.1":
url: https://github.com/jarro2783/cxxopts/archive/v2.2.1.zip
sha256: 7021ce97f51a40f7fd3558da416ab6914b1d3f758ccf68a1e8734ad10b49b676
"3.0.0":
url: https://github.com/jarro2783/cxxopts/archive/v3.0.0.zip
sha256: 1eefdf5af3ba0c66458258de05df2a113262ad5e85cac489de0a456088e9f9b0
url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.0.0.tar.gz"
sha256: "36f41fa2a46b3c1466613b63f3fa73dc24d912bc90d667147f1e43215a8c6d00"
"2.2.1":
url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v2.2.1.tar.gz"
sha256: "984aa3c8917d649b14d7f6277104ce38dd142ce378a9198ec926f03302399681"
"2.2.0":
url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v2.2.0.tar.gz"
sha256: "447dbfc2361fce9742c5d1c9cfb25731c977b405f9085a738fbd608626da8a4d"
"1.4.4":
url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v1.4.4.tar.gz"
sha256: "1d0eedb39ecbc64a0f82d8b6fe40d5c8e611501702969cfbd14a07ce6ddb8501"
73 changes: 44 additions & 29 deletions recipes/cxxopts/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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
import os
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.51.1"


class CxxOptsConan(ConanFile):
Expand All @@ -10,17 +16,18 @@ class CxxOptsConan(ConanFile):
description = "Lightweight C++ option parser library, supporting the standard GNU style syntax for options."
license = "MIT"
topics = ("option-parser", "positional-arguments ", "header-only")
settings = "compiler"
options = { "unicode": [True, False] }
default_options = { "unicode": False }
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"
settings = "os", "arch", "compiler", "build_type"
options = {
"unicode": [True, False],
}
default_options = {
"unicode": False,
}
no_copy_source = True

@property
def _minimum_cpp_standard(self):
def _min_cppstd(self):
return 11

@property
Expand All @@ -32,33 +39,41 @@ def _minimum_compilers_version(self):
"apple-clang": "8",
}

def configure(self):
if self.settings.compiler.get_safe("cppstd"):
tools.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))
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration("{} requires C++{} support. The current compiler {} {} does not support it.".format(
self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version))
def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
if self.options.unicode:
self.requires("icu/70.1")
self.requires("icu/71.1")

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if min_version and Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support",
)

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],
destination=self.source_folder, strip_root=True)

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
self.copy("{}.hpp".format(self.name), dst="include", src=os.path.join(self._source_subfolder, "include"))
def build(self):
pass

def package_id(self):
self.info.header_only()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "cxxopts.hpp", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "cxxopts")
self.cpp_info.set_property("cmake_target_name", "cxxopts::cxxopts")
self.cpp_info.set_property("pkg_config_name", "cxxopts")
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if self.options.unicode:
self.cpp_info.defines = ["CXXOPTS_USE_UNICODE"]
13 changes: 6 additions & 7 deletions recipes/cxxopts/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1.3)
project(test_package CXX)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(cxxopts REQUIRED CONFIG)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::cxxopts)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts::cxxopts)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
28 changes: 19 additions & 9 deletions recipes/cxxopts/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import os
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
from io import StringIO
from conans import ConanFile, CMake, tools
import os


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

def layout(self):
cmake_layout(self)

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

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

def test(self):
if not tools.cross_building(self):
if can_run(self):
output = StringIO()
bin_path = os.path.join("bin", "test_package")
option_string = "-f 41 --bar baria --baz";
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
option_string = "-f 41 --bar baria --baz"
if self.options["cxxopts"].unicode:
option_string += " -q quxis";
self.run("{} {}".format(bin_path, option_string), run_environment=True, output=output)
option_string += " -q quxis"
self.run(f"{bin_path} {option_string}", env="conanrun", output=output)
output_lines = set(output.getvalue().splitlines())
expected_lines = {"foo:41", "bar:baria", "baz:1"}
if self.options["cxxopts"].unicode:
Expand Down
8 changes: 8 additions & 0 deletions recipes/cxxopts/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.1)
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)
27 changes: 27 additions & 0 deletions recipes/cxxopts/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conans import ConanFile, CMake, tools
from io import StringIO
import os


class TestPackageConan(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 tools.cross_building(self):
output = StringIO()
bin_path = os.path.join("bin", "test_package")
option_string = "-f 41 --bar baria --baz"
if self.options["cxxopts"].unicode:
option_string += " -q quxis"
self.run(f"{bin_path} {option_string}", run_environment=True, output=output)
output_lines = set(output.getvalue().splitlines())
expected_lines = {"foo:41", "bar:baria", "baz:1"}
if self.options["cxxopts"].unicode:
expected_lines.add("qux:quxis")
assert(expected_lines.issubset(output_lines))
8 changes: 4 additions & 4 deletions recipes/cxxopts/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
versions:
"1.4.4":
folder: all
"2.2.0":
"3.0.0":
folder: all
"2.2.1":
folder: all
"3.0.0":
"2.2.0":
folder: all
"1.4.4":
folder: all