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: bump + enable building libraries on MSVC #3849

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
21 changes: 16 additions & 5 deletions recipes/mpc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
sources:
"1.2.1":
url: "https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz"
sha256: "17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459"
"1.2.0":
url: https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz
sha256: e90f2d99553a9c19911abdb4305bf8217106a957e3994436428572c8dfe8fda6
url: "https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz"
sha256: "e90f2d99553a9c19911abdb4305bf8217106a957e3994436428572c8dfe8fda6"
"1.1.0":
url: https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
sha256: 6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e
url: "https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz"
sha256: "6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e"
patches:
"1.2.1":
- base_path: "source_subfolder"
patch_file: "patches/1.2.0-0001-msvc-add-mpfr-libpath+shared.patch"
"1.2.0":
- patch_file: "patches/1.2.0-0001-asin-missing-limits.patch"
- patch_file: "patches/1.2.0-0001-msvc-add-mpfr-libpath+shared.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.2.0-0002-asin-missing-limits.patch"
base_path: "source_subfolder"
"1.1.0":
- base_path: "source_subfolder"
patch_file: "patches/1.1.0-0001-msvc-add-mpfr-libpath+shared.patch"
80 changes: 61 additions & 19 deletions recipes/mpc/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MpcConan(ConanFile):
homepage = "http://www.multiprecision.org/mpc/home.html"
license = "LGPL-3.0-or-later"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
options = {"shared": [True, False], "fPIC": [True, False], "exact_int": ["gmp", "mpir"]}
default_options = {"shared": False, "fPIC": True, "exact_int": "gmp"}
exports_sources = "patches/**"

@property
Expand All @@ -23,18 +23,27 @@ def _source_subfolder(self):
_autotools = None

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

def requirements(self):
self.requires("mpfr/4.1.0")

def configure(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("The mpc package cannot be built on Visual Studio.")
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def requirements(self):
self.requires("mpfr/4.1.0")
# FIXME: DO AUTOTOOLS NEED GMP/MPIR???????
if self.options.exact_int == "gmp":
self.requires("gmp/6.2.1")
elif self.options.exact_int == "mpir":
self.requires("mpir/3.0.0")

def build_requirements(self):
if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH") and self.settings.compiler != "Visual Studio":
self.build_requires("msys2/20200517")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
Expand All @@ -43,27 +52,60 @@ def source(self):
def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self)
args = []
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
if self.options.shared:
args.extend(["--disable-static", "--enable-shared"])
else:
args.extend(["--disable-shared", "--enable-static"])
self._autotools.defines.append("MPC_SHARED")
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
self._autotools.configure(args=args, configure_dir=self._source_subfolder)
return self._autotools

def _nmake_run(self):
autotools = AutoToolsBuildEnvironment(self)
autotools.libs = []
autotools.flags.append("-EHs")
if self.options.shared:
autotools.defines.append("MPC_SHARED")
with tools.chdir(self._source_subfolder):
with tools.vcvars(self.settings):
self.run("nmake /f Makefile.vc STATIC={} GMPDIR=\"{}\" MPFR=\"{}\" CDEFAULTFLAGS=\"{}\" DESTDIR=\"{}\" GMPMUSTBEDLL=\"\"".format(
"0" if self.options.shared else "1",
self.deps_cpp_info[str(self.options.exact_int)].rootpath,
self.deps_cpp_info["mpfr"].rootpath,
"{} {}".format(autotools.vars["CPPFLAGS"], autotools.vars["CFLAGS"]),
self.package_folder,
), run_environment=True)

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
autotools = self._configure_autotools()
autotools.make()
if self.options.exact_int == "mpir":
tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile.vc"),
"libmpfr.lib", "mpfr.lib")
tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile.vc"),
"gmp.lib", "mpir.lib")
if self.settings.compiler == "Visual Studio":
self._nmake_run()
else:
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy(pattern="COPYING.LESSER", dst="licenses", src=self._source_subfolder)
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
os.unlink(os.path.join(self.package_folder, "lib", "libmpc.la"))
if self.settings.compiler == "Visual Studio":
self.copy("libmpc.lib", src=self._source_subfolder, dst="lib", keep_path=False)
os.rename(os.path.join(self.package_folder, "lib", "libmpc.lib"),
os.path.join(self.package_folder, "lib", "mpc.lib"))
self.copy("libmpc.dll", src=self._source_subfolder, dst="bin", keep_path=False)
self.copy("mpc.h", src=os.path.join(self._source_subfolder, "src"), dst="include")
else:
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
os.unlink(os.path.join(self.package_folder, "lib", "libmpc.la"))

def package_info(self):
self.cpp_info.libs = ["mpc"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- Makefile.vc
+++ Makefile.vc
@@ -267,7 +267,7 @@
#

$(LIBRARY): $(DIRMPC)config.h $(CPPOBJECTS)
- $(LINKER) /out:$@ $(CPPLINKOBJECTS) /LIBPATH:"$(GMPDIR)\lib" libmpfr.lib libgmp.lib $(LIBS_LOGGING)
+ $(LINKER) /out:$@ $(CPPLINKOBJECTS) /LIBPATH:"$(MPFR)\lib" /LIBPATH:"$(GMPDIR)\lib" mpfr.lib gmp.lib $(LIBS_LOGGING)

$(DIRMPC)config.h :
echo #define PACKAGE_STRING "mpc" >$(DIRMPC)\config.h
--- src/mpc.h
+++ src/mpc.h
@@ -109,7 +109,7 @@
/* Support for WINDOWS DLL, see
http://lists.gforge.inria.fr/pipermail/mpc-discuss/2011-November/000990.html;
when building the DLL, export symbols, otherwise behave as GMP */
-#if defined (__MPC_LIBRARY_BUILD) && __GMP_LIBGMP_DLL
-#define __MPC_DECLSPEC __GMP_DECLSPEC_EXPORT
+#if defined (__MPC_LIBRARY_BUILD) && defined(_WIN32) && defined(MPC_SHARED)
+#define __MPC_DECLSPEC __declspec(dllexport)
#else
#define __MPC_DECLSPEC __GMP_DECLSPEC
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- Makefile.vc
+++ Makefile.vc
@@ -267,7 +267,7 @@
#

$(LIBRARY): $(DIRMPC)config.h $(CPPOBJECTS)
- $(LINKER) /out:$@ $(CPPLINKOBJECTS) /LIBPATH:"$(GMPDIR)\lib" libmpfr.lib libgmp.lib $(LIBS_LOGGING)
+ $(LINKER) /out:$@ $(CPPLINKOBJECTS) /LIBPATH:"$(MPFR)\lib" /LIBPATH:"$(GMPDIR)\lib" mpfr.lib gmp.lib $(LIBS_LOGGING)

$(DIRMPC)config.h :
echo #define PACKAGE_STRING "mpc" >$(DIRMPC)\config.h
--- src/mpc.h
+++ src/mpc.h
@@ -111,7 +111,7 @@
/* Support for WINDOWS DLL, see
http://lists.gforge.inria.fr/pipermail/mpc-discuss/2011-November/000990.html;
when building the DLL, export symbols, otherwise behave as GMP */
-#if defined (__MPC_LIBRARY_BUILD) && __GMP_LIBGMP_DLL
-#define __MPC_DECLSPEC __GMP_DECLSPEC_EXPORT
+#if defined (__MPC_LIBRARY_BUILD) && defined(_WIN32) && defined(MPC_SHARED)
+#define __MPC_DECLSPEC __declspec(dllexport)
#else
#define __MPC_DECLSPEC __GMP_DECLSPEC
2 changes: 1 addition & 1 deletion recipes/mpc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ project(test_package)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* example was taken from https://www.gnu.org/ghm/2011/paris/slides/andreas-enge-mpc.pdf */

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

int main (void) {
mpc_t z;
Expand Down
2 changes: 2 additions & 0 deletions recipes/mpc/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.2.1":
folder: all
"1.2.0":
folder: all
"1.1.0":
Expand Down