Skip to content

Commit

Permalink
(#4577) add qt cmake macros
Browse files Browse the repository at this point in the history
* add qt cmake macros

fixes #4574

* compatibility with conan < 1.33

* setup self.cpp_info.builddirs

and remove unused cmake files
  • Loading branch information
ericLemanissier authored Feb 19, 2021
1 parent aa1d93f commit c78f6f3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
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"]:

This comment has been minimized.

Copy link
@NewProggie

NewProggie Apr 24, 2021

@ericLemanissier Hey, this change basically killed this Conan package to be consumed in any sensible way using ordinary CMake (e.g. find_package()). What is the reason that Qt5Config.cmake etc. got removed during the packaging step?

This comment has been minimized.

Copy link
@ericLemanissier

ericLemanissier Apr 24, 2021

Author Contributor

More cmake files were deleted before this change than after, so I'm surprised you see a degradation here. Regarding the "why", please refer to https://github.com/conan-io/conan-center-index/blob/master/docs/faqs.md#why-are-cmake-findconfig-files-and-pkg-config-files-not-packaged

This comment has been minimized.

Copy link
@NiceBlueChai

NiceBlueChai May 24, 2024

This change leads to no execution Qt5CoreConfigExtras.cmake, some configuration is not set correctly, such as QT_NO_DEBUG not define in the Release version is correct

This comment has been minimized.

Copy link
@ericLemanissier

ericLemanissier May 24, 2024

Author Contributor

@NiceBlueChai pull request 24009 is reintroducing QT_NO_DEBUG for qt5. If you miss something else, don't hesitate to open an issue or a pull request

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)")
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

0 comments on commit c78f6f3

Please sign in to comment.