Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New recipe: imgui-sfml #24874

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/imgui-sfml/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.6":
url: "https://github.com/SFML/imgui-sfml/archive/refs/tags/v2.6.tar.gz"
sha256: "b1195ca1210dd46c8049cfc8cae7f31cd34f1591da7de1c56297b277ac9c5cc0"
92 changes: 92 additions & 0 deletions recipes/imgui-sfml/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file, rm, rmdir, mkdir

Check warning on line 4 in recipes/imgui-sfml/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused mkdir imported from conan.tools.files
import os


required_conan_version = ">=1.53.0"


class ImGuiSFMLConan(ConanFile):
name = "imgui-sfml"
description = "ImGui-SFML integrates Dear ImGui with SFML, enabling easy creation of GUIs for SFML applications."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/SFML/imgui-sfml"
topics = ("gui", "graphical", "sfml", "imgui")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 11

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("sfml/2.6.1", transitive_headers=True)
self.requires("imgui/1.91.0")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
self.requires("opengl/system")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["IMGUI_DIR"] = self.dependencies["imgui"].package_folder
tc.variables["IMGUI_INCLUDE_DIR"] = self.dependencies["imgui"].cpp_info.includedir
tc.generate()

tc = CMakeDeps(self)
tc.set_property("imgui", "cmake_file_name", "ImGui")
tc.generate()

def _patch_sources(self):
# This is a workaround to avoid installing vendorized imgui headers as well to the package folder
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), 'list(APPEND IMGUI_SFML_PUBLIC_HEADERS "${IMGUI_PUBLIC_HEADERS}")', "")
ErniGH marked this conversation as resolved.
Show resolved Hide resolved

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["ImGui-SFML"]

self.cpp_info.set_property("cmake_file_name", "ImGui-SFML")
self.cpp_info.set_property("cmake_target_name", "ImGui-SFML::ImGui-SFML")
9 changes: 9 additions & 0 deletions recipes/imgui-sfml/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)

project(test_package LANGUAGES CXX)

find_package(ImGui-SFML REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ImGui-SFML::ImGui-SFML)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
27 changes: 27 additions & 0 deletions recipes/imgui-sfml/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
6 changes: 6 additions & 0 deletions recipes/imgui-sfml/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "imgui-SFML.h"

int main() {
ImGui::SFML::Shutdown();
return 0;
}
3 changes: 3 additions & 0 deletions recipes/imgui-sfml/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.6":
folder: all
Loading