Search code examples
c++artifactoryconanbuild-type

How to overwrite conan shared option inside my project?


I have a project with the following conan recipe:

from conans import ConanFile, CMake

class MyLibConan(ConanFile):
    name = "mylib"
    version = "1.16.0"
    generators = "cmake"
    settings = "os", "arch", "compiler", "build_type"
    options = {"shared": [True, False]}
    default_options = "shared=False"
    exports_sources = ["*"]
    url = "some-url"
    license = "my license"
    description = "my library"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
       # do some copying here

    def package_info(self):
        self.cpp_info.includedirs = ['include']
        self.cpp_info.libdirs = ['lib']
        self.cpp_info.libs = ['mylib']

This library is supposed to be built in static mode. But the company servers build this as shared and my library tests fail because they can't find the .lib files.

Even though I have set the default type as static, it gets overwritten when the server runs it's script. I have also removed the True value from the options but then the whole script fails because True is not an option.

options = {"shared": [False]}

How can I make sure the library is always built in static mode without the server script failing?


Solution

  • The obvious suggestion is fixing your server script, because your library can be built as shared and static. Another possibility is updating your server script to generate static and shared, not only one option. If in your company you need to maintain an internal script, I would suggest using Conan Package Tools instead, where you can define a set of configuration to be built.

    However, if it's not a possible scenario and you really need a workaround, you still can enforce your package option in configure(self) method:

    def configure(self):
        self.options.shared = False
    

    It will override any value passed by argument when building. Also, the package ID will be same, as your package will be always static.