diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 6e3f3f701..dfabaab0b 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -143,16 +143,17 @@ if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) endforeach() endif() +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Freetype DEFAULT_MSG FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS FREETYPE_VERSION_STRING) -# set FREETYPE_FOUND to TRUE if all listed variables are TRUE -if(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS AND FREETYPE_VERSION_STRING) - set(FREETYPE_FOUND TRUE) -else() - set(FREETYPE_FOUND FALSE) +mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) + +if(NOT TARGET Freetype::Freetype) + add_library(Freetype::Freetype IMPORTED UNKNOWN) + set_target_properties(Freetype::Freetype PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FREETYPE_INCLUDE_DIRS}") + if(FREETYPE_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(Freetype::Freetype PROPERTIES IMPORTED_LOCATION ${FREETYPE_LIBRARY}/${CMAKE_MATCH_1}) + else() + set_target_properties(Freetype::Freetype PROPERTIES IMPORTED_LOCATION ${FREETYPE_LIBRARY}) + endif() endif() - -mark_as_advanced( - FREETYPE_LIBRARY - FREETYPE_INCLUDE_DIR_freetype2 - FREETYPE_INCLUDE_DIR_ft2build -) diff --git a/cmake/SFMLConfigDependencies.cmake.in b/cmake/SFMLConfigDependencies.cmake.in index fbef902c7..5d849e5a5 100644 --- a/cmake/SFMLConfigDependencies.cmake.in +++ b/cmake/SFMLConfigDependencies.cmake.in @@ -67,7 +67,7 @@ if(SFML_STATIC_LIBRARIES) # SFML::Graphics list(FIND SFML_FIND_COMPONENTS "Graphics" FIND_SFML_GRAPHICS_COMPONENT_INDEX) if(FIND_SFML_GRAPHICS_COMPONENT_INDEX GREATER -1) - sfml_bind_dependency(TARGET Freetype FRIENDLY_NAME "FreeType" SEARCH_NAMES "freetype") + find_package(Freetype) endif() # SFML::Audio diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index ab0a38f0c..fee5ce5f1 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -117,8 +117,8 @@ elseif(SFML_OS_IOS) target_link_libraries(sfml-graphics PRIVATE z bz2) endif() -sfml_find_package(Freetype FREETYPE_INCLUDE_DIRS FREETYPE_LIBRARY) -target_link_libraries(sfml-graphics PRIVATE Freetype) +find_package(Freetype REQUIRED) +target_link_libraries(sfml-graphics PRIVATE Freetype::Freetype) # on some platforms (e.g. Raspberry Pi 3 armhf), GCC requires linking libatomic to use features # that aren't supported by native CPU instructions (64-bit atomic operations on 32-bit architecture)