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

qxmpp: migrate to Conan v2 #18743

Merged
merged 14 commits into from
Jun 24, 2024
9 changes: 0 additions & 9 deletions recipes/qxmpp/all/CMakeLists.txt

This file was deleted.

10 changes: 6 additions & 4 deletions recipes/qxmpp/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ sources:
sha256: "2148162138eaf4b431a6ee94104f87877b85a589da803dff9433c698b4cf4f19"
patches:
"1.4.0":
- patch_file: "patches/001-add_conan_1.4.0.patch"
base_path: "source_subfolder"
- patch_file: "patches/002-add_gstreamer_1.4.0.patch"
base_path: "source_subfolder"
- patch_file: "patches/001-skip-module-path.patch"
patch_description: "Do not use module path provided by the upstream"
patch_type: "conan"
- patch_file: "patches/002-use-conan-gstreamer.patch"
patch_description: "Adapt to consume gstreamer from Conan"
patch_type: "conan"
119 changes: 73 additions & 46 deletions recipes/qxmpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
from conan import ConanFile
from conan.tools import files
from conans import CMake
import functools
import os

required_conan_version = ">=1.43.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, rename, mkdir
from conan.tools.microsoft import is_msvc
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.scm import Version

required_conan_version = ">=1.60.0 <2 || >=2.0.5"


class QxmppConan(ConanFile):
name = "qxmpp"
description = ("Cross-platform C++ XMPP client and server library. "
"It is written in C++ and uses Qt framework.")
license = "LGPL-2.1"
homepage = "https://github.com/qxmpp-project/qxmpp"
url = "https://github.com/conan-io/conan-center-index"
description = "Cross-platform C++ XMPP client and server library. It is written in C++ and uses Qt framework."
topics = "qt", "qt6", "xmpp", "xmpp-library", "xmpp-server", "xmpp-client"
homepage = "https://github.com/qxmpp-project/qxmpp"
topics = ("qt", "qt6", "xmpp", "xmpp-library", "xmpp-server", "xmpp-client")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -27,62 +34,84 @@ class QxmppConan(ConanFile):
"with_gstreamer": False,
}
uilianries marked this conversation as resolved.
Show resolved Hide resolved

generators = "cmake", "cmake_find_package_multi"
@property
def _min_cppstd(self):
return 17

@property
def _source_subfolder(self):
return "source_subfolder"
def _compilers_minimum_version(self):
return {
"gcc": "10",
"Visual Studio": "17",
"msvc": "192",
"clang": "8",
"apple-clang": "13",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

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

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

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

def requirements(self):
self.requires("qt/6.2.4")
self.requires("qt/[>=5.15 <7]", transitive_headers=True, transitive_libs=True)
if self.options.with_gstreamer:
self.requires("gstreamer/1.19.2")
self.requires("glib/2.70.1")
self.requires("gstreamer/1.22.6")
self.requires("glib/2.78.3")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")

def build_requirements(self):
self.tool_requires("qt/<host_version>")

uilianries marked this conversation as resolved.
Show resolved Hide resolved
def source(self):
files.get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()
venv = VirtualRunEnv(self)
venv.generate(scope="build")
tc = CMakeToolchain(self)
tc.variables["BUILD_DOCUMENTATION"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["WITH_GSTREAMER"] = self.options.with_gstreamer
tc.variables["BUILD_SHARED"] = self.options.get_safe("shared")
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()
tc = CMakeDeps(self)
tc.generate()

@functools.lru_cache(1)
def _configure_cmake(self):
def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.definitions["BUILD_DOCUMENTATION"] = "OFF"
cmake.definitions["BUILD_TESTS"] = "OFF"
cmake.definitions["BUILD_EXAMPLES"] = "OFF"
cmake.definitions["WITH_GSTREAMER"] = self.options.with_gstreamer
cmake.definitions["BUILD_SHARED"] = self.options.shared
cmake.configure()
return cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
files.patch(self, **patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE.LGPL", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE.LGPL", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
files.rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
files.rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

if self.options.shared and self.settings.os == "Windows":
files.mkdir(self, os.path.join(self.package_folder, "bin"))
files.rename(self, os.path.join(self.package_folder, "lib", "qxmpp.dll"),
os.path.join(self.package_folder, "bin", "qxmpp.dll"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
if is_msvc(self) and self.options.shared:
mkdir(self, os.path.join(self.package_folder, "bin"))
rename(self, os.path.join(self.package_folder, "lib", "qxmpp.dll"), os.path.join(self.package_folder, "bin", "qxmpp.dll"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "QXmpp")
Expand All @@ -91,7 +120,5 @@ def package_info(self):
self.cpp_info.libs = ["qxmpp"]
self.cpp_info.includedirs.append(os.path.join("include", "qxmpp"))
self.cpp_info.requires = ["qt::qtCore", "qt::qtNetwork", "qt::qtXml"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "QXmpp"
self.cpp_info.names["cmake_find_package_multi"] = "QXmpp"
if self.options.with_gstreamer:
self.cpp_info.requires.extend(["gstreamer::gstreamer", "glib::glib"])
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 550ea39a..9ed4d825 100644
index 550ea39..e550959 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,10 +8,12 @@ set(CMAKE_CXX_STANDARD 17)
@@ -8,10 +8,8 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules")

-find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Xml)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Xml)
-find_package(Qt${QT_VERSION_MAJOR} 5.7.0 REQUIRED COMPONENTS Core Network Xml)
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
+list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
+
+find_package(Qt6 COMPONENTS Core Network Xml REQUIRED)
+set(QT_VERSION_MAJOR 6)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
8 changes: 2 additions & 6 deletions recipes/qxmpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

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

find_package(QXmpp REQUIRED CONFIG)

set(CMAKE_CXX_STANDARD 17)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} QXmpp::QXmpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
22 changes: 16 additions & 6 deletions recipes/qxmpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +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", "cmake_find_package_multi"
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):
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")
2 changes: 2 additions & 0 deletions recipes/qxmpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <cstdlib>
#include <QXmppClient.h>
#include <QXmppLogger.h>

int main() {
QXmppClient client;
client.logger()->setLoggingType(QXmppLogger::StdoutLogging);
return EXIT_SUCCESS;
}
Loading