Skip to content

Commit

Permalink
(conan-io#14770) MPC Conan 2.0 Compatibility
Browse files Browse the repository at this point in the history
* MPC Conan 2.0 Compatibility

* Fixed lint errors

* Fixed license copying code

* Tweaked how win_bash is set

* Added new metadata for patch

* Try adding VirtrualBuildEnv for v1.x

* Bump required_conan_version

* Define CL-related flag macro values.

* Import is_msvc

* Add automake as a tool_requires

* Fixed typo

* Recognize that recipe lacks Visual Studio support

* Formatting tweak

* Added blank line to trigger CI build

* Use autotools.autoreconf() per review suggestion

* Add "m" as system_libs

* Add call to fix_apple_shared_install_name

Co-authored-by: Stella Smith <40411082+StellaSmith@users.noreply.github.com>

* Removed setting of shared/static options per code review

* Incorporate @spacelm's review feedback

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* Per review feedback

---------

Co-authored-by: Stella Smith <40411082+StellaSmith@users.noreply.github.com>
Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 2, 2023
1 parent aac5c3a commit aa5bf41
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 46 deletions.
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"
95 changes: 58 additions & 37 deletions recipes/mpc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"]
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)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE mpc::mpc)
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)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
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", "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)

0 comments on commit aa5bf41

Please sign in to comment.