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

mpir: relocatable shared lib on macOS + modernize #9135

Merged
merged 6 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
62 changes: 37 additions & 25 deletions recipes/mpir/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
from conans.errors import ConanInvalidConfiguration
import os
import glob

required_conan_version = ">=1.33.0"


class MpirConan(ConanFile):
name = "mpir"
description = "MPIR is a highly optimised library for bignum arithmetic" \
Expand All @@ -13,18 +14,21 @@ class MpirConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://mpir.org/"
license = "LGPL-3.0-or-later"
settings = "os", "compiler", "arch", "build_type"

provides = []

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_cxx": [True, False],
"enable_gmpcompat": [True, False]
"enable_gmpcompat": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_cxx": True,
"enable_gmpcompat": True
"enable_gmpcompat": True,
}

_autotools = None
Expand All @@ -33,34 +37,40 @@ class MpirConan(ConanFile):
def _source_subfolder(self):
return "source_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler == "Visual Studio" and self.options.shared:
if self._is_msvc and self.options.shared:
del self.options.enable_cxx
if not self.options.get_safe("enable_cxx", False):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.options.enable_gmpcompat:
self.provides.append("gmp")

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross-building doesn't work (yet)")

def build_requirements(self):
self.build_requires("yasm/1.3.0")
if self.settings.compiler != "Visual Studio":
if not self._is_msvc:
self.build_requires("m4/1.4.19")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross-building doesn't work (yet)")

def source(self):
tools.get(keep_permissions=True, **self.conan_data["sources"][self.version],
strip_root=True, destination=self._source_subfolder)
Expand Down Expand Up @@ -88,15 +98,15 @@ def _vcxproj_paths(self):
return vcxproj_paths

def _build_visual_studio(self):
if "MD" in self.settings.compiler.runtime and not self.options.shared: # RuntimeLibrary only defined in lib props files
props_path = os.path.join(self._source_subfolder, "build.vc",
"mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib))
if self.settings.build_type == "Debug":
tools.replace_in_file(props_path, "<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>",
"<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>")
else:
tools.replace_in_file(props_path, "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>",
"<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>")
if "MD" in msvc_runtime_flag(self) and not self.options.shared: # RuntimeLibrary only defined in lib props files
props_path = os.path.join(self._source_subfolder, "build.vc",
"mpir_{}_{}.props".format(str(self.settings.build_type).lower(), self._dll_or_lib))
if self.settings.build_type == "Debug":
tools.replace_in_file(props_path, "<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>",
"<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>")
else:
tools.replace_in_file(props_path, "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>",
"<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>")
SpaceIm marked this conversation as resolved.
Show resolved Hide resolved
msbuild = MSBuild(self)
for vcxproj_path in self._vcxproj_paths:
msbuild.build(vcxproj_path, platforms=self._platforms, upgrade_project=False)
Expand All @@ -121,16 +131,18 @@ def _configure_autotools(self):
return self._autotools

def build(self):
if self.settings.compiler == "Visual Studio":
if self._is_msvc:
self._build_visual_studio()
else:
with tools.chdir(self._source_subfolder):
# relocatable shared lib on macOS
tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/")
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("COPYING*", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == "Visual Studio":
if self._is_msvc:
lib_folder = os.path.join(self._source_subfolder, self._dll_or_lib,
self._platforms.get(str(self.settings.arch)),
str(self.settings.build_type))
Expand All @@ -154,7 +166,7 @@ def package_info(self):
if self.options.get_safe("enable_cxx"):
self.cpp_info.libs.append("mpirxx")
self.cpp_info.libs.append("mpir")
if self.options.enable_gmpcompat and self.settings.compiler != "Visual Studio":
if self.options.enable_gmpcompat and not self._is_msvc:
if self.options.get_safe("enable_cxx"):
self.cpp_info.libs.append("gmpxx")
self.cpp_info.libs.append("gmp")
Expand Down
4 changes: 2 additions & 2 deletions recipes/mpir/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"

def build(self):
Expand All @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)