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

qcoro: migrate to Conan v2 #18837

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions recipes/qcoro/all/CMakeLists.txt

This file was deleted.

6 changes: 3 additions & 3 deletions recipes/qcoro/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sources:
"0.4.0":
url: "https://github.com/danvratil/qcoro/archive/refs/tags/v0.4.0.tar.gz"
sha256: "0e68b3f0ce7bf521ffbdd731464d2d60d8d7a39a749b551ed26855a1707d86d1"
"0.10.0":
url: "https://github.com/danvratil/qcoro/archive/refs/tags/v0.10.0.tar.gz"
sha256: "b7c8f00273ad27d85814bf4ec93eb6922c75656800a61d11854d36355a4a1aec"
209 changes: 109 additions & 100 deletions recipes/qcoro/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, can_run
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, replace_in_file, rmdir
from conan.tools.scm import Version

required_conan_version = ">=2.0.9"


class QCoroConan(ConanFile):
name = "qcoro"
description = "C++ Coroutines for Qt."
license = "MIT"
homepage = "https://github.com/danvratil/qcoro"
url = "https://github.com/conan-io/conan-center-index"
description = "C++ Coroutines for Qt."
homepage = "https://github.com/danvratil/qcoro"
topics = ("coroutines", "qt")
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -23,124 +30,126 @@ class QCoroConan(ConanFile):
"fPIC": True,
"asan": False,
}
generators = "cmake", "cmake_find_package_multi"
exports_sources = ["CMakeLists.txt"]
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
implements = ["auto_shared_fpic"]

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

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

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

def build_requirements(self):
self.build_requires("cmake/3.23.2")
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("qt/6.3.1")
self.requires("qt/[>=5.15 <7]", transitive_headers=True, transitive_libs=True, run=can_run(self))

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

def lazy_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
lv2 = [int(v) for v in v2.split(".")]
min_length = min(len(lv1), len(lv2))
return lv1[:min_length] < lv2[:min_length]

#Special check for clang that can only be linked to libc++
check_min_cppstd(self, 20)
# Special check for clang that can only be linked to libc++
if self.settings.compiler == "clang" and self.settings.compiler.libcxx != "libc++":
raise ConanInvalidConfiguration("imagl requires some C++20 features, which are available in libc++ for clang compiler.")
raise ConanInvalidConfiguration(
"qcoro requires some C++20 features, which are only available in libc++ for clang compiler."
)

compiler_version = str(self.settings.compiler.version)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn("qcoro requires C++20. Your compiler is unknown. Assuming it supports C++20.")
elif lazy_lt_semver(compiler_version, minimum_version):
raise ConanInvalidConfiguration("qcoro requires some C++20 features, which your {} {} compiler does not support.".format(str(self.settings.compiler), compiler_version))
else:
print("Your compiler is {} {} and is compatible.".format(str(self.settings.compiler), compiler_version))
if minimum_version and Version(compiler_version) < minimum_version:
raise ConanInvalidConfiguration(
f"qcoro requires some C++20 features, which your {str(self.settings.compiler)} "
f"{compiler_version} compiler does not support."
)

def build_requirements(self):
self.tool_requires("cmake/[>=3.23 <4]")
if not can_run(self):
self.tool_requires("qt/<host_version>")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)
replace_in_file(self, os.path.join(self.source_folder, "cmake", "ECMQueryQt.cmake"),
"get_target_property(_qtpaths_executable Qt6::qtpaths LOCATION)",
"set(_qtpaths_executable qtpaths)")

def _configure_cmake(self):
if self._cmake:
return self._cmake
@property
def _with_qml(self):
return self.dependencies["qt"].options.get_safe("qtdeclarative", False)

self._cmake = CMake(self)
@property
def _with_dbus(self):
return self.dependencies["qt"].options.get_safe("with_dbus", False)

self._cmake.definitions["QCORO_BUILD_EXAMPLES"] = False
self._cmake.definitions["QCORO_ENABLE_ASAN"] = self.options.asan
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.definitions["QCORO_WITH_QTDBUS"] = self.options["qt"].with_dbus
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
@property
def _with_quick(self):
return (self.dependencies["qt"].options.get_safe("gui", False) and
self.dependencies["qt"].options.get_safe("qtshadertools", False))

@property
def _with_websockets(self):
return self.dependencies["qt"].options.get_safe("qtwebsockets", False)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["QCORO_BUILD_EXAMPLES"] = False
tc.variables["QCORO_ENABLE_ASAN"] = self.options.asan
tc.variables["BUILD_TESTING"] = False
tc.variables["USE_QT_VERSION"] = self.dependencies["qt"].ref.version.major
tc.variables["QCORO_WITH_QML"] = self._with_qml
tc.variables["QCORO_WITH_QTDBUS"] = self._with_qml
tc.variables["QCORO_WITH_QTQUICK"] = self._with_quick
tc.variables["QCORO_WITH_QTWEBSOCKETS"] = self._with_websockets
tc.generate()
deps = CMakeDeps(self)
deps.generate()

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

def package(self):
self.copy("*", dst="licenses", src=os.path.join(self._source_subfolder, "LICENSES"))
cmake = self._configure_cmake()
copy(self, "*",
src=os.path.join(self.source_folder, "LICENSES"),
dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "mkspecs"))
for mask in ["Find*.cmake", "*Config*.cmake", "*-config.cmake", "*Targets*.cmake"]:
tools.remove_files_by_mask(self.package_folder, mask)
rm(self, mask, self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "QCoro6"
self.cpp_info.filenames["cmake_find_package_multi"] = "QCoro6"
self.cpp_info.set_property("cmake_file_name", "QCoro6")
self.cpp_info.names["cmake_find_package"] = "QCoro"
self.cpp_info.names["cmake_find_package_multi"] = "QCoro"

self.cpp_info.components["qcoro-core"].set_property("cmake_target_name", "QCoro::Core")
self.cpp_info.components["qcoro-core"].names["cmake_find_package"] = "Core"
self.cpp_info.components["qcoro-core"].names["cmake_find_package_multi"] = "Core"
self.cpp_info.components["qcoro-core"].libs = ["QCoro6Core"]
self.cpp_info.components["qcoro-core"].includedirs.append(os.path.join("include", "qcoro6", "qcoro"))
self.cpp_info.components["qcoro-core"].requires = ["qt::qtCore"]
self.cpp_info.components["qcoro-core"].build_modules["cmake_find_package"].append(os.path.join("lib", "cmake", "QCoro6Coro", "QCoroMacros.cmake"))
self.cpp_info.components["qcoro-core"].build_modules["cmake_find_package_multi"].append(os.path.join("lib", "cmake", "QCoro6Coro", "QCoroMacros.cmake"))
self.cpp_info.components["qcoro-core"].builddirs.append(os.path.join("lib", "cmake", "QCoro6Coro"))

self.cpp_info.components["qcoro-network"].set_property("cmake_target_name", "QCoro::Network")
self.cpp_info.components["qcoro-network"].names["cmake_find_package"] = "Network"
self.cpp_info.components["qcoro-network"].names["cmake_find_package_multi"] = "Network"
self.cpp_info.components["qcoro-network"].libs = ["QCoro6Network"]
self.cpp_info.components["qcoro-network"].requires = ["qt::qtNetwork"]

if self.options["qt"].with_dbus:
self.cpp_info.components["qcoro-dbus"].set_property("cmake_target_name", "QCoro::DBus")
self.cpp_info.components["qcoro-dbus"].names["cmake_find_package"] = "DBus"
self.cpp_info.components["qcoro-dbus"].names["cmake_find_package_multi"] = "DBus"
self.cpp_info.components["qcoro-dbus"].libs = ["QCoroDBus"]
self.cpp_info.components["qcoro-core"].requires = ["qt::qtDBus"]
qt_major = self.dependencies["qt"].ref.version.major
name = f"QCoro{qt_major}"
self.cpp_info.set_property("cmake_file_name", name)
self.cpp_info.set_property("cmake_target_name", f"{name}::{name}")

def _add_module(module_name, requires=None, interface=False):
component = self.cpp_info.components[module_name.lower()]
component.set_property("cmake_target_name", f"{name}::{module_name}")
if not interface:
component.libs = [f"{name}{module_name}"]
component.includedirs.append(os.path.join("include", f"qcoro{qt_major}", "qcoro"))
component.requires = requires or []

_add_module("Coro", interface=True)
_add_module("Core", requires=["coro", "qt::qtCore"])
_add_module("Network", requires=["coro", "core", "qt::qtCore", "qt::qtNetwork"])
if is_apple_os(self):
self.cpp_info.components["network"].frameworks = ["CFNetwork"]
_add_module("Test", requires=["qt::qtTest"], interface=True)
if self._with_dbus:
_add_module("DBus", requires=["coro", "core", "qt::qtCore", "qt::qtDBus"])
if self._with_qml:
_add_module("Qml", requires=["coro", "qt::qtCore", "qt::qtQml"])
if self._with_quick:
_add_module("Quick", requires=["coro", "core", "qt::qtCore", "qt::qtGui", "qt::qtQuick"])
if self._with_websockets:
_add_module("WebSockets", requires=["coro", "core", "qt::qtCore", "qt::qtNetwork", "qt::qtWebSockets"])

self.cpp_info.builddirs.append(os.path.join("lib", "cmake", f"{name}Coro"))
macros_cmake_path = os.path.join("lib", "cmake", f"{name}Coro", "QCoroMacros.cmake")
self.cpp_info.set_property("cmake_build_modules", [macros_cmake_path])
18 changes: 10 additions & 8 deletions recipes/qcoro/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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(QCoro6 REQUIRED COMPONENTS Core)
qcoro_enable_coroutines()

if(MSVC)
# Qt6Core.lib(qlocale_win.cpp.obj) : error LNK2038: mismatch detected for '_COROUTINE_ABI': value '1' doesn't match value '2' in test_package.obj
# https://stackoverflow.com/questions/70348706/error-lnk2038-mismatch-detected-for-coroutine-abi-value-2-doesnt-match-v
# https://devblogs.microsoft.com/oldnewthing/20230111-00/?p=107694
add_compile_definitions(_ALLOW_COROUTINE_ABI_MISMATCH)
endif()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} QCoro::Core
Qt6::Core
Qt6::Concurrent)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME} QCoro6::Core Qt6::Concurrent)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
20 changes: 14 additions & 6 deletions recipes/qcoro/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
from conan import ConanFile
from conan.tools.build import cross_building
from conans import CMake
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

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

def layout(self):
cmake_layout(self)

def build_requirements(self):
self.build_requires("cmake/3.23.2")
self.tool_requires("cmake/[>=3.23 <4]")

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

def test(self):
if not cross_building(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
35 changes: 3 additions & 32 deletions recipes/qcoro/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
// SPDX-FileCopyrightText: 2021 Daniel Vrátil <[email protected]>
//
// SPDX-License-Identifier: MIT

#include "qcorofuture.h"

#include <QCoreApplication>
#include <QTimer>
#include <qcorofuture.h>
#include <QtConcurrent>

#include <iostream>
#include <random>

QCoro::Task<> startTask() {
const auto data = co_await QtConcurrent::run([]() {
QVector<std::uint64_t> data;
std::random_device rd{};
std::mt19937 gen{rd()};
data.reserve(10'000'000);
for (int i = 0; i < 10'000'000; ++i) {
data.push_back(gen());
}
return data;
return 0;
});

std::cout << "Generated " << data.size() << " random numbers" << std::endl;

const auto sum = co_await QtConcurrent::filteredReduced<std::uint64_t>(
data, [](const auto &) { return true; },
[](std::uint64_t &interm, std::uint64_t val) { interm += val; },
QtConcurrent::UnorderedReduce);

std::cout << "Calculated result: " << sum << std::endl;
qApp->quit();
}

int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
QTimer::singleShot(0, startTask);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep this call to be able to ensure the compiler is not optimizing away the whole function declaration

return app.exec();
return 0;
}
8 changes: 8 additions & 0 deletions recipes/qcoro/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/)
Loading