mirror of
https://github.com/conan-io/conan-center-index.git
synced 2025-08-15 19:14:43 +00:00
(#14702) numcpp: conan v2 support
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
from conans import ConanFile, tools
|
||||
from conans.errors import ConanInvalidConfiguration
|
||||
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
|
||||
|
||||
required_conan_version = ">=1.43.0"
|
||||
required_conan_version = ">=1.50.0"
|
||||
|
||||
|
||||
class NumCppConan(ConanFile):
|
||||
@@ -26,66 +30,70 @@ class NumCppConan(ConanFile):
|
||||
no_copy_source = True
|
||||
|
||||
@property
|
||||
def _source_subfolder(self):
|
||||
return "source_subfolder"
|
||||
def _min_cppstd(self):
|
||||
return "14"
|
||||
|
||||
def config_options(self):
|
||||
if tools.Version(self.version) < "2.5.0":
|
||||
del self.options.with_boost
|
||||
self.options.threads = True
|
||||
|
||||
def requirements(self):
|
||||
if tools.Version(self.version) < "2.5.0" or self.options.with_boost:
|
||||
self.requires("boost/1.78.0")
|
||||
|
||||
def package_id(self):
|
||||
self.info.header_only()
|
||||
|
||||
def validate(self):
|
||||
minimal_cpp_standard = "14"
|
||||
if self.settings.compiler.get_safe("cppstd"):
|
||||
tools.check_min_cppstd(self, minimal_cpp_standard)
|
||||
minimal_version = {
|
||||
@property
|
||||
def _compilers_minimum_version(self):
|
||||
return {
|
||||
"gcc": "5",
|
||||
"clang": "3.4",
|
||||
"apple-clang": "10",
|
||||
"Visual Studio": "14"
|
||||
"Visual Studio": "14",
|
||||
"msvc": "190",
|
||||
}
|
||||
compiler = str(self.settings.compiler)
|
||||
if compiler not in minimal_version:
|
||||
self.output.warn(
|
||||
"%s recipe lacks information about the %s compiler standard version support" % (self.name, compiler))
|
||||
self.output.warn(
|
||||
"%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
|
||||
return
|
||||
version = tools.Version(self.settings.compiler.version)
|
||||
if version < minimal_version[compiler]:
|
||||
raise ConanInvalidConfiguration("%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
|
||||
|
||||
def config_options(self):
|
||||
if Version(self.version) < "2.5.0":
|
||||
del self.options.with_boost
|
||||
self.options.threads = True
|
||||
|
||||
def layout(self):
|
||||
basic_layout(self, src_folder="src")
|
||||
|
||||
def requirements(self):
|
||||
if self.options.get_safe("with_boost", True):
|
||||
self.requires("boost/1.80.0", transitive_headers=True)
|
||||
|
||||
def package_id(self):
|
||||
self.info.clear()
|
||||
|
||||
def validate(self):
|
||||
if self.settings.compiler.get_safe("cppstd"):
|
||||
check_min_cppstd(self, self._min_cppstd)
|
||||
|
||||
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
|
||||
if minimum_version and Version(self.settings.compiler.version) < minimum_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 build(self):
|
||||
pass
|
||||
|
||||
def package(self):
|
||||
include_folder = os.path.join(self._source_subfolder, "include")
|
||||
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
|
||||
self.copy(pattern="*", dst="include", src=include_folder)
|
||||
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
|
||||
copy(self, "*", 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", "NumCpp")
|
||||
self.cpp_info.set_property("cmake_target_name", "NumCpp::NumCpp")
|
||||
if not self.options.get_safe("with_boost", False):
|
||||
if self.options.get_safe("with_boost", True):
|
||||
self.cpp_info.requires = ["boost::headers"]
|
||||
else:
|
||||
self.cpp_info.defines.append("NUMCPP_NO_USE_BOOST")
|
||||
|
||||
if tools.Version(self.version) < "2.5.0" and not self.options.threads:
|
||||
if Version(self.version) < "2.5.0" and not self.options.threads:
|
||||
self.cpp_info.defines.append("NO_MULTITHREAD")
|
||||
if tools.Version(self.version) >= "2.5.0" and self.options.threads:
|
||||
if Version(self.version) >= "2.5.0" and self.options.threads:
|
||||
self.cpp_info.defines.append("NUMCPP_USE_MULTITHREAD")
|
||||
|
||||
self.cpp_info.bindirs = []
|
||||
self.cpp_info.frameworkdirs = []
|
||||
self.cpp_info.libdirs = []
|
||||
self.cpp_info.resdirs = []
|
||||
|
||||
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
|
||||
self.cpp_info.names["cmake_find_package"] = "NumCpp"
|
||||
|
@@ -1,11 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test_package)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup(TARGETS)
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(test_package LANGUAGES CXX)
|
||||
|
||||
find_package(NumCpp REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} NumCpp::NumCpp)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE NumCpp::NumCpp)
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
|
||||
|
@@ -1,10 +1,19 @@
|
||||
from conans import ConanFile, CMake, tools
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "cmake", "cmake_find_package_multi"
|
||||
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)
|
||||
@@ -12,6 +21,6 @@ class TestPackageConan(ConanFile):
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if not tools.cross_building(self):
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run(bin_path, 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")
|
||||
|
8
recipes/numcpp/all/test_v1_package/CMakeLists.txt
Normal file
8
recipes/numcpp/all/test_v1_package/CMakeLists.txt
Normal file
@@ -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)
|
17
recipes/numcpp/all/test_v1_package/conanfile.py
Normal file
17
recipes/numcpp/all/test_v1_package/conanfile.py
Normal file
@@ -0,0 +1,17 @@
|
||||
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):
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run(bin_path, run_environment=True)
|
Reference in New Issue
Block a user