Attempting to bring conan recipe from 1.x to new 2.x has stopped building static library

30 Views Asked by At

I use a conan recipe to build a 3rd party set of libraries.. in the past it built a static library (.a file).. but now there are loads of deprecation warnings to upgrade .. although gitlab is still on 1.x support only.. I thought fine lets upgrade the recipe to get "ready"

however I can see that my recipe is not working as expected.. it should be building a library that is static shared = false .. but it is in fact doing an .so file.. indicating it is a shared library.

Anyone with experience with conan able to help? I've search the docs and this seems not to jump out to me.

ConanFile.py

from conan import ConanFile
from conan.tools.files import files, copy
from conan.tools.layout import basic_layout
from conan.tools.cmake import CMake, CMakeToolchain
import os
from os.path import join

MY_VERSION = "10.27.01"

BRANCH_NAME = "10.27.01_fix"


class MyApiConan(ConanFile):
    name = "myapi"
    version = MY_VERSION
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [ False]}
    default_options = {"shared": False}
    generators = "CMakeToolchain"

    def source(self):
        self.run("git clone --depth 1 --branch " + BRANCH_NAME + " [email protected]:EMCP/my-api.git")

        files.replace_in_file(self, file_path="my-api/CMakeLists.txt", search="project( IBKR LANGUAGES CXX )",
                              replace='''project( MYAPI LANGUAGES CXX )
add_compile_options(-std=c++17)''')

    #        files.replace_in_file(self, file_path="my-api/CMakeLists.txt", search="         LANGUAGES CXX )",
#                              replace='''         LANGUAGES CXX )
#add_compile_options(-std=c++17)''')

    def layout(self):
        basic_layout(self, src_folder="src")

    def generate(self):
        tc = CMakeToolchain(self)
        tc.variables["BUILD_SHARED_LIBS"] = "OFF"  # Force static library
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure(build_script_folder="my-api")
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

        copy(self, "*.h", self.source_folder,   dst=join(self.package_folder, "include"), keep_path=False)
        copy(self, "*.lib", self.source_folder, dst=join(self.package_folder, "lib"), keep_path=False)
        copy(self, "*.dll", self.source_folder, dst=join(self.package_folder, "bin"), keep_path=False)
        copy(self, "*.so", self.source_folder, dst=join(self.package_folder, "lib"), keep_path=False)
        copy(self, "*.so", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"), keep_path=False)
        copy(self, "*.dylib", self.source_folder, dst=join(self.package_folder, "lib"), keep_path=False)
        copy(self, "*.a", self.source_folder, dst=join(self.package_folder, "lib"), keep_path=False)
        copy(self, "*.a", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"), keep_path=False)

        lib_paths = [
            "/usr/lib/x86_64-linux-gnu/libbidgcc000.a"
        ]
        for lib_path in lib_paths:
            if os.path.isfile(lib_path):
                self.output.info(f"Found library: {lib_path}")
                copy(self, pattern="libbidgcc000*.a", dst="lib", keep_path=False, src="/usr/lib/x86_64-linux-gnu/")
            else:
                self.output.warn(f"Library not found: {lib_path}")

    def package_info(self):
        self.cpp_info.libs = ["twsapi"]


0

There are 0 best solutions below