1from conans import ConanFile, CMake, tools 2from conans.errors import ConanException 3 4 5class FruitConan(ConanFile): 6 name = "fruit" 7 version = "3.4.0" 8 license = "Apache" 9 url = "https://github.com/google/fruit" 10 description = "C++ dependency injection framework" 11 settings = "os", "compiler", "build_type", "arch" 12 options = {"shared": [True, False], "use_boost": [True, False]} 13 default_options = "shared=False", "use_boost=True" 14 generators = "cmake" 15 16 def configure(self): 17 min_version = { 18 "gcc": "5", 19 "clang": "3.5", 20 "apple-clang": "7.3", 21 "Visual Studio": "14", # MSVC 2015 22 }.get(str(self.settings.compiler)) 23 if not min_version: 24 # Unknown minimum version, let's try going ahead with the build to see if it works. 25 return 26 if str(self.settings.compiler.version) < min_version: 27 raise ConanException("%s %s is not supported, must be at least %s" % (self.settings.compiler, 28 self.settings.compiler.version, 29 min_version)) 30 31 def requirements(self): 32 if self.options.use_boost: 33 self.requires("boost/1.68.0@conan/stable") 34 35 def source(self): 36 self.run("git clone https://github.com/google/fruit") 37 self.run("cd fruit && git checkout v%s" % self.version) 38 # This small hack might be useful to guarantee proper /MT /MD linkage 39 # in MSVC if the packaged project doesn't have variables to set it 40 # properly 41 tools.replace_in_file("fruit/CMakeLists.txt", "project(Fruit)", 42 '''PROJECT(Myfruit) 43include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 44conan_basic_setup()''') 45 46 def build(self): 47 cmake = CMake(self) 48 cmake.definitions["FRUIT_IS_BEING_BUILT_BY_CONAN"] = "YES" 49 cmake.definitions["BUILD_SHARED_LIBS"] = "YES" if self.options.shared else "NO" 50 if self.options.use_boost: 51 if self.settings.os == "Windows": 52 cmake.definitions["BOOST_DIR"] = "." 53 else: 54 cmake.definitions["FRUIT_USES_BOOST"] = "NO" 55 if self.settings.os == "Windows": 56 cmake.definitions["FRUIT_TESTS_USE_PRECOMPILED_HEADERS"] = "NO" 57 cmake.definitions["CMAKE_BUILD_TYPE"] = self.settings.build_type 58 cmake.configure(source_folder="fruit") 59 cmake.build() 60 cmake.install() 61 62 def package(self): 63 self.copy("*.h", dst="include", src="include") 64 self.copy("*.h", dst="include", src="fruit/include") 65 self.copy("*fruit.lib", dst="lib", keep_path=False) 66 self.copy("*.dll", dst="bin", keep_path=False) 67 self.copy("*.so", dst="lib", keep_path=False) 68 self.copy("*.dylib", dst="lib", keep_path=False) 69 self.copy("*.a", dst="lib", keep_path=False) 70 tools.save("LICENSE", tools.load("fruit/COPYING")) 71 self.copy("COPYING", dst="licenses", ignore_case=True, keep_path=False) 72 73 def package_info(self): 74 self.cpp_info.libs = ["fruit"] 75