lasote / conan-libcurl

Lib curl library package for conan
2 stars 12 forks source link

Building project in MacOS fails because Cocoa/Security frameworks not linked? #6

Open kinghajj opened 8 years ago

kinghajj commented 8 years ago

First, I'm quite new to conan, so I'm not really sure if this is 1) a bug with conan, 2) a bug with this recipe, or 3) a bug in my own recipe. Sorry if it turns out 1 or 3 are the actual culprits.

I'm trying to write a recipe for the AWS C++ SDK. So far, I've managed to use it successfully on both Arch Linux and an Ubuntu 16.04 Docker container. When I attempted to install it on my Macbook, however, I get a bunch of "Undefined symbols for architecture x86_64" referencing functions like _CFArrayCreate/_SSLClose/etc.

Here's the recipe I've come up with so far:

from conans import ConanFile, CMake
from conans.tools import download, unzip, check_md5, replace_in_file
from multiprocessing import cpu_count

libraries = [
    "access-management",
    "acm",
    "apigateway",
    "application-autoscaling",
    "autoscaling",
    "cloudformation",
    "cloudfront",
    "cloudhsm",
    "cloudsearch",
    "cloudsearchdomain",
    "cloudtrail",
    "codecommit",
    "codedeploy",
    "codepipeline",
    "cognito-identity",
    "cognito-idp",
    "cognito-sync",
    "config",
    "core",
    "datapipeline",
    "devicefarm",
    "directconnect",
    "dms",
    "ds",
    "dynamodb",
    "ec2",
    "ecr",
    "ecs",
    "elasticache",
    "elasticbeanstalk",
    "elasticfilesystem",
    "elasticloadbalancing",
    "elasticloadbalancingv2",
    "elasticmapreduce",
    "elastictranscoder",
    "email",
    "es",
    "events",
    "firehose",
    "gamelift",
    "glacier",
    "iam",
    "identity-management",
    "importexport",
    "inspector",
    "iot",
    "kinesis",
    "kinesisanalytics",
    "kms",
    "lambda",
    "logs",
    "machinelearning",
    "marketplacecommerceanalytics",
    "meteringmarketplace",
    "mobileanalytics",
    "monitoring",
    "opsworks",
    "queues",
    "rds",
    "redshift",
    "route53",
    "route53domains",
    "s3",
    "sdb",
    "servicecatalog",
    "snowball",
    "sns",
    "sqs",
    "ssm",
    "storagegateway",
    "sts",
    "support",
    "swf",
    "transfer",
    "waf",
    "workspaces",
]

class AwsSdkCppConan(ConanFile):
    name = "aws-sdk-cpp"
    version = "0.14.7"
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = "shared=True", "fPIC=True"
    generators = [ "cmake" ]

    def config(self):
        self.requires('libcurl/7.49.1@lasote/stable')
        self.requires('OpenSSL/1.0.2h@lasote/stable')

    def source(self):
        self.run("git clone --depth=1 -b %s https://github.com/aws/aws-sdk-cpp.git" % self.version)

    def build(self):
        cmake = CMake(self.settings)
        cmake_flags = []
        cmake_flags.append("-DENABLE_TESTING=OFF")
        if self.options.shared:
            cmake_flags.append("-DBUILD_SHARED_LIBS=ON")
        else:
            cmake_flags.append("-DSTATIC_LINKING=1")
        if self.settings.os != "Windows" and self.options.fPIC:
            cmake_flags.append("-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE")

        replace_in_file(
            "aws-sdk-cpp/CMakeLists.txt",
            "project(aws-sdk-cpp-all)",
            """project(aws-sdk-cpp-all)
            include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
            conan_basic_setup()""")
        self.run('cmake %s/aws-sdk-cpp %s %s' % (self.conanfile_directory, cmake.command_line, " ".join(cmake_flags)))
        self.run("make %s -j%s" % (cmake.build_config, cpu_count()))

    def package(self):
        for library in libraries:
            self.copy("*.h", dst="include", src=("aws-sdk-cpp/aws-cpp-sdk-%s/include" % library))
            self.copy("*.so", dst="lib", src=("aws-cpp-sdk-%s" % library))

    def package_info(self):
        self.cpp_info.libs = [("libaws-cpp-sdk-%s.so" % library) for library in libraries]

Do you have any suggestions to make the recipe work? I shouldn't have to specify these libraries manually, right, because line 166 of this project conanfile.py, right?

lasote commented 8 years ago

HI! It should work. Let me try it, we discovered a better way to link with Apple frameworks and maybe it solves the problem. I'll report back.

lasote commented 8 years ago

Try now, I've updated the libcurl package. Remember to use the "-u" option in conan install to get the updated recipe. Now the linker works great against the apple frameworks but it fails linking with zlib. Conan specifies it as a dependency automatically but I think you should "hack" a little more the CMakeLists aws-sdk-cpp/CMakeLists.txt. Take in account that in these CMakeLists.txt the CONAN_LIBS variable is not used so I don't know if it's automatically linking with "z" or not. But I think it's another issue and not related with the libcurl package, so it's and advance!

Great job with the conanfile.py by the way, it looks fantastic. Write me if I can help with it.