From 4c31ce68d5367a6ec4dd3cf2f55e4b226add876d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 3 Jun 2019 11:06:07 +0200 Subject: [PATCH] Improve finding of sqlite with vcpkg We use qt_find_package(SQLite3 PROVIDED_TARGETS SQLite::SQLite3) which intends to find cmake's FindSQLite3.cmake and expects the existence of the corresponding target. However qt_find_package first tries to call find_package in config mode, which does not interact well with vcpkg's sqlite, where sqlite3-config.cmake is provided to support multi-config targets. So that call will appear to succeed, yet the expected targets are not there of course. Therefore this patch adds a sanity check for the target existence and allows for a fallback to the module mode for find_package, in order to find CMake's FindSQLite3.cmake. Change-Id: I660f26c38369c3504df1c590e9d3a51ff1f65c6c Reviewed-by: Alexandru Croitor --- cmake/QtBuild.cmake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 0db99d07f14..fd9cc095729 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1901,6 +1901,24 @@ macro(qt_find_package) set(config_package_arg ${arg_UNPARSED_ARGUMENTS}) list(APPEND config_package_arg "CONFIG;QUIET") find_package(${config_package_arg}) + + # Double check that in config mode the targets become visible. Sometimes + # only the module mode creates the targets. For example with vcpkg, the sqlite + # package provides sqlite3-config.cmake, which offers multi-config targets but + # in their own way. CMake has FindSQLite3.cmake and with the original + # qt_find_package(SQLite3) call it is our intention to use the cmake package + # in module mode. + if (${ARGV0}_FOUND AND arg_PROVIDED_TARGETS) + foreach(expected_target ${arg_PROVIDED_TARGETS}) + if (TARGET ${expected_target}) + set(any_target_found TRUE) + break() + endif() + endforeach() + if(NOT any_target_found) + set(${ARGV0}_FOUND) + endif() + endif() endif() # Ensure the options are back in the original unparsed arguments