qt5base-lts/cmake/FindWrapHarfbuzz.cmake
Alexandru Croitor 8d35ad8726 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 <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-11-25 11:58:02 +00:00

46 lines
1.6 KiB
CMake

# 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)