From 8d35ad8726f44c4e853b5a192203ffcbbd2476e1 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 20 Nov 2019 17:28:15 +0100 Subject: Add FindWrapHarfbuzz Apparently we didn't have a wrap find module for it before. Add one, and add special support to handle a Gentoo broken Config file which is exported by an autotools build of harbuzz. Change-Id: I83cbeb817caf2610104c16713d4eac6ab6f8c63b Reviewed-by: Simon Hausmann Reviewed-by: Qt CMake Build Bot --- cmake/FindWrapHarfbuzz.cmake | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/configure.cmake | 2 +- util/cmake/helper.py | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 cmake/FindWrapHarfbuzz.cmake diff --git a/cmake/FindWrapHarfbuzz.cmake b/cmake/FindWrapHarfbuzz.cmake new file mode 100644 index 0000000000..f7845b28bd --- /dev/null +++ b/cmake/FindWrapHarfbuzz.cmake @@ -0,0 +1,45 @@ +# 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 WrapHarfbuzz::WrapHarfbuzz) + set(WrapHarfbuzz_FOUND ON) + return() +endif() + +set(WrapHarfbuzz_FOUND OFF) + +find_package(harfbuzz) + +# Gentoo has some buggy version of a harfbuzz Config file. Check if include paths are valid. +set(__harfbuzz_target_name "harfbuzz::harfbuzz") +if(harfbuzz_FOUND AND TARGET "${__harfbuzz_target_name}") + get_property(__harfbuzz_include_paths TARGET "${__harfbuzz_target_name}" + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + foreach(__harfbuzz_include_dir ${__harfbuzz_include_paths}) + if(NOT EXISTS "${__harfbuzz_include_dir}") + # Must be the broken Gentoo harfbuzzConfig.cmake file. Try to use pkg-config instead. + set(__harfbuzz_broken_config_file TRUE) + break() + endif() + endforeach() +endif() + +if(__harfbuzz_broken_config_file) + find_package(PkgConfig) + + pkg_check_modules(harfbuzz harfbuzz IMPORTED_TARGET) + set(__harfbuzz_target_name "PkgConfig::harfbuzz") + + if (NOT TARGET "${__harfbuzz_target_name}") + set(harfbuzz_FOUND 0) + endif() +endif() + +if(TARGET "${__harfbuzz_target_name}") + set(WrapHarfbuzz_FOUND ON) + + add_library(WrapHarfbuzz::WrapHarfbuzz INTERFACE IMPORTED) + target_link_libraries(WrapHarfbuzz::WrapHarfbuzz INTERFACE ${__harfbuzz_target_name}) +endif() +unset(__harfbuzz_target_name) +unset(__harfbuzz_include_dir) +unset(__harfbuzz_broken_config_file) diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 9269b130b6..0ff1b3bfc4 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -30,7 +30,7 @@ qt_find_package(WrapFreetype PROVIDED_TARGETS WrapFreetype::WrapFreetype) set_package_properties(WrapFreetype PROPERTIES TYPE REQUIRED) qt_find_package(Fontconfig PROVIDED_TARGETS Fontconfig::Fontconfig) qt_find_package(gbm PROVIDED_TARGETS gbm::gbm) -qt_find_package(harfbuzz PROVIDED_TARGETS harfbuzz::harfbuzz) +qt_find_package(WrapHarfbuzz PROVIDED_TARGETS WrapHarfbuzz::WrapHarfbuzz) qt_find_package(Libinput PROVIDED_TARGETS Libinput::Libinput) qt_find_package(JPEG PROVIDED_TARGETS JPEG::JPEG) qt_find_package(PNG PROVIDED_TARGETS PNG::PNG) diff --git a/util/cmake/helper.py b/util/cmake/helper.py index 38ce134051..20ee7956ab 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -384,7 +384,7 @@ _library_map = [ LibraryMapping("gnu_iconv", None, None), LibraryMapping("gtk3", "GTK3", "PkgConfig::GTK3"), LibraryMapping("gssapi", "GSSAPI", "GSSAPI::GSSAPI"), - LibraryMapping("harfbuzz", "harfbuzz", "harfbuzz::harfbuzz"), + LibraryMapping("harfbuzz", "WrapHarfbuzz", "WrapHarfbuzz::WrapHarfbuzz"), LibraryMapping("host_dbus", None, None), LibraryMapping( "icu", "ICU", "ICU::i18n ICU::uc ICU::data", extra=["COMPONENTS", "i18n", "uc", "data"] -- cgit v1.2.3