Commit 55a97b0cb133b7a5dc28dfabec77a1b9f742c301

Thomas Sondergaard 2022-06-23T08:51:50

CMakeLists.txt: Provide both 'freetype' and 'Freetype::Freetype' targets. FreeType can be located by consuming projects that use `find_package(Freetype)` either via the old `MODULE` path (which uses `FindFreetype.cmake` supplied by CMake), or via the new `CONFIG` path (which uses `freetype-config.cmake` as supplied by this project). Up to this point the CMake module has supplied the target `Freetype::Freetype` and the config file provided by this project the target `freetype`. Now we supply both `freetype` and `Freetype::Freetype` so that consuming projects can always use the target `Freetype::Freetype` regardless of what path was taken by `find_package(Freetype)`. Fixes #1165.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d12897c..feb4be3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -498,6 +498,13 @@ if (BUILD_FRAMEWORK)
   )
 endif ()
 
+# 'freetype-interface' is an interface library, to be accessed with
+# `EXPORT_NAME Freetype::Freetype`.  This is the target name provided by
+# CMake's `FindFreetype.cmake`, so we provide it for compatibility.
+add_library(freetype-interface INTERFACE)
+set_target_properties(freetype-interface PROPERTIES
+  EXPORT_NAME Freetype::Freetype
+  INTERFACE_LINK_LIBRARIES freetype)
 
 set(PKGCONFIG_REQUIRES "")
 set(PKGCONFIG_REQUIRES_PRIVATE "")
@@ -615,7 +622,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
     COMPATIBILITY SameMajorVersion)
 
   install(
-    TARGETS freetype
+    TARGETS freetype freetype-interface
       EXPORT freetype-targets
       LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
       ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}