diff --git a/recipes/mpc/all/conandata.yml b/recipes/mpc/all/conandata.yml index 007c14f9a1cc4..cd8f83a739d7d 100644 --- a/recipes/mpc/all/conandata.yml +++ b/recipes/mpc/all/conandata.yml @@ -8,4 +8,5 @@ sources: patches: "1.2.0": - patch_file: "patches/1.2.0-0001-asin-missing-limits.patch" - base_path: "source_subfolder" + patch_description: "asin.c needs limits.h" + patch_type: "portability" diff --git a/recipes/mpc/all/conanfile.py b/recipes/mpc/all/conanfile.py index 0d3ae8cad33a5..f996155628e5c 100644 --- a/recipes/mpc/all/conanfile.py +++ b/recipes/mpc/all/conanfile.py @@ -1,11 +1,20 @@ -from conans import ConanFile, AutoToolsBuildEnvironment, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.env import VirtualBuildEnv, VirtualRunEnv +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.layout import basic_layout +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.microsoft import is_msvc, unix_path +from conan.tools.apple import fix_apple_shared_install_name +from conan.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.33.0" + +required_conan_version = ">=1.54.0" class MpcConan(ConanFile): name = "mpc" + package_type = "library" description = "GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision " \ "and correct rounding of the result" topics = ("conan", "mpc", "multiprecision", "math", "mathematics") @@ -15,66 +24,78 @@ class MpcConan(ConanFile): settings = "os", "arch", "compiler", "build_type" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} - exports_sources = "patches/**" - _autotools = 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 + self.options.rm_safe("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 requirements(self): - self.requires("mpfr/4.1.0") + self.requires("gmp/6.2.1", transitive_headers=True) + self.requires("mpfr/4.1.0", transitive_headers=True) def validate(self): - # FIXME: add Visual Studio support, upstream has a makefile.vc - if self.settings.compiler == "Visual Studio": - raise ConanInvalidConfiguration("mpc can be built with Visual Studio, but it's not supported yet in this recipe.") + # FIXME: add msvc support, upstream has a makefile.vc + if is_msvc(self): + raise ConanInvalidConfiguration("mpc can be built with msvc, but it's not supported yet in this recipe.") @property def _settings_build(self): return getattr(self, "settings_build", self.settings) def build_requirements(self): - if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): - self.build_requires("msys2/cci.latest") + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + + def layout(self): + basic_layout(self, src_folder="src") 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], + destination=self.source_folder, strip_root=True) - def _configure_autotools(self): - if self._autotools: - return self._autotools - self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - args = [] - if self.options.shared: - args.extend(["--disable-static", "--enable-shared"]) - else: - args.extend(["--disable-shared", "--enable-static"]) - self._autotools.configure(args=args, configure_dir=self._source_subfolder) - return self._autotools + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + + tc = AutotoolsToolchain(self) + tc.configure_args.append(f'--with-gmp={unix_path(self, self.dependencies["gmp"].package_folder)}') + tc.configure_args.append(f'--with-mpfr={unix_path(self, self.dependencies["mpfr"].package_folder)}') + tc.generate() + + tc = AutotoolsDeps(self) + tc.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - autotools = self._configure_autotools() + apply_conandata_patches(self) + autotools = Autotools(self) + if not os.path.exists(os.path.join(self.source_folder, "configure")): + autotools.autoreconf(["-i"]) + autotools.configure() autotools.make() def package(self): - self.copy(pattern="COPYING.LESSER", dst="licenses", src=self._source_subfolder) - autotools = self._configure_autotools() + copy(self, "COPYING.LESSER", self.source_folder, os.path.join(self.package_folder, "licenses"), keep_path=False) + autotools = Autotools(self) autotools.install() - tools.rmdir(os.path.join(self.package_folder, "share")) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") + fix_apple_shared_install_name(self) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.la", os.path.join(self.package_folder, "lib"), recursive=True) def package_info(self): self.cpp_info.libs = ["mpc"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs = ["m"] diff --git a/recipes/mpc/all/test_package/CMakeLists.txt b/recipes/mpc/all/test_package/CMakeLists.txt index 7b9b613cbb24a..5167a095daebe 100644 --- a/recipes/mpc/all/test_package/CMakeLists.txt +++ b/recipes/mpc/all/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(test_package C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(mpc REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +target_link_libraries(${PROJECT_NAME} PRIVATE mpc::mpc) diff --git a/recipes/mpc/all/test_package/conanfile.py b/recipes/mpc/all/test_package/conanfile.py index bd7165a553cf4..da190011b6b6d 100644 --- a/recipes/mpc/all/test_package/conanfile.py +++ b/recipes/mpc/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import cross_building import os class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,6 +20,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self.settings): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if not cross_building(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/mpc/all/test_v1_package/CMakeLists.txt b/recipes/mpc/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/mpc/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/mpc/all/test_v1_package/conanfile.py b/recipes/mpc/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..7e2dfe859bb27 --- /dev/null +++ b/recipes/mpc/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)