CMake package configuration files for upstream projects using Qt5 problems -
i working on larger c++ library using cmake , depends on qt. moved qt4 qt5 , encounter problem when using our lib in upstream project. minimal working example demonstrating problem please have @ repo:
https://github.com/philthiel/cmake_qt5_upstream
it contains 2 separate cmake projects:
mylib: tiny library uses qstring qt5::core.
it generates , installs package configuration files mylibconfig.cmake, mylibconfigversion.cmake, , mylibtargets.cmake in order searchable cmake find_package()
myapp: tiny executable depending on mylib
the project uses find_package(mylib) , creates executable uses mylib
the problem cmake gives me following error message when configuring myapp project:
cmake error @ cmakelists.txt:11 (add_executable): target "myapp" links target "qt5::core" target not found. perhaps find_package() call missing imported target, or alias target missing?
the reason behaviour in automatically generated mylibtargets.cmake file interface_link_libraries entry qt5 core qt5::core symbol. using qt4, absolute path qt core lib specified here.
now, can resolve using
find_package(qt5core 5.x required)
in myapp project.
however, know if intended/generic way go, i.e. requesting upstream projects of our lib search required transitive qt5 dependencies themselves, or if misuse cmake here , need change configuration procedure?
the cmake docu on package file generation
https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
mentions macros can provided package configuration files upstream. maybe correct place search imported targets qt5 , break upstream configuration runs when these dependencies not found?
best, philipp
[edit of edit] full source example
you need deliver cmake config file project, , configfile should generated via cmake (because cannot know shure user install software).
tip, use ecm cmake modules ease creation of that:
find_package(ecm required no_module) include(cmakepackageconfighelpers) ecm_setup_version(${project_version} variable_prefix atcore version_header "${cmake_current_binary_dir}/atcore_version.h" package_version_file "${cmake_current_binary_dir}/kf5atcoreconfigversion.cmake" soversion 1 ) configure_package_config_file("${cmake_current_source_dir}/kf5atcoreconfig.cmake.in" "${cmake_current_binary_dir}/kf5atcoreconfig.cmake" install_destination ${cmakeconfig_install_dir} )
and kf5atcoreconfig.cmake.in:
@package_init@ find_dependency(qt5widgets "@required_qt_version@") find_dependency(qt5serialport "@required_qt_version@") find_dependency(kf5solid "@kf5_dep_version@") include("${cmake_current_list_dir}/kf5atcoretargets.cmake")
this generate correct findyoursortware.cmake dependencies.
[edit] better explanation on what's going on. if providing library use qt, , need find qt5 library before compilling user's source, need provide findyourlibrary.cmake code, call
find_package(qt5 required components core gui widgets whatever)
now, if it's your executable needs linked, use components instead of way doing now.
find_package(qt5 required components core)
then link library with
target_link_libraries(yourtarget qt5::core)
Comments
Post a Comment