summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-03-05 13:15:34 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-03-05 16:08:14 +0100
commit4f7cc722985fb52ea67f56dfb766bb274410ba2d (patch)
treed2a96bb9091c94aaed5e0cc7b9d408e26c71ec09 /cmake
parenta2305f94306013a0273b276955b3b2340a06a9e6 (diff)
CMake: Handle conditions in third party find modules correctly
Previously the FindWrap modules checked for hardcoded features when deciding whether to use a bundled library or not. This proved not to work correctly because features were not available when the find modules were processed. Introduce a new CMake API call that needs to be manually called after an add_subdirectory call which declares a bundled library. The call will check for the existence of the bundled target, and will then set a cache variable QT_USE_BUNDLED_Bundled<TargetName>. The same variable is written into a FindWrapFooConfigExtra.cmake file which will be loaded by the appropriate FindWrap module. The module can that use that variable to decided whether to link against the bundled library or the system library. Change-Id: I75e9a4f4e14d88d4490916a79ad12f1ce57891e0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindWrapFreetype.cmake10
-rw-r--r--cmake/FindWrapHarfbuzz.cmake10
-rw-r--r--cmake/FindWrapPCRE2.cmake10
-rw-r--r--cmake/FindWrapPNG.cmake10
-rw-r--r--cmake/QtBaseGlobalTargets.cmake1
-rw-r--r--cmake/QtBuild.cmake22
-rw-r--r--cmake/QtFindWrapConfigExtra.cmake.in1
-rw-r--r--cmake/QtFindWrapHelper.cmake18
8 files changed, 45 insertions, 37 deletions
diff --git a/cmake/FindWrapFreetype.cmake b/cmake/FindWrapFreetype.cmake
index 3f8317be69..59219df6c2 100644
--- a/cmake/FindWrapFreetype.cmake
+++ b/cmake/FindWrapFreetype.cmake
@@ -1,17 +1,11 @@
include(QtFindWrapHelper NO_POLICY_SCOPE)
-set(_qt_wrap_use_bundled FALSE)
-if(QT_FEATURE_freetype AND NOT QT_FEATURE_system_freetype)
- set(_qt_wrap_use_bundled TRUE)
-endif()
-
qt_find_package_system_or_bundled(wrap_freetype
FRIENDLY_PACKAGE_NAME "Freetype"
WRAP_PACKAGE_TARGET "WrapFreetype::WrapFreetype"
WRAP_PACKAGE_FOUND_VAR_NAME "WrapFreetype_FOUND"
- BUNDLED_PACKAGE_NAME "Qt6BundledFreetype"
- BUNDLED_PACKAGE_TARGET "Qt6::BundledFreetype"
+ BUNDLED_PACKAGE_NAME "BundledFreetype"
+ BUNDLED_PACKAGE_TARGET "BundledFreetype"
SYSTEM_PACKAGE_NAME "WrapSystemFreetype"
SYSTEM_PACKAGE_TARGET "WrapSystemFreetype::WrapSystemFreetype"
- USE_BUNDLED_PACKAGE "${_qt_wrap_use_bundled}"
)
diff --git a/cmake/FindWrapHarfbuzz.cmake b/cmake/FindWrapHarfbuzz.cmake
index eac95b669d..a66bb08d89 100644
--- a/cmake/FindWrapHarfbuzz.cmake
+++ b/cmake/FindWrapHarfbuzz.cmake
@@ -1,17 +1,11 @@
include(QtFindWrapHelper NO_POLICY_SCOPE)
-set(_qt_wrap_use_bundled FALSE)
-if(QT_FEATURE_harfbuzz AND NOT QT_FEATURE_system_harfbuzz)
- set(_qt_wrap_use_bundled TRUE)
-endif()
-
qt_find_package_system_or_bundled(wrap_harfbuzz
FRIENDLY_PACKAGE_NAME "Harfbuzz"
WRAP_PACKAGE_TARGET "WrapHarfbuzz::WrapHarfbuzz"
WRAP_PACKAGE_FOUND_VAR_NAME "WrapHarfbuzz_FOUND"
- BUNDLED_PACKAGE_NAME "Qt6BundledHarfbuzz"
- BUNDLED_PACKAGE_TARGET "Qt6::BundledHarfbuzz"
+ BUNDLED_PACKAGE_NAME "BundledHarfbuzz"
+ BUNDLED_PACKAGE_TARGET "BundledHarfbuzz"
SYSTEM_PACKAGE_NAME "WrapSystemHarfbuzz"
SYSTEM_PACKAGE_TARGET "WrapSystemHarfbuzz::WrapSystemHarfbuzz"
- USE_BUNDLED_PACKAGE "${_qt_wrap_use_bundled}"
)
diff --git a/cmake/FindWrapPCRE2.cmake b/cmake/FindWrapPCRE2.cmake
index fec46f36b0..08e12163ed 100644
--- a/cmake/FindWrapPCRE2.cmake
+++ b/cmake/FindWrapPCRE2.cmake
@@ -1,17 +1,11 @@
include(QtFindWrapHelper NO_POLICY_SCOPE)
-set(_qt_wrap_use_bundled FALSE)
-if(QT_FEATURE_pcre2 AND NOT QT_FEATURE_system_pcre2)
- set(_qt_wrap_use_bundled TRUE)
-endif()
-
qt_find_package_system_or_bundled(wrap_pcre2
FRIENDLY_PACKAGE_NAME "PCRE2"
WRAP_PACKAGE_TARGET "WrapPCRE2::WrapPCRE2"
WRAP_PACKAGE_FOUND_VAR_NAME "WrapPCRE2_FOUND"
- BUNDLED_PACKAGE_NAME "Qt6BundledPcre2"
- BUNDLED_PACKAGE_TARGET "Qt6::BundledPcre2"
+ BUNDLED_PACKAGE_NAME "BundledPcre2"
+ BUNDLED_PACKAGE_TARGET "BundledPcre2"
SYSTEM_PACKAGE_NAME "WrapSystemPCRE2"
SYSTEM_PACKAGE_TARGET "WrapSystemPCRE2::WrapSystemPCRE2"
- USE_BUNDLED_PACKAGE "${_qt_wrap_use_bundled}"
)
diff --git a/cmake/FindWrapPNG.cmake b/cmake/FindWrapPNG.cmake
index d9e7aa539b..55bfbdcffd 100644
--- a/cmake/FindWrapPNG.cmake
+++ b/cmake/FindWrapPNG.cmake
@@ -1,17 +1,11 @@
include(QtFindWrapHelper NO_POLICY_SCOPE)
-set(_qt_wrap_use_bundled FALSE)
-if(QT_FEATURE_png AND NOT QT_FEATURE_system_png)
- set(_qt_wrap_use_bundled TRUE)
-endif()
-
qt_find_package_system_or_bundled(wrap_png
FRIENDLY_PACKAGE_NAME "PNG"
WRAP_PACKAGE_TARGET "WrapPNG::WrapPNG"
WRAP_PACKAGE_FOUND_VAR_NAME "WrapPNG_FOUND"
- BUNDLED_PACKAGE_NAME "Qt6BundledLibpng"
- BUNDLED_PACKAGE_TARGET "Qt6::BundledLibpng"
+ BUNDLED_PACKAGE_NAME "BundledLibpng"
+ BUNDLED_PACKAGE_TARGET "BundledLibpng"
SYSTEM_PACKAGE_NAME "WrapSystemPNG"
SYSTEM_PACKAGE_TARGET "WrapSystemPNG::WrapSystemPNG"
- USE_BUNDLED_PACKAGE "${_qt_wrap_use_bundled}"
)
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index 31e0512732..a788392bad 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -230,6 +230,7 @@ qt_copy_or_install(FILES
cmake/QtCompilerOptimization.cmake
cmake/QtFeature.cmake
cmake/QtFindWrapHelper.cmake
+ cmake/QtFindWrapConfigExtra.cmake.in
cmake/QtPlatformSupport.cmake
cmake/QtPlatformAndroid.cmake
cmake/QtPostProcess.cmake
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 90306a44c8..e62f5aa196 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -3163,6 +3163,28 @@ function(qt_add_3rdparty_library target)
endif()
endfunction()
+function(qt_install_3rdparty_library_wrap_config_extra_file target)
+ if(TARGET "${target}")
+ set(use_bundled "ON")
+ else()
+ set(use_bundled "OFF")
+ endif()
+
+ set(QT_USE_BUNDLED_${target} "${use_bundled}" CACHE BOOL "" FORCE)
+ set(extra_cmake_code "set(QT_USE_BUNDLED_${target} ${use_bundled} CACHE BOOL \"\" FORCE)")
+ configure_file(
+ "${QT_CMAKE_DIR}/QtFindWrapConfigExtra.cmake.in"
+ "${QT_CONFIG_BUILD_DIR}/${INSTALL_CMAKE_NAMESPACE}/FindWrap${target}ConfigExtra.cmake"
+ @ONLY
+ )
+
+ qt_install(FILES
+ "${QT_CONFIG_BUILD_DIR}/${INSTALL_CMAKE_NAMESPACE}/FindWrap${target}ConfigExtra.cmake"
+ DESTINATION "${QT_CONFIG_INSTALL_DIR}/${INSTALL_CMAKE_NAMESPACE}"
+ COMPONENT Devel
+ )
+endfunction()
+
function(qt_get_tool_cmake_configuration out_var)
qt_get_main_cmake_configuration("${out_var}")
string(TOUPPER "${${out_var}}" upper_config)
diff --git a/cmake/QtFindWrapConfigExtra.cmake.in b/cmake/QtFindWrapConfigExtra.cmake.in
new file mode 100644
index 0000000000..6ecf43512c
--- /dev/null
+++ b/cmake/QtFindWrapConfigExtra.cmake.in
@@ -0,0 +1 @@
+@extra_cmake_code@
diff --git a/cmake/QtFindWrapHelper.cmake b/cmake/QtFindWrapHelper.cmake
index cb6d19600b..f536df99e1 100644
--- a/cmake/QtFindWrapHelper.cmake
+++ b/cmake/QtFindWrapHelper.cmake
@@ -19,7 +19,6 @@ macro(qt_find_package_system_or_bundled _unique_prefix)
BUNDLED_PACKAGE_TARGET
SYSTEM_PACKAGE_NAME
SYSTEM_PACKAGE_TARGET
- USE_BUNDLED_PACKAGE
)
set(_multioptions "")
@@ -36,11 +35,20 @@ macro(qt_find_package_system_or_bundled _unique_prefix)
set(${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME} OFF)
- if(_qfwrap_${_unique_prefix}_USE_BUNDLED_PACKAGE)
+ 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
- "${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_NAME}")
+ "Qt6${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_NAME}")
set(${_unique_prefix}_qt_package_target_to_use
- "${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}")
+ "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")
@@ -69,6 +77,6 @@ macro(qt_find_package_system_or_bundled _unique_prefix)
INTERFACE_QT_3RD_PARTY_PACKAGE_TYPE
"${${_unique_prefix}_qt_package_type}")
elseif(${_unique_prefix}_qt_package_type STREQUAL "bundled")
- message(FATAL_ERROR "Can't find ${_qfwrap_${_unique_prefix}_BUNDLED_PACKAGE_TARGET}.")
+ message(FATAL_ERROR "Can't find ${${_unique_prefix}_qt_package_target_to_use}.")
endif()
endmacro()