FindFreetype.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #[[
  2. Custom find module for Freetype for Emscripten compilation.
  3. Input variables:
  4. none
  5. Output variables:
  6. Freetype_FOUND
  7. FREETYPE_VERSION_STRING
  8. Resulting targets:
  9. Freetype::Freetype
  10. More info:
  11. https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html
  12. ]]
  13. include(FindPackageHandleStandardArgs)
  14. include(FindPackageMessage)
  15. if(NOT TARGET Freetype::Freetype)
  16. # If no version was specified, set default
  17. if(NOT DEFINED Freetype_FIND_VERSION)
  18. set(Freetype_FIND_VERSION "2")
  19. endif()
  20. # Check if requested Freetype version is valid
  21. # Emscripten SDK only provides Freetype 2.x
  22. if((Freetype_FIND_VERSION VERSION_LESS "2") OR (Freetype_FIND_VERSION VERSION_GREATER_EQUAL "3"))
  23. message(FATAL_ERROR "The requested Freetype version ${Freetype_FIND_VERSION} is invalid.")
  24. endif()
  25. # Emscripten includes Freetype support as part of it's SDK, meaning there's no need to find it
  26. set(Freetype_FOUND TRUE)
  27. add_library(Freetype::Freetype INTERFACE IMPORTED)
  28. # Set found Freetype version
  29. # Version set based on latest Emscripten SDK at the time of writing this file
  30. set(FREETYPE_VERSION_STRING "2.6")
  31. # Enable compilation and linking against Freetype
  32. target_compile_options(Freetype::Freetype INTERFACE "-sUSE_FREETYPE=1")
  33. target_link_libraries(Freetype::Freetype INTERFACE "-sUSE_FREETYPE=1")
  34. # Get final compiler and linker flags to print them
  35. get_target_property(Freetype_COMPILE_FLAGS Freetype::Freetype "INTERFACE_COMPILE_OPTIONS")
  36. get_target_property(Freetype_LINK_FLAGS Freetype::Freetype "INTERFACE_LINK_OPTIONS")
  37. find_package_message(
  38. "Freetype"
  39. "Freetype ${FREETYPE_VERSION_STRING} has been found as part of the Emscripten SDK."
  40. "[${Freetype_COMPILE_FLAGS}][${Freetype_LINK_FLAGS}]"
  41. )
  42. # Clean scope
  43. unset(Freetype_COMPILE_FLAGS)
  44. unset(Freetype_LINK_FLAGS)
  45. else()
  46. # Since the target already exists, we declare it as found
  47. set(Freetype_FOUND TRUE)
  48. if(NOT DEFINED FREETYPE_VERSION_STRING)
  49. set(FREETYPE_VERSION_STRING "UNKNOWN")
  50. endif()
  51. endif()