From aa4be0ef70cf697bafc3c5a1df409067505d91e6 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 9 Aug 2022 20:51:42 +0200 Subject: [PATCH] Fix build errors with CMake 3.24.0 See note in comment; concrete example of build error (when building syncthingtray against qtforkawesome built with CMake 3.24.0): ``` CMake Error at plasmoid/lib/CMakeLists.txt:15 (find_package): Found package configuration file: /usr/share/qtquickforkawesome-git/cmake/qtquickforkawesome-gitConfig.cmake but it set qtquickforkawesome-git_FOUND to FALSE so package "qtquickforkawesome-git" is considered to be NOT FOUND. Reason given by package: The following imported targets are referenced, but are missing: qtforkawesome-git ``` --- cmake/modules/LibraryTarget.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmake/modules/LibraryTarget.cmake b/cmake/modules/LibraryTarget.cmake index 80ce29f..b554def 100644 --- a/cmake/modules/LibraryTarget.cmake +++ b/cmake/modules/LibraryTarget.cmake @@ -256,6 +256,18 @@ foreach (INTERFACE_REQUIRED_PKG_CONFIG_MODULE ${INTERFACE_REQUIRED_PKG_CONFIG_MO ) endforeach () +# add all REQUIRED_PACKAGES that are exported by the current build to INTERFACE_REQUIRED_PACKAGES +foreach (REQUIRED_PACKAGE ${REQUIRED_PACKAGES}) + # note: Looks like CMake (as of version 3.24.0) adds a check for targets that are exported as + # part of the current build in "*Targets.cmake" export files as those targets are also added as + # "IMPORTED_LINK_DEPENDENT_LIBRARIES". For instance, qtforkawesome and qtquickforkawesome are + # built within the same project and qtforkawesome ends up as IMPORTED_LINK_DEPENDENT_LIBRARIES + # on qtquickforkawesome's export and is checked to exist. + if ("${EXPORT_${REQUIRED_PACKAGE}}") + list(APPEND INTERFACE_REQUIRED_PACKAGES "${REQUIRED_PACKAGE}") + endif () +endforeach () + # create the CMake package config file from template if (INTERFACE_REQUIRED_PACKAGES) list(REMOVE_ITEM INTERFACE_REQUIRED_PACKAGES "") @@ -510,6 +522,9 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) EXPORT_LINK_INTERFACE_LIBRARIES COMPONENT cmake-config) + # allow checking for the export in subsequent sibling projects/directories + set("EXPORT_${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}" ON PARENT_SCOPE) + # add install target for header files if (NOT META_IS_PLUGIN) foreach (HEADER_FILE ${HEADER_FILES} ${ADDITIONAL_HEADER_FILES})