|
| 1 | +import os |
| 2 | + |
| 3 | +from conan import ConanFile |
| 4 | +from conan.errors import ConanInvalidConfiguration |
| 5 | +from conan.tools.build import cross_building |
| 6 | +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout |
| 7 | +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir |
| 8 | +from conan.tools.microsoft import is_msvc, check_min_vs |
| 9 | + |
| 10 | +required_conan_version = ">=1.52.0" |
| 11 | + |
| 12 | + |
| 13 | +class CorradeConan(ConanFile): |
| 14 | + name = "corrade" |
| 15 | + description = "Corrade is a multiplatform utility library written in C++11/C++14." |
| 16 | + license = "MIT" |
| 17 | + url = "https://github.com/conan-io/conan-center-index" |
| 18 | + homepage = "https://magnum.graphics/corrade" |
| 19 | + topics = ("magnum", "filesystem", "console", "environment", "os") |
| 20 | + |
| 21 | + package_type = "library" |
| 22 | + settings = "os", "arch", "compiler", "build_type" |
| 23 | + options = { |
| 24 | + "shared": [True, False], |
| 25 | + "fPIC": [True, False], |
| 26 | + "build_deprecated": [True, False], |
| 27 | + "with_interconnect": [True, False], |
| 28 | + "with_main": [True, False], |
| 29 | + "with_pluginmanager": [True, False], |
| 30 | + "with_testsuite": [True, False], |
| 31 | + "with_utility": [True, False], |
| 32 | + } |
| 33 | + default_options = { |
| 34 | + "shared": False, |
| 35 | + "fPIC": True, |
| 36 | + "build_deprecated": True, |
| 37 | + "with_interconnect": True, |
| 38 | + "with_main": True, |
| 39 | + "with_pluginmanager": True, |
| 40 | + "with_testsuite": True, |
| 41 | + "with_utility": True, |
| 42 | + } |
| 43 | + |
| 44 | + def export_sources(self): |
| 45 | + copy(self, "cmake/*", src=self.recipe_folder, dst=self.export_sources_folder) |
| 46 | + export_conandata_patches(self) |
| 47 | + |
| 48 | + def config_options(self): |
| 49 | + if self.settings.os == "Windows": |
| 50 | + del self.options.fPIC |
| 51 | + |
| 52 | + def configure(self): |
| 53 | + if self.options.shared: |
| 54 | + self.options.rm_safe("fPIC") |
| 55 | + |
| 56 | + def layout(self): |
| 57 | + cmake_layout(self, src_folder="src") |
| 58 | + |
| 59 | + def validate(self): |
| 60 | + check_min_vs(self, 190) |
| 61 | + if not self.options.with_utility and ( |
| 62 | + self.options.with_testsuite or self.options.with_interconnect or self.options.with_pluginmanager |
| 63 | + ): |
| 64 | + raise ConanInvalidConfiguration( |
| 65 | + "Component 'utility' is required for 'test_suite', 'interconnect' and 'plugin_manager'" |
| 66 | + ) |
| 67 | + |
| 68 | + def build_requirements(self): |
| 69 | + if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True): |
| 70 | + self.tool_requires(f"corrade/{self.version}") |
| 71 | + |
| 72 | + def source(self): |
| 73 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 74 | + |
| 75 | + def generate(self): |
| 76 | + tc = CMakeToolchain(self) |
| 77 | + tc.variables["BUILD_STATIC"] = not self.options.shared |
| 78 | + tc.variables["BUILD_STATIC_PIC"] = self.options.get_safe("fPIC", False) |
| 79 | + |
| 80 | + tc.variables["BUILD_DEPRECATED"] = self.options.build_deprecated |
| 81 | + tc.variables["WITH_INTERCONNECT"] = self.options.with_interconnect |
| 82 | + tc.variables["WITH_MAIN"] = self.options.with_main |
| 83 | + tc.variables["WITH_PLUGINMANAGER"] = self.options.with_pluginmanager |
| 84 | + tc.variables["WITH_TESTSUITE"] = self.options.with_testsuite |
| 85 | + tc.variables["WITH_UTILITY"] = self.options.with_utility |
| 86 | + tc.variables["WITH_RC"] = self.options.with_utility |
| 87 | + |
| 88 | + # Corrade uses suffix on the resulting "lib"-folder when running cmake.install() |
| 89 | + # Set it explicitly to empty, else Corrade might set it implicitly (eg. to "64") |
| 90 | + tc.variables["LIB_SUFFIX"] = "" |
| 91 | + |
| 92 | + if is_msvc(self): |
| 93 | + if check_min_vs(self, 193, raise_invalid=False): |
| 94 | + tc.variables["MSVC2019_COMPATIBILITY"] = True |
| 95 | + elif check_min_vs(self, 192, raise_invalid=False): |
| 96 | + tc.variables["MSVC2017_COMPATIBILITY"] = True |
| 97 | + elif check_min_vs(self, 191, raise_invalid=False): |
| 98 | + tc.variables["MSVC2015_COMPATIBILITY"] = True |
| 99 | + |
| 100 | + tc.generate() |
| 101 | + tc = CMakeDeps(self) |
| 102 | + tc.generate() |
| 103 | + |
| 104 | + def build(self): |
| 105 | + apply_conandata_patches(self) |
| 106 | + cmake = CMake(self) |
| 107 | + cmake.configure() |
| 108 | + cmake.build() |
| 109 | + |
| 110 | + def package(self): |
| 111 | + copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) |
| 112 | + cmake = CMake(self) |
| 113 | + cmake.install() |
| 114 | + share_cmake = os.path.join(self.package_folder, "share", "cmake", "Corrade") |
| 115 | + copy(self, "UseCorrade.cmake", |
| 116 | + src=share_cmake, |
| 117 | + dst=os.path.join(self.package_folder, "lib", "cmake")) |
| 118 | + copy(self, "CorradeLibSuffix.cmake", |
| 119 | + src=share_cmake, |
| 120 | + dst=os.path.join(self.package_folder, "lib", "cmake")) |
| 121 | + copy(self, "*.cmake", |
| 122 | + src=os.path.join(self.export_sources_folder, "cmake"), |
| 123 | + dst=os.path.join(self.package_folder, "lib", "cmake")) |
| 124 | + rmdir(self, os.path.join(self.package_folder, "share")) |
| 125 | + |
| 126 | + def package_info(self): |
| 127 | + self.cpp_info.set_property("cmake_find_mode", "both") |
| 128 | + self.cpp_info.set_property("cmake_file_name", "Corrade") |
| 129 | + self.cpp_info.set_property("cmake_target_name", "Corrade::Corrade") |
| 130 | + |
| 131 | + suffix = "-d" if self.settings.build_type == "Debug" else "" |
| 132 | + |
| 133 | + cmake_modules = [ |
| 134 | + # Reproduces the variables and calls performed by the FindCorrade.cmake provided by the library |
| 135 | + os.path.join("lib", "cmake", "conan-corrade-vars.cmake"), |
| 136 | + # Autodetects LIB_SUFFIX (either "64" or "") |
| 137 | + os.path.join("lib", "cmake", "CorradeLibSuffix.cmake"), |
| 138 | + # Exports build flags and macros |
| 139 | + os.path.join("lib", "cmake", "UseCorrade.cmake"), |
| 140 | + ] |
| 141 | + self.cpp_info.set_property("cmake_build_modules", cmake_modules) |
| 142 | + self.cpp_info.components["_corrade"].build_modules["cmake_find_package"] = cmake_modules |
| 143 | + self.cpp_info.components["_corrade"].build_modules["cmake_find_package_multi"] = cmake_modules |
| 144 | + |
| 145 | + if self.options.with_main: |
| 146 | + self.cpp_info.components["main"].set_property("cmake_target_name", "Corrade::Main") |
| 147 | + self.cpp_info.components["main"].names["cmake_find_package"] = "Main" |
| 148 | + self.cpp_info.components["main"].names["cmake_find_package_multi"] = "Main" |
| 149 | + if self.settings.os == "Windows": |
| 150 | + self.cpp_info.components["main"].libs = ["CorradeMain" + suffix] |
| 151 | + self.cpp_info.components["main"].requires = ["_corrade"] |
| 152 | + |
| 153 | + if self.options.with_utility: |
| 154 | + self.cpp_info.components["utility"].set_property("cmake_target_name", "Corrade::Utility") |
| 155 | + self.cpp_info.components["utility"].names["cmake_find_package"] = "Utility" |
| 156 | + self.cpp_info.components["utility"].names["cmake_find_package_multi"] = "Utility" |
| 157 | + self.cpp_info.components["utility"].libs = ["CorradeUtility" + suffix] |
| 158 | + if self.settings.os in ["Linux", "FreeBSD"]: |
| 159 | + self.cpp_info.components["utility"].system_libs = ["m", "dl"] |
| 160 | + self.cpp_info.components["utility"].requires = ["_corrade"] |
| 161 | + |
| 162 | + if self.options.with_interconnect: |
| 163 | + self.cpp_info.components["interconnect"].set_property("cmake_target_name", "Corrade::Interconnect") |
| 164 | + self.cpp_info.components["interconnect"].names["cmake_find_package"] = "Interconnect" |
| 165 | + self.cpp_info.components["interconnect"].names["cmake_find_package_multi"] = "Interconnect" |
| 166 | + self.cpp_info.components["interconnect"].libs = ["CorradeInterconnect" + suffix] |
| 167 | + self.cpp_info.components["interconnect"].requires = ["utility"] |
| 168 | + |
| 169 | + if self.options.with_pluginmanager: |
| 170 | + self.cpp_info.components["plugin_manager"].set_property("cmake_target_name", "Corrade::PluginManager") |
| 171 | + self.cpp_info.components["plugin_manager"].names["cmake_find_package"] = "PluginManager" |
| 172 | + self.cpp_info.components["plugin_manager"].names["cmake_find_package_multi"] = "PluginManager" |
| 173 | + self.cpp_info.components["plugin_manager"].libs = ["CorradePluginManager" + suffix] |
| 174 | + self.cpp_info.components["plugin_manager"].requires = ["utility"] |
| 175 | + |
| 176 | + if self.options.with_testsuite: |
| 177 | + self.cpp_info.components["test_suite"].set_property("cmake_target_name", "Corrade::TestSuite") |
| 178 | + self.cpp_info.components["test_suite"].names["cmake_find_package"] = "TestSuite" |
| 179 | + self.cpp_info.components["test_suite"].names["cmake_find_package_multi"] = "TestSuite" |
| 180 | + self.cpp_info.components["test_suite"].libs = ["CorradeTestSuite" + suffix] |
| 181 | + self.cpp_info.components["test_suite"].requires = ["utility"] |
| 182 | + |
| 183 | + if self.options.with_utility: |
| 184 | + bindir = os.path.join(self.package_folder, "bin") |
| 185 | + self.output.info(f"Appending PATH environment variable: {bindir}") |
| 186 | + self.env_info.PATH.append(bindir) |
| 187 | + |
| 188 | + # pkg_config: Add more explicit naming to generated files (avoid filesystem collision). |
| 189 | + for key, component in self.cpp_info.components.items(): |
| 190 | + component.set_property("pkg_config_name", f"{self.name}_{key}") |
| 191 | + |
| 192 | + self.cpp_info.names["cmake_find_package"] = "Corrade" |
| 193 | + self.cpp_info.names["cmake_find_package_multi"] = "Corrade" |
0 commit comments