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

glib: refactor test package #24054

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 4 additions & 14 deletions recipes/glib/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

add_executable(${PROJECT_NAME} test_package.c)
find_package(glib CONFIG REQUIRED)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(glib CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glib::glib-2.0 glib::gio-2.0 glib::gmodule-2.0 glib::gobject-2.0 glib::gthread-2.0)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(glib-2.0 REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(gio-2.0 REQUIRED IMPORTED_TARGET gio-2.0)
pkg_check_modules(gmodule-2.0 REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject-2.0 REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread-2.0 REQUIRED IMPORTED_TARGET gthread-2.0)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
endif()
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE glib::glib-2.0 glib::gio-2.0 glib::gmodule-2.0 glib::gobject-2.0 glib::gthread-2.0)
37 changes: 3 additions & 34 deletions recipes/glib/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps, CMakeToolchain
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.gnu import PkgConfig, PkgConfigDeps
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
Expand All @@ -16,33 +15,6 @@ def layout(self):
def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
if self.settings.os != "Windows" and not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/2.0.3")

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
virtual_run_env = VirtualRunEnv(self)
virtual_run_env.generate()

if self.settings.os == "Macos":
env = Environment()
# Avoid conflicts with system libiconv
# see: https://github.com/conan-io/conan-center-index/pull/17610#issuecomment-1552921286
env.define_path("DYLD_FALLBACK_LIBRARY_PATH", "$DYLD_LIBRARY_PATH")
env.define_path("DYLD_LIBRARY_PATH", "")
env.vars(self, scope="run").save_script("conanrun_macos_runtimepath")
Comment on lines -29 to -35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if self.settings.os == "Windows":
deps = CMakeDeps(self)
deps.generate()
else:
virtual_build_env = VirtualBuildEnv(self)
virtual_build_env.generate()
pkg_config_deps = PkgConfigDeps(self)
pkg_config_deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
Expand All @@ -52,8 +24,5 @@ def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

if self.settings.os != "Windows":
pkg_config = PkgConfig(self, "gio-2.0", pkg_config_path=self.generators_folder)
gdbus_codegen = pkg_config.variables["gdbus_codegen"]
self.run(f"{gdbus_codegen} -h", env="conanrun")
self.run("gdbus-codegen -h", env="conanrun")
2 changes: 1 addition & 1 deletion recipes/glib/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand Down
20 changes: 6 additions & 14 deletions recipes/glib/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@

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

def build_requirements(self):
if self.settings.os != "Windows":
self.tool_requires("pkgconf/2.0.3")
generators = "cmake", "cmake_find_package_multi"

def build(self):
if self.settings.os != "Windows":
with tools.environment_append({'PKG_CONFIG_PATH': "."}):
pkg_config = tools.PkgConfig("gio-2.0")
self.run(f"{pkg_config.variables['gdbus_codegen']} -h", run_environment=True)

with tools.environment_append({'PKG_CONFIG_PATH': "."}):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if self.settings.os != "Windows":
self.run("gdbus-codegen -h", env="conanrun")
Loading