|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +import os.path |
| 5 | +from conans import ConanFile, CMake |
| 6 | +from conans.tools import Git |
| 7 | +from conans.errors import ConanInvalidConfiguration |
| 8 | + |
| 9 | +class ImguiSfmlConan(ConanFile): |
| 10 | + """ Imgui-SFML library conan file. |
| 11 | +
|
| 12 | + Options: |
| 13 | +
|
| 14 | + * shared: True or False |
| 15 | + Whether to build this library shared or static. |
| 16 | +
|
| 17 | + * fPIC: True or False |
| 18 | + Whether or not to use -fPIC option while building. |
| 19 | +
|
| 20 | + * imconfig: None or String |
| 21 | + Use 'None' if you want this library to provide default |
| 22 | + ImGui's imconfig.h file. Otherwise, provide a path to the |
| 23 | + imconfig.h file you want to include in the build. |
| 24 | +
|
| 25 | + * imconfig_install_folder: None or String |
| 26 | + Use 'None' if you want this build to include custom config |
| 27 | + file, otherwise specify the directory where your imconfig |
| 28 | + will be installed. |
| 29 | +
|
| 30 | + * imgui_revision: String |
| 31 | + Tag or branch of ImGui repository that should be used with |
| 32 | + ImGui-SFML. |
| 33 | + """ |
| 34 | + |
| 35 | + name = 'imgui-sfml' |
| 36 | + version = '2.0.2' |
| 37 | + description = 'ImGui binding for use with SFML' |
| 38 | + topics = ('conan', 'sfml', 'gui', 'imgui') |
| 39 | + url = 'https://github.com/eliasdaler/imgui-sfml' |
| 40 | + homepage = 'https://github.com/eliasdaler/imgui-sfml' |
| 41 | + author = 'Elias Daler <[email protected]>' |
| 42 | + requires = 'sfml/2.5.1@bincrafters/stable' |
| 43 | + license = 'MIT' |
| 44 | + settings = 'os', 'compiler', 'build_type', 'arch' |
| 45 | + options = { |
| 46 | + 'shared': [True, False], |
| 47 | + 'fPIC': [True, False], |
| 48 | + 'imconfig': 'ANY', |
| 49 | + 'imconfig_install_folder': 'ANY', |
| 50 | + 'imgui_revision': 'ANY' |
| 51 | + } |
| 52 | + default_options = { |
| 53 | + 'shared': False, |
| 54 | + 'fPIC': True, |
| 55 | + 'imconfig': None, |
| 56 | + 'imconfig_install_folder': None, |
| 57 | + 'imgui_revision': 'v1.70' |
| 58 | + } |
| 59 | + exports_sources = [ |
| 60 | + 'cmake/FindImGui.cmake', |
| 61 | + 'CMakeLists.txt', |
| 62 | + 'imconfig-SFML.h', |
| 63 | + 'imgui-SFML.cpp', |
| 64 | + 'imgui-SFML_export.h', |
| 65 | + 'imgui-SFML.h', |
| 66 | + ] |
| 67 | + exports = 'LICENSE' |
| 68 | + _imgui_dir = 'imgui' |
| 69 | + |
| 70 | + def source(self): |
| 71 | + git = Git(folder=self._imgui_dir) |
| 72 | + git.clone('https://github.com/ocornut/imgui.git', str(self.options.imgui_revision)) |
| 73 | + |
| 74 | + def configure(self): |
| 75 | + imconfig = self.options.imconfig |
| 76 | + if imconfig: |
| 77 | + if not os.path.isfile(str(imconfig)): |
| 78 | + raise ConanInvalidConfiguration("Provided user config is not a file or doesn't exist") |
| 79 | + else: |
| 80 | + self._imconfig_path = os.path.abspath(str(self.options.imconfig)) |
| 81 | + if not self.options.imgui_revision: |
| 82 | + raise ConanInvalidConfiguration("ImGui revision is empty. Try latest version tag or 'master'") |
| 83 | + |
| 84 | + self.options['sfml'].graphics = True |
| 85 | + self.options['sfml'].window = True |
| 86 | + self.options['sfml'].shared = self.options.shared |
| 87 | + |
| 88 | + def _configure_cmake(self): |
| 89 | + cmake = CMake(self) |
| 90 | + cmake.definitions['IMGUI_DIR'] = os.path.join(self.source_folder, self._imgui_dir) |
| 91 | + cmake.definitions['SFML_DIR'] = os.path.join(self.deps_cpp_info['sfml'].lib_paths[0], 'cmake', 'SFML') |
| 92 | + cmake.definitions['IMGUI_SFML_BUILD_EXAMPLES'] = 'OFF' |
| 93 | + cmake.definitions['IMGUI_SFML_FIND_SFML'] = 'ON' |
| 94 | + if self.options.imconfig_install_folder: |
| 95 | + cmake.definitions['IMGUI_SFML_CONFIG_INSTALL_DIR'] = self.options.imconfig_install_folder |
| 96 | + if self.options.imconfig: |
| 97 | + cmake.definitions['IMGUI_SFML_USE_DEFAULT_CONFIG'] = 'OFF' |
| 98 | + cmake.definitions['IMGUI_SFML_CONFIG_NAME'] = os.path.basename(self._imconfig_path) |
| 99 | + cmake.definitions['IMGUI_SFML_CONFIG_DIR'] = os.path.dirname(self._imconfig_path) |
| 100 | + else: |
| 101 | + cmake.definitions['IMGUI_SFML_USE_DEFAULT_CONFIG'] = 'ON' |
| 102 | + cmake.configure() |
| 103 | + return cmake |
| 104 | + |
| 105 | + def build(self): |
| 106 | + cmake = self._configure_cmake() |
| 107 | + cmake.build() |
| 108 | + |
| 109 | + def package(self): |
| 110 | + cmake = self._configure_cmake() |
| 111 | + cmake.install() |
| 112 | + |
| 113 | + def package_info(self): |
| 114 | + self.cpp_info.libs = ['ImGui-SFML'] |
0 commit comments