Skip to content

Instantly share code, notes, and snippets.

@lasote
Created February 17, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lasote/d2a2020b061aff23c54829df85c55599 to your computer and use it in GitHub Desktop.
Save lasote/d2a2020b061aff23c54829df85c55599 to your computer and use it in GitHub Desktop.
GMPConan with new env refactor
import os
from conans import ConanFile, tools, AutoToolsBuildEnvironment
class GmpConan(ConanFile):
name = "gmp"
version = "6.1.1"
license = ""
url = "https://github.com/plexinc/plex-conan"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = "shared=False"
def source(self):
filename = "gmp-%s.tar.bz2" % self.version
tools.download("http://gmplib.org/download/gmp/%s" % filename, filename)
tools.unzip(filename)
os.unlink(filename)
def _run_cmd(self, command):
if self.settings.os == "Windows":
tools.run_in_windows_bash(self, command)
else:
self.run(command)
def build(self):
be = AutoToolsBuildEnvironment(self)
with tools.environment_append(be.vars):
with tools.chdir("gmp-%s" % self.version):
# Configure
installdir = tools.unix_path(os.path.join(self.conanfile_directory, "install"))
static_option = "--enable-shared=yes --enable-static=no" if self.options.shared \
else "--enable-shared=no --enable-static=yes"
configure_cmd = "./configure --prefix=%s %s --with-pic=yes" % (installdir, static_option)
self._run_cmd(configure_cmd)
# Make
make_cmd = "make -j %s" % (tools.cpu_count() - 1)
self._run_cmd(configure_cmd)
# Make Install
make_cmd = "make install"
self._run_cmd(configure_cmd)
def package(self):
include_dir = "install/include"
lib_dir = "install/lib"
include_dst = "include"
lib_dst = "lib"
header_keep_path = True
self.copy("*.h", src=include_dir, dst=include_dst, keep_path=header_keep_path)
self.copy("*.hpp", src=include_dir, dst=include_dst, keep_path=header_keep_path)
# Window's lib files always needs to be copied
self.copy("*.lib", src=lib_dir, dst=lib_dst, keep_path=False)
# save our pkg-config file as well
self.copy("*.pc", src=lib_dir, dst=os.path.join(lib_dst, "pkgconfig"), keep_path=False)
if self.options.shared:
# Windows DLL's go into 'bin'
if self.settings.os == "Windows":
self.copy("*.dll", src=lib_dir, dst="bin", keep_path=False)
# Linux so's
self.copy("*.so", src=lib_dir, dst=lib_dst, keep_path=False, links=True)
self.copy("*.so.*", src=lib_dir, dst=lib_dst, keep_path=False, links=True)
if not self.options.shared:
self.copy("*.a", src=lib_dir, dst=lib_dst, keep_path=False)
def package_info(self):
self.cpp_info.libs = ["gmp"]
if self.settings.os == "Windows":
return
rpaths = ["-Wl,-rpath,{0}".format(os.path.join(self.package_folder, libdir))
for libdir in self.cpp_info.libdirs]
self.cpp_info.sharedlinkflags += rpaths
self.cpp_info.exelinkflags += rpaths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment