-
Notifications
You must be signed in to change notification settings - Fork 0
/
QtFindWrapHelper.cmake
122 lines (109 loc) · 5.57 KB
/
QtFindWrapHelper.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# Creates an imported wrapper target that links against either a Qt bundled package
# or a system package.
#
# Used for consuming 3rd party libraries in Qt.
#
# Example: Creates WrapFreetype::WrapFreetype linking against either
# Qt6::BundledFreetype or WrapSystemFreetype::WrapSystemFreetype.
#
# The implementation has to use a unique prefix in each variable, otherwise when WrapFreetype
# find_package()s WrapPNG, the nested call would override the parent call variables, due to macros
# using the same scope.
macro(qt_find_package_system_or_bundled _unique_prefix)
set(_flags "")
set(_options
FRIENDLY_PACKAGE_NAME
WRAP_PACKAGE_TARGET
WRAP_PACKAGE_FOUND_VAR_NAME
BUNDLED_PACKAGE_NAME
BUNDLED_PACKAGE_TARGET
SYSTEM_PACKAGE_NAME
SYSTEM_PACKAGE_TARGET
)
set(_multioptions "")
cmake_parse_arguments("_qfwrap_${_unique_prefix}"
"${_flags}" "${_options}" "${_multioptions}" ${ARGN})
# We can't create the same interface imported target multiple times, CMake will complain if we
# do that. This can happen if the find_package call is done in multiple different
# subdirectories.
if(TARGET "${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_TARGET}")
set(${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME} ON)
return()
endif()
set(${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME} OFF)
include("FindWrap${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}ConfigExtra" OPTIONAL)
if(NOT DEFINED "QT_USE_BUNDLED_${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}")
message(FATAL_ERROR
"Can't find cache variable "
"QT_USE_BUNDLED_${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET} "
"to decide whether to use bundled or system library.")
endif()
if("${QT_USE_BUNDLED_${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}}")
set(${_unique_prefix}_qt_package_name_to_use
"Qt6${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_NAME}")
set(${_unique_prefix}_qt_package_target_to_use
"Qt6::${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}")
set(${_unique_prefix}_qt_package_success_message
"Using Qt bundled ${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}.")
set(${_unique_prefix}_qt_package_type "bundled")
else()
set(${_unique_prefix}_qt_package_name_to_use
"${_qfwrap_${_unique_prefix}_SYSTEM_PACKAGE_NAME}")
set(${_unique_prefix}_qt_package_target_to_use
"${_qfwrap_${_unique_prefix}_SYSTEM_PACKAGE_TARGET}")
set(${_unique_prefix}_qt_package_success_message
"Using system ${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}.")
set(${_unique_prefix}_qt_package_type "system")
endif()
if(NOT TARGET "${${_unique_prefix}_qt_package_target_to_use}")
find_package("${${_unique_prefix}_qt_package_name_to_use}")
endif()
if(TARGET "${${_unique_prefix}_qt_package_target_to_use}")
set(${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME} ON)
message(STATUS "${${_unique_prefix}_qt_package_success_message}")
add_library("${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_TARGET}" INTERFACE IMPORTED)
target_link_libraries("${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_TARGET}"
INTERFACE
${${_unique_prefix}_qt_package_target_to_use})
set_target_properties("${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_TARGET}" PROPERTIES
INTERFACE_QT_3RD_PARTY_PACKAGE_TYPE
"${${_unique_prefix}_qt_package_type}")
# This might not be set, because qt_find_package() is called from a configure.cmake file via
# qt_feature_evaluate_features, which means the _VERSION var is confined to the function
# scope.
if(${${_unique_prefix}_qt_package_name_to_use}_VERSION)
set(_qfwrap_${_unique_prefix}_package_version
"${${${_unique_prefix}_qt_package_name_to_use}_VERSION}"
)
else()
# We set this in qt_find_package, so try to retrieve it.
get_target_property(_qfwrap_${_unique_prefix}_package_version_from_prop
"${${_unique_prefix}_qt_package_target_to_use}" _qt_package_found_version)
if(_qfwrap_${_unique_prefix}_package_version_from_prop)
set(_qfwrap_${_unique_prefix}_package_version
"${_qfwrap_${_unique_prefix}_package_version_from_prop}"
)
else()
set(_qfwrap_${_unique_prefix}_package_version "")
endif()
endif()
if(_qfwrap_${_unique_prefix}_package_version)
set(Wrap${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}_VERSION
"${_qfwrap_${_unique_prefix}_package_version}"
)
set(_qfwrap_${_unique_prefix}_package_version_option
VERSION_VAR "Wrap${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}_VERSION"
)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Wrap${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}
REQUIRED_VARS ${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME}
${_qfwrap_${_unique_prefix}_package_version_option}
)
elseif(${_unique_prefix}_qt_package_type STREQUAL "bundled")
message(FATAL_ERROR "Can't find ${${_unique_prefix}_qt_package_target_to_use}.")
endif()
endmacro()