|
| 1 | +from conan import ConanFile |
| 2 | +from conan.errors import ConanInvalidConfiguration |
| 3 | +from conan.tools.build import check_min_cppstd |
| 4 | +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout |
| 5 | +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir |
| 6 | +from conan.tools.microsoft import is_msvc, is_msvc_static_runtime |
| 7 | +import os |
| 8 | + |
| 9 | + |
| 10 | +required_conan_version = ">=2.0.9" |
| 11 | + |
| 12 | +class PackageConan(ConanFile): |
| 13 | + name = "sgltk" |
| 14 | + description = "A collection of easy to use OpenGL tools." |
| 15 | + license = "Zlib" |
| 16 | + url = "https://github.com/conan-io/conan-center-index" |
| 17 | + homepage = "https://github.com/pyth/sgltk" |
| 18 | + topics = ("c-plus-plus", "opengl", "sdl2") |
| 19 | + package_type = "library" |
| 20 | + settings = "os", "arch", "compiler", "build_type" |
| 21 | + options = { |
| 22 | + "shared": [True, False], |
| 23 | + "fPIC": [True, False], |
| 24 | + "with_sdl_ttf": [True, False], |
| 25 | + "with_assimp": [True, False], |
| 26 | + } |
| 27 | + default_options = { |
| 28 | + "shared": False, |
| 29 | + "fPIC": True, |
| 30 | + "with_sdl_ttf": True, |
| 31 | + "with_assimp": True, |
| 32 | + } |
| 33 | + implements = ["auto_shared_fpic"] |
| 34 | + |
| 35 | + def export_sources(self): |
| 36 | + export_conandata_patches(self) |
| 37 | + |
| 38 | + def configure(self): |
| 39 | + if self.options.shared: |
| 40 | + self.options.rm_safe("fPIC") |
| 41 | + |
| 42 | + def layout(self): |
| 43 | + cmake_layout(self, src_folder="src") |
| 44 | + |
| 45 | + def requirements(self): |
| 46 | + self.requires("glm/1.0.1") |
| 47 | + self.requires("glew/2.2.0") |
| 48 | + self.requires("sdl/2.28.3") |
| 49 | + self.requires("sdl_image/2.8.2") |
| 50 | + if self.options.with_sdl_ttf: |
| 51 | + self.requires("sdl_ttf/2.24.0") |
| 52 | + if self.options.with_assimp: |
| 53 | + self.requires("assimp/5.4.3") |
| 54 | + |
| 55 | + def build_requirements(self): |
| 56 | + self.tool_requires("cmake/[>=3.16 <4]") |
| 57 | + |
| 58 | + def source(self): |
| 59 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 60 | + apply_conandata_patches(self) |
| 61 | + |
| 62 | + def generate(self): |
| 63 | + tc = CMakeToolchain(self) |
| 64 | + tc.cache_variables["PACKAGE_BUILD_TESTS"] = False |
| 65 | + if is_msvc(self): |
| 66 | + tc.cache_variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) |
| 67 | + tc.generate() |
| 68 | + |
| 69 | + deps = CMakeDeps(self) |
| 70 | + deps.generate() |
| 71 | + |
| 72 | + def build(self): |
| 73 | + cmake = CMake(self) |
| 74 | + cmake.configure() |
| 75 | + cmake.build() |
| 76 | + |
| 77 | + def package(self): |
| 78 | + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) |
| 79 | + cmake = CMake(self) |
| 80 | + cmake.install() |
| 81 | + |
| 82 | + def package_info(self): |
| 83 | + self.cpp_info.set_property("cmake_file_name", "sgltk") |
| 84 | + self.cpp_info.set_property("cmake_target_name", "sgltk::sgltk") |
| 85 | + |
| 86 | + self.cpp_info.libs = ["sgltk" if self.options.shared else "sgltk_static"] |
| 87 | + |
| 88 | + reqs = [ |
| 89 | + "glm::glm", |
| 90 | + "glew::glew", |
| 91 | + "sdl::sdl", |
| 92 | + "sdl_image::sdl_image", |
| 93 | + ] |
| 94 | + if self.options.with_sdl_ttf: |
| 95 | + reqs.append("sdl_ttf::sdl_ttf") |
| 96 | + if self.options.with_assimp: |
| 97 | + reqs.append("assimp::assimp") |
| 98 | + |
| 99 | + self.cpp_info.requires = reqs |
0 commit comments