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 <alexandru.croitor@qt.io>
This commit is contained in:
Simon Hausmann 2019-06-03 11:06:07 +02:00
parent 3966ab8e9f
commit 4c31ce68d5

View File

@ -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