Skip to content

Commit

Permalink
libui: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 20, 2023
1 parent e9bdd35 commit 01d2523
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 72 deletions.
7 changes: 0 additions & 7 deletions recipes/libui/all/CMakeLists.txt

This file was deleted.

126 changes: 73 additions & 53 deletions recipes/libui/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,99 @@
from conans import ConanFile, CMake, tools
from conans.tools import os_info
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import collect_libs, copy, get
from conan.tools.gnu import PkgConfigDeps

required_conan_version = ">=1.53.0"


class libuiConan(ConanFile):
name = "libui"
description = "Simple and portable GUI library in C that uses the native GUI technologies of each platform it supports."
topics = ("conan", "libui", "ui", "gui")
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/andlabs/libui"
license = "MIT"
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "pkg_config"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

@property
def _source_subfolder(self):
return "source_subfolder"
topics = ("ui", "gui")

@property
def _build_subfolder(self):
return "build_subfolder"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")
if self.settings.os in ["Linux", "FreeBSD"]:
self.options["gtk"].version = 3

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("gtk/3.24.24")
if self.settings.os in ["Linux", "FreeBSD"]:
self.requires("gtk/system")

def _configure_cmake(self):
cmake = CMake(self)
cmake.configure(build_folder=self._build_subfolder)
return cmake
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()
tc = PkgConfigDeps(self)
tc.generate()

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

def package(self):
self.copy(pattern="LICENSE", dst="licenses",
src=self._source_subfolder)
self.copy(pattern="*.h", dst="include", src=self._source_subfolder)
self.copy(pattern="*.dll", dst="bin", keep_path=False)
self.copy(pattern="*.lib", dst="lib", keep_path=False)
self.copy(pattern="*.a", dst="lib", keep_path=False)
self.copy(pattern="*.so*", dst="lib", keep_path=False)
self.copy(pattern="*.dylib", dst="lib", keep_path=False)
copy(self, "LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self, "*.h",
dst=os.path.join(self.package_folder, "include"),
src=self.source_folder)
copy(self, "*.dll",
dst=os.path.join(self.package_folder, "bin"),
src=self.build_folder,
keep_path=False)
for pattern in ["*.a", "*.so*", "*.dylib*", "*.lib"]:
copy(self, pattern,
dst=os.path.join(self.package_folder, "lib"),
src=self.build_folder,
keep_path=False)

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(
[
"user32",
"kernel32",
"gdi32",
"comctl32",
"msimg32",
"comdlg32",
"d2d1",
"dwrite",
"ole32",
"oleaut32",
"oleacc",
"uuid",
"windowscodecs",
]
)
self.cpp_info.libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs += ["dl"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs += [
"user32",
"kernel32",
"gdi32",
"comctl32",
"msimg32",
"comdlg32",
"d2d1",
"dwrite",
"ole32",
"oleaut32",
"oleacc",
"uuid",
"windowscodecs",
]
8 changes: 3 additions & 5 deletions recipes/libui/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)


include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(libui REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE libui::libui)
21 changes: 15 additions & 6 deletions recipes/libui/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
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 not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 7 additions & 1 deletion recipes/libui/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ui.h"
#include <stdio.h>

int main(void)
void init_ui(void)
{
uiInitOptions o;

Expand All @@ -17,5 +17,11 @@ int main(void)

uiMain();
uiUninit();
}

int main(void)
{
// Do not actually create the UI in this test
// init_ui();
return 0;
}
8 changes: 8 additions & 0 deletions recipes/libui/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/libui/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 01d2523

Please sign in to comment.