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

add qt cmake macros #4577

Merged
merged 3 commits into from
Feb 19, 2021
Merged
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
17 changes: 16 additions & 1 deletion recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ def package(self):
if not self.options.get_safe(module):
tools.rmdir(os.path.join(self.package_folder, "licenses", module))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
for mask in ["Find*.cmake", "*Config.cmake", "*-config.cmake"]:
tools.remove_files_by_mask(self.package_folder, mask)
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.pdb*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
Expand Down Expand Up @@ -695,6 +696,20 @@ def package_info(self):
self.cpp_info.frameworks.extend(["Cocoa"]) # "libQt5Core.a" require "_OBJC_CLASS_$_NSApplication" and more, which are in "Cocoa" framework
self.cpp_info.frameworks.extend(["Security"]) # "libQt5Core.a" require "_SecRequirementCreateWithString" and more, which are in "Security" framework

tools.save(os.path.join("lib", "cmake", "Qt5Core", "extras.cmake"),
"set(Qt5Core_QMAKE_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../../../bin/qmake)\n"
"set(Qt5Core_MOC_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../../../bin/moc)\n"
"set(Qt5Core_RCC_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../../../bin/rcc)\n"
"set(Qt5Core_UIC_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../../../bin/uic)")
Copy link
Contributor Author

@ericLemanissier ericLemanissier Feb 17, 2021

Choose a reason for hiding this comment

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

TLDR: Would it be ok to provide cmake targets in Qt5:: namespace (using this build module) whereas conan generated target are in the qt:: namespace ?

Director's cut: With the change as it is now, the user has to manually call qt5_wrap_cpp on the sources in the CMakeLists.txt. Most projects do not use this, but instead rely on CMAKE_AUTOMOC, which automatically invokes MOC on sources of all targets. This currently does not work, because cmake tries to invoke the target Qt5::moc, which does not exist. Would it be fine if I added this add_executable(Qt5::moc IMPORTED); set_target_properties(Qt5::moc PROPERTIES IMPORTED_LOCATION ${Qt5Core_QMAKE_EXECUTABLE}) ? I'm not sure because all the targets generated by conan are in the qt namespace, not in the Qt5 namespace, and I don't want to make this shift without components support.

WDYT ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is what is making my PR fail
#4562

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes: take a look at ericriff#5

for m in os.listdir(os.path.join("lib", "cmake")):
module = os.path.join("lib", "cmake", m, "%sMacros.cmake" % m)
if os.path.isfile(module):
self.cpp_info.build_modules.append(module)
self.cpp_info.builddirs.append(os.path.join("lib", "cmake", m))
else:
tools.rmdir(os.path.join("lib", "cmake", m))
self.cpp_info.build_modules.append(os.path.join("lib", "cmake", "Qt5Core", "extras.cmake"))


@staticmethod
def _remove_duplicate(l):
Expand Down
8 changes: 7 additions & 1 deletion recipes/qt/5.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ conan_output_dirs_setup()

find_package(qt REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp greeter.h moc_greeter.cpp)

set(SOURCES test_package.cpp)
qt5_wrap_cpp(SOURCES greeter.h)

qt5_add_resources(SOURCES example.qrc)

add_executable(${PROJECT_NAME} ${SOURCES})
# Must compile with "-fPIC" since Qt was built with -reduce-relocations.
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)

Expand Down
1 change: 0 additions & 1 deletion recipes/qt/5.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _build_with_cmake_find_package_multi(self):
if self.settings.os == "Macos":
cmake.definitions['CMAKE_OSX_DEPLOYMENT_TARGET'] = '10.14'

self.run("moc %s -o moc_greeter.cpp" % os.path.join(self.source_folder, "greeter.h"), run_environment=True)
cmake.configure()
cmake.build()

Expand Down
5 changes: 5 additions & 0 deletions recipes/qt/5.x.x/test_package/example.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource>
<file>resource.txt</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion recipes/qt/5.x.x/test_package/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project('test_package', 'cpp')
qt5 = import('qt5')
qt5_dep = dependency('qt5', modules: ['Core'])
moc_files = qt5.preprocess(moc_headers : 'greeter.h')
moc_files = qt5.preprocess(moc_headers : 'greeter.h', qresources : 'example.qrc')
executable('test_package', 'test_package.cpp', moc_files,
dependencies : qt5_dep)
1 change: 1 addition & 0 deletions recipes/qt/5.x.x/test_package/resource.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World From Resource
7 changes: 7 additions & 0 deletions recipes/qt/5.x.x/test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QString>
#include <QTimer>
#include "greeter.h"
#include <QFile>

int main(int argc, char *argv[]){
QCoreApplication app(argc, argv);
Expand All @@ -18,5 +19,11 @@ int main(int argc, char *argv[]){
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();

return app.exec();
}
2 changes: 2 additions & 0 deletions recipes/qt/5.x.x/test_package/test_package.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ SOURCES += test_package.cpp

HEADERS += greeter.h

RESOURCES = example.qrc

QT -= gui

CONFIG += console