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

mpdecimal: Fix cxx+shared, remove unnecessary automake dependency #25903

Merged
merged 17 commits into from
Nov 15, 2024
Merged
44 changes: 19 additions & 25 deletions recipes/mpdecimal/2.5.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.gnu import AutotoolsToolchain, AutotoolsDeps, Autotools
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.files import get, chdir, copy, export_conandata_patches, apply_conandata_patches, mkdir, rename
from conan.tools.layout import basic_layout
from conan.tools.build import cross_building
Expand Down Expand Up @@ -32,10 +32,6 @@ class MpdecimalConan(ConanFile):
"cxx": True,
}

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

def export_sources(self):
export_conandata_patches(self)

Expand All @@ -57,20 +53,16 @@ def validate(self):
if is_msvc(self) and self.settings.arch not in ("x86", "x86_64"):
raise ConanInvalidConfiguration(
f"{self.ref} currently does not supported {self.settings.arch}. Contributions are welcomed")
if self.options.cxx:
if self.options.cxx and Version(self.version) < "2.5.1":
if self.options.shared and self.settings.os == "Windows":
raise ConanInvalidConfiguration(
"A shared libmpdec++ is not possible on Windows (due to non-exportable thread local storage)")

def build_requirements(self):
if is_msvc(self):
self.tool_requires("automake/1.16.5")
else:
# required to support windows as a build machine
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")
if not is_msvc(self) and self.settings_build.os == "Windows":
self.win_bash = True
jcar87 marked this conversation as resolved.
Show resolved Hide resolved
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand Down Expand Up @@ -102,13 +94,9 @@ def generate(self):

tc = AutotoolsToolchain(self)
tc.configure_args.append("--enable-cxx" if self.options.cxx else "--disable-cxx")
tc.generate()

deps = AutotoolsDeps(self)
if is_apple_os(self) and self.settings.arch == "armv8":
deps.environment.append("LDFLAGS", ["-arch arm64"])
deps.environment.append("LDXXFLAGS", ["-arch arm64"])
deps.generate()
tc_env = tc.environment()
tc_env.append("LDXXFLAGS", ["$LDFLAGS"])
tc.generate(tc_env)

@property
def _dist_folder(self):
Expand Down Expand Up @@ -145,13 +133,16 @@ def _build_msvc(self):
copy(self, "mpdecimal.h", libmpdec_folder, dist_folder)
if self.options.shared:
copy(self, f"libmpdec-{self.version}.dll", libmpdec_folder, dist_folder)
copy(self, f"libmpdec-{self.version}.dll.exp", libmpdec_folder, dist_folder)
copy(self, f"libmpdec-{self.version}.dll.lib", libmpdec_folder, dist_folder)
else:
copy(self, f"libmpdec-{self.version}.lib", libmpdec_folder, dist_folder)
if self.options.cxx:
if self.options.shared:
copy(self, f"libmpdec++-{self.version}.dll", libmpdecpp_folder, dist_folder)
copy(self, f"libmpdec++-{self.version}.dll.lib", libmpdecpp_folder, dist_folder)
else:
copy(self, f"libmpdec++-{self.version}.lib", libmpdecpp_folder, dist_folder)
copy(self, "decimal.hh", libmpdecpp_folder, dist_folder)
jcar87 marked this conversation as resolved.
Show resolved Hide resolved
copy(self, f"libmpdec++-{self.version}.lib", libmpdecpp_folder, dist_folder)

@property
def _shared_suffix(self):
Expand Down Expand Up @@ -219,7 +210,10 @@ def package(self):
def package_info(self):
lib_pre_suf = ("", "")
if is_msvc(self):
lib_pre_suf = ("lib", f"-{self.version}")
if self.options.shared:
lib_pre_suf = ("lib", f"-{self.version}.dll")
else:
lib_pre_suf = ("lib", f"-{self.version}")
elif self.settings.os == "Windows":
if self.options.shared:
lib_pre_suf = ("", ".dll")
Expand All @@ -240,4 +234,4 @@ def package_info(self):
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libmpdecimal++"].system_libs = ["pthread"]
if self.options.shared and Version(self.version) >= "2.5.1":
self.cpp_info.components["libmpdecimal"].defines = ["MPDECIMALXX_DLL"]
self.cpp_info.components["libmpdecimal++"].defines = ["MPDECIMALXX_DLL"]