[DO-981] qt package (!15)
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/15
This commit is contained in:
18
recipes/qt/6.x.x/test_package/CMakeLists.txt
Normal file
18
recipes/qt/6.x.x/test_package/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(test_package LANGUAGES CXX)
|
||||
|
||||
find_package(Qt6 COMPONENTS Core Network Sql Concurrent Xml REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp greeter.h example.qrc)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Network Qt6::Sql Qt6::Concurrent Qt6::Xml Qt6::Widgets)
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON AUTORCC ON)
|
||||
|
||||
# Only running this Qt macros in macOS
|
||||
if (APPLE)
|
||||
# Related to https://github.com/conan-io/conan-center-index/issues/20574
|
||||
qt_standard_project_setup()
|
||||
qt_add_executable(test_macos_bundle MACOSX_BUNDLE test_macos_bundle.cpp)
|
||||
target_link_libraries(test_macos_bundle PRIVATE Qt6::Core)
|
||||
target_compile_features(test_macos_bundle PRIVATE cxx_std_17)
|
||||
endif()
|
||||
47
recipes/qt/6.x.x/test_package/conanfile.py
Normal file
47
recipes/qt/6.x.x/test_package/conanfile.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
from conan.tools.env import VirtualRunEnv
|
||||
from conan.tools.files import copy, save
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str, run=can_run(self))
|
||||
|
||||
def build_requirements(self):
|
||||
if not can_run(self):
|
||||
self.tool_requires(self.tested_reference_str)
|
||||
|
||||
def generate(self):
|
||||
path = self.dependencies["qt"].package_folder.replace("\\", "/")
|
||||
save(self, "qt.conf", f"""[Paths]
|
||||
Prefix = {path}""")
|
||||
|
||||
VirtualRunEnv(self).generate()
|
||||
if can_run(self):
|
||||
VirtualRunEnv(self).generate(scope="build")
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if can_run(self):
|
||||
copy(self, "qt.conf", src=self.generators_folder, dst=os.path.join(self.cpp.build.bindirs[0]))
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(bin_path, env="conanrun")
|
||||
# Related to https://github.com/conan-io/conan-center-index/issues/20574
|
||||
if self.settings.os == "Macos":
|
||||
bin_macos_path = os.path.join(self.cpp.build.bindirs[0], "test_macos_bundle.app", "Contents", "MacOS", "test_macos_bundle")
|
||||
self.run(bin_macos_path, env="conanrun")
|
||||
5
recipes/qt/6.x.x/test_package/example.qrc
Normal file
5
recipes/qt/6.x.x/test_package/example.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource>
|
||||
<file>resource.txt</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
26
recipes/qt/6.x.x/test_package/greeter.h
Normal file
26
recipes/qt/6.x.x/test_package/greeter.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class Greeter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Greeter(const QString& name, QObject *parent = 0)
|
||||
: QObject(parent)
|
||||
, mName(name) {}
|
||||
|
||||
public slots:
|
||||
void run()
|
||||
{
|
||||
qDebug() << QString("Hello %1!").arg(mName);
|
||||
|
||||
emit finished();
|
||||
}
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
const QString& mName;
|
||||
};
|
||||
1
recipes/qt/6.x.x/test_package/resource.txt
Normal file
1
recipes/qt/6.x.x/test_package/resource.txt
Normal file
@@ -0,0 +1 @@
|
||||
Hello World From Resource
|
||||
7
recipes/qt/6.x.x/test_package/test_macos_bundle.cpp
Normal file
7
recipes/qt/6.x.x/test_package/test_macos_bundle.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <QCoreApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
48
recipes/qt/6.x.x/test_package/test_package.cpp
Normal file
48
recipes/qt/6.x.x/test_package/test_package.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QFile>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QSqlDatabase>
|
||||
#include <qtconcurrentfilter.h>
|
||||
#include <QDomText>
|
||||
|
||||
#include "greeter.h"
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setApplicationName("Application Example");
|
||||
QCoreApplication::setApplicationVersion("1.0.0");
|
||||
|
||||
QString name = argc > 0 ? argv[1] : "";
|
||||
if (name.isEmpty()) {
|
||||
name = "World";
|
||||
}
|
||||
|
||||
Greeter* greeter = new Greeter(name, &app);
|
||||
QObject::connect(greeter, SIGNAL(finished()), &app, SLOT(quit()));
|
||||
QTimer::singleShot(0, greeter, SLOT(run()));
|
||||
|
||||
QFile f(":/resource.txt");
|
||||
if(!f.open(QIODevice::ReadOnly))
|
||||
qFatal("Could not open resource file");
|
||||
qDebug() << "Resource content:" << f.readAll();
|
||||
f.close();
|
||||
|
||||
QNetworkAccessManager networkTester;
|
||||
|
||||
QSqlDatabase sqlTester;
|
||||
|
||||
QVector<int> v;
|
||||
v << 1 << 2 << 3 << 4;
|
||||
QtConcurrent::blockingFilter(v, [](int i)
|
||||
{
|
||||
return i % 2;
|
||||
});
|
||||
|
||||
QDomText xmlTester;
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user