-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
polymorphic_value: conan v2 support #13973
Changes from 1 commit
55c8f45
e01f806
84f85e4
0fc7148
0df272d
0ab6ad4
803ab4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,11 @@ | ||||||
from conans import ConanFile, tools | ||||||
from conans.errors import ConanInvalidConfiguration | ||||||
import os | ||||||
|
||||||
required_conan_version = ">=1.43.0" | ||||||
from conan import ConanFile, tools | ||||||
from conan.errors import ConanInvalidConfiguration | ||||||
from conan.tools.files import copy, get | ||||||
from conan.tools.layout import basic_layout | ||||||
|
||||||
required_conan_version = ">=1.50.0" | ||||||
|
||||||
|
||||||
class PolymorphictValueConan(ConanFile): | ||||||
|
@@ -14,10 +18,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,38 +32,42 @@ 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.info.settings.get_safe("compiler.cppstd"): | ||||||
dvirtz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
tools.build.check_min_cppstd(self, self._minimum_cpp_standard) | ||||||
min_version = self._minimum_compilers_version.get( | ||||||
str(self.settings.compiler)) | ||||||
str(self.info.settings.compiler)) | ||||||
dvirtz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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.info.settings.compiler)) | ||||||
dvirtz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
else: | ||||||
if tools.Version(self.settings.compiler.version) < min_version: | ||||||
if tools.Version(self.info.settings.compiler.version) < min_version: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in |
||||||
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)) | ||||||
self.info.settings.compiler, | ||||||
self.info.settings.compiler.version)) | ||||||
dvirtz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
def package_id(self): | ||||||
self.info.header_only() | ||||||
self.info.clear() | ||||||
|
||||||
def layout(self): | ||||||
basic_layout(self, src_folder="source") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a style convention, 😎
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to have that in the docs then: https://docs.conan.io/en/latest/migrating_to_2.0/recipes.html#the-layout-method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dvirtz Conan docs is different from ConanCenterIndex convention. It's well documented on ConanCenterIndex templates: https://github.com/conan-io/conan-center-index/blob/master/docs/package_templates/cmake_package/all/conanfile.py#L70 |
||||||
|
||||||
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +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.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE polymorphic_value::polymorphic_value) | ||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) | ||
|
||
enable_testing() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It saves the need to track down the executable path though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is running it the virtualenv. Running a test from cmake command, does not guarantee which environment (conanrun, conanbuild) is being used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,20 @@ | ||||||||
from conans import ConanFile, CMake, tools | ||||||||
import os | ||||||||
from conan import ConanFile, tools | ||||||||
from conan.tools.cmake import CMake | ||||||||
|
||||||||
|
||||||||
class TestPackageConan(ConanFile): | ||||||||
settings = "os", "arch", "compiler", "build_type" | ||||||||
generators = "cmake", "cmake_find_package_multi" | ||||||||
generators = "CMakeDeps", "CMakeToolchain" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
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): | ||||||||
self.run(os.path.join("bin", "test_package"), run_environment=True) | ||||||||
if not tools.build.cross_building(self): | ||||||||
cmake = CMake(self) | ||||||||
cmake.test() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct would run |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from conans import ConanFile, CMake, tools | ||
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): | ||
self.run(os.path.join("bin", "test_package"), run_environment=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private import, we recommend important the functions directly in CCI