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

MPC Conan 2.0 Compatibility #14770

Merged
merged 20 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
3 changes: 2 additions & 1 deletion recipes/mpc/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
92 changes: 55 additions & 37 deletions recipes/mpc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.env import VirtualBuildEnv
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.files import copy, get, rmdir, rm, apply_conandata_patches
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.layout import basic_layout
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.microsoft import is_msvc, unix_path
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
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.56.0"
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

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")
Expand All @@ -16,65 +24,75 @@ class MpcConan(ConanFile):
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
exports_sources = "patches/**"
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

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()
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

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"])
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved
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()
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
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.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "MPC")
self.cpp_info.set_property("cmake_module_file_name", "mpc")
self.cpp_info.set_property("cmake_target_name", "MPC::MPC")
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.libs = ["mpc"]
self.cpp_info.system_libs = ["m"]
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions recipes/mpc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE MPC::MPC)
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 13 additions & 5 deletions recipes/mpc/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.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)
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)
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/mpc/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 C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions recipes/mpc/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, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

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)
16 changes: 16 additions & 0 deletions recipes/mpc/all/test_v1_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* example was taken from https://www.gnu.org/ghm/2011/paris/slides/andreas-enge-mpc.pdf */
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

#include <stdio.h>
#include <mpc.h>

int main (void) {
mpc_t z;
int inex;
mpc_init2 (z, 123);
mpc_set_ui_ui (z, 0, 2, MPC_RNDNN);
inex = mpc_asin (z, z, MPC_RNDNN);
mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
printf ("\n%i %i\n", MPC_INEX_RE (inex), MPC_INEX_IM (inex));
mpc_clear (z);
return 0;
}