Skip to content

Commit

Permalink
(#18901) mpdecimal/2.4.2: migrate to Conan v2
Browse files Browse the repository at this point in the history
* mpdecimal/2.4.2: migrate to Conan v2

* mpdecimal: restore VirtualRunEnv in test_package

* mpdecimal/2.4.2: fix MSVC build

* mpdecimal/2.5.x: make use of self.*_path variables

* mpdecimal/2.5.x: fix and simplify test_package

* mpdecimal/2.4.2: fix Windows lib name

* mpdecimal/2.4.2: fix_apple_shared_install_name()
  • Loading branch information
valgur authored Jan 10, 2024
1 parent 53710fd commit 757a1f6
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 201 deletions.
6 changes: 2 additions & 4 deletions recipes/mpdecimal/2.4.2/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ sources:
url: "http://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.4.2.tar.gz"
patches:
"2.4.2":
- base_path: "source_subfolder"
patch_file: "patches/0001-msvc-fixes.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-disable-vcstdint-h-vs2015.patch"
- patch_file: "patches/0001-msvc-fixes.patch"
- patch_file: "patches/0002-disable-vcstdint-h-vs2015.patch"
321 changes: 180 additions & 141 deletions recipes/mpdecimal/2.4.2/conanfile.py

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions recipes/mpdecimal/2.4.2/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()
find_package(mpdecimal REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE mpdecimal::mpdecimal)
20 changes: 15 additions & 5 deletions recipes/mpdecimal/2.4.2/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
self.run("{} 13 100".format(os.path.join("bin", "test_package")), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(f"{bin_path} 13 100", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/mpdecimal/2.4.2/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
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/)
16 changes: 16 additions & 0 deletions recipes/mpdecimal/2.4.2/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from conans import ConanFile, CMake, tools


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):
self.run("{} 13 100".format(os.path.join("bin", "test_package")), run_environment=True)
73 changes: 37 additions & 36 deletions recipes/mpdecimal/2.5.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from conan.tools.apple import is_apple_os
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
import pathlib

required_conan_version = ">=1.55.0"

Expand All @@ -17,10 +16,11 @@ class MpdecimalConan(ConanFile):
name = "mpdecimal"
description = "mpdecimal is a package for correctly-rounded arbitrary precision decimal floating point arithmetic."
license = "BSD-2-Clause"
topics = ("mpdecimal", "multiprecision", "library")
topics = ("multiprecision", "library")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://www.bytereef.org/mpdecimal"
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand Down Expand Up @@ -64,9 +64,9 @@ def validate(self):

def build_requirements(self):
if is_msvc(self):
self.tool_requires("automake/1.16.4")
self.tool_requires("automake/1.16.5")
else:
# required to suppport windows as a build machine
# 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):
Expand Down Expand Up @@ -110,18 +110,18 @@ def generate(self):
deps.environment.append("LDXXFLAGS", ["-arch arm64"])
deps.generate()

@property
def _dist_folder(self):
vcbuild_folder = self.build_path / "vcbuild"
arch_ext = "32" if self.settings.arch == "x86" else "64"
return vcbuild_folder / f"dist{arch_ext}"

def _build_msvc(self):
source_dir = pathlib.Path(self.source_folder)
build_dir = pathlib.Path(self.build_folder)
libmpdec_folder = source_dir / "libmpdec"
libmpdecpp_folder = source_dir / "libmpdec++"
vcbuild_folder = build_dir / "vcbuild"
arch_ext = "{}".format(32 if self.settings.arch == "x86" else 64)
dist_folder = vcbuild_folder / "dist{}".format(arch_ext)
mkdir(self, dist_folder)
libmpdec_folder = self.source_path / "libmpdec"
libmpdecpp_folder = self.source_path / "libmpdec++"

copy(self, "Makefile.vc", libmpdec_folder, build_dir)
rename(self, build_dir / "Makefile.vc", libmpdec_folder / "Makefile")
copy(self, "Makefile.vc", libmpdec_folder, self.build_path)
rename(self, self.build_path / "Makefile.vc", libmpdec_folder / "Makefile")

mpdec_target = "libmpdec-{}.{}".format(self.version, "dll" if self.options.shared else "lib")
mpdecpp_target = "libmpdec++-{}.{}".format(self.version, "dll" if self.options.shared else "lib")
Expand All @@ -140,16 +140,18 @@ def _build_msvc(self):
dll="1" if self.options.shared else "0",
))

dist_folder = self._dist_folder
mkdir(self, dist_folder)
copy(self, "mpdecimal.h", libmpdec_folder, dist_folder)
if self.options.shared:
copy(self, "libmpdec-{}.dll".format(self.version), libmpdec_folder, dist_folder)
copy(self, "libmpdec-{}.dll.exp".format(self.version), libmpdec_folder, dist_folder)
copy(self, "libmpdec-{}.dll.lib".format(self.version), libmpdec_folder, dist_folder)
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, "libmpdec-{}.lib".format(self.version), libmpdec_folder, dist_folder)
copy(self, f"libmpdec-{self.version}.lib", libmpdec_folder, dist_folder)
if self.options.cxx:
copy(self, "decimal.hh", libmpdecpp_folder, dist_folder)
copy(self, "libmpdec++-{}.lib".format(self.version), libmpdecpp_folder, dist_folder)
copy(self, f"libmpdec++-{self.version}.lib", libmpdecpp_folder, dist_folder)

@property
def _shared_suffix(self):
Expand All @@ -162,10 +164,13 @@ def _shared_suffix(self):
@property
def _target_names(self):
libsuffix = self._shared_suffix if self.options.shared else ".a"
versionsuffix = ".{}".format(self.version) if self.options.shared else ""
suffix = "{}{}".format(versionsuffix, libsuffix) if is_apple_os(
self) or self.settings.os == "Windows" else "{}{}".format(libsuffix, versionsuffix)
return "libmpdec{}".format(suffix), "libmpdec++{}".format(suffix)
versionsuffix = f".{self.version}" if self.options.shared else ""
suffix = (
f"{versionsuffix}{libsuffix}"
if is_apple_os(self) or self.settings.os == "Windows"
else f"{libsuffix}{versionsuffix}"
)
return f"libmpdec{suffix}", f"libmpdec++{suffix}"

def build(self):
apply_conandata_patches(self)
Expand All @@ -176,32 +181,28 @@ def build(self):
autotools.configure()
# self.output.info(load(self, pathlib.Path("libmpdec", "Makefile")))
libmpdec, libmpdecpp = self._target_names
copy(self, "*", pathlib.Path(self.source_folder, "libmpdec"), pathlib.Path(self.build_folder, "libmpdec"))
copy(self, "*", self.source_path / "libmpdec", self.build_path / "libmpdec")
with chdir(self, "libmpdec"):
autotools.make(target=libmpdec)
if self.options.cxx:
copy(self, "*", pathlib.Path(self.source_folder, "libmpdec++"),
pathlib.Path(self.build_folder, "libmpdec++"))
copy(self, "*", self.source_path / "libmpdec++", self.build_path / "libmpdec++")
with chdir(self, "libmpdec++"):
autotools.make(target=libmpdecpp)

def package(self):
source_dir = pathlib.Path(self.source_folder)
pkg_dir = pathlib.Path(self.package_folder)
pkg_dir = self.package_path
copy(self, "LICENSE.txt", src=self.source_folder, dst=pkg_dir / "licenses")
if is_msvc(self):
build_dir = pathlib.Path(self.build_folder)
distfolder = build_dir / "vcbuild" / "dist{}".format(32 if self.settings.arch == "x86" else 64)
copy(self, "vc*.h", src=source_dir / "libmpdec", dst=pkg_dir / "include")
distfolder = self._dist_folder
copy(self, "vc*.h", src=self.source_path / "libmpdec", dst=pkg_dir / "include")
copy(self, "*.h", src=distfolder, dst=pkg_dir / "include")
if self.options.cxx:
copy(self, "*.hh", src=distfolder, dst=pkg_dir / "include")
copy(self, "*.lib", src=distfolder, dst=pkg_dir / "lib")
copy(self, "*.dll", src=distfolder, dst=pkg_dir / "bin")
else:
build_dir = pathlib.Path(self.build_folder)
mpdecdir = build_dir / "libmpdec"
mpdecppdir = build_dir / "libmpdec++"
mpdecdir = self.build_path / "libmpdec"
mpdecppdir = self.build_path / "libmpdec++"
copy(self, "mpdecimal.h", src=mpdecdir, dst=pkg_dir / "include")
if self.options.cxx:
copy(self, "decimal.hh", src=mpdecppdir, dst=pkg_dir / "include")
Expand All @@ -218,7 +219,7 @@ def package(self):
def package_info(self):
lib_pre_suf = ("", "")
if is_msvc(self):
lib_pre_suf = ("lib", "-{}".format(self.version))
lib_pre_suf = ("lib", f"-{self.version}")
elif self.settings.os == "Windows":
if self.options.shared:
lib_pre_suf = ("", ".dll")
Expand Down
4 changes: 2 additions & 2 deletions recipes/mpdecimal/2.5.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)
project(test_package LANGUAGES CXX C)

enable_testing()

Expand All @@ -10,7 +10,7 @@ add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE mpdecimal::libmpdecimal)
add_test(NAME test_package COMMAND test_package 10 13)

if(MPDECIMAL_CXX)
if(TARGET mpdecimal::libmpdecimal++)
add_executable(${PROJECT_NAME}_cpp test_package.cpp)
set_propertY(TARGET ${PROJECT_NAME}_cpp PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME}_cpp PRIVATE mpdecimal::libmpdecimal++)
Expand Down
9 changes: 2 additions & 7 deletions recipes/mpdecimal/2.5.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run, build_jobs


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "VirtualRunEnv", "CMakeDeps"
generators = "VirtualRunEnv", "CMakeToolchain", "CMakeDeps"
test_type = "explicit"

def layout(self):
Expand All @@ -14,11 +14,6 @@ def layout(self):
def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MPDECIMAL_CXX"] = self.dependencies["mpdecimal"].options.cxx
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
2 changes: 1 addition & 1 deletion recipes/mpdecimal/2.5.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_v1_package)

enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion recipes/mpdecimal/2.5.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

def build(self):
cmake = CMake(self)
Expand Down

0 comments on commit 757a1f6

Please sign in to comment.