Dependencies.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #[[
  2. Set up external dependencies required to build RmlUi itself.
  3. Packages are configured as soft dependencies (i.e. not REQUIRED), so that a consuming project can declare them
  4. by other means, without an error being emitted here. For the same reason, instead of relying on variables like
  5. *_NOTFOUND variables, we check directly for the existence of the target.
  6. ]]
  7. if(RMLUI_FONT_ENGINE STREQUAL "freetype")
  8. find_package("Freetype")
  9. if(FREETYPE_VERSION_STRING)
  10. if(FREETYPE_VERSION_STRING VERSION_EQUAL "2.11.0" AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  11. message(WARNING "Using Freetype 2.11.0 with MSVC can cause issues, please upgrade to Freetype 2.11.1 or newer.")
  12. endif()
  13. endif()
  14. report_dependency_found_or_error("Freetype" Freetype::Freetype "Freetype font engine enabled")
  15. endif()
  16. if(RMLUI_LOTTIE_PLUGIN)
  17. find_package("rlottie")
  18. report_dependency_found_or_error("rlottie" rlottie::rlottie "Lottie plugin enabled")
  19. endif()
  20. if(RMLUI_SVG_PLUGIN)
  21. find_package("lunasvg")
  22. report_dependency_found_or_error("lunasvg" lunasvg::lunasvg "SVG plugin enabled")
  23. endif()
  24. # The Lua and LuaJIT modules don't provide targets, so make our own, or let users define the target already.
  25. if(RMLUI_LUA_BINDINGS AND (RMLUI_LUA_BINDINGS_LIBRARY STREQUAL "lua" OR RMLUI_LUA_BINDINGS_LIBRARY STREQUAL "lua_as_cxx"))
  26. if(NOT TARGET Lua::Lua)
  27. find_package("Lua" REQUIRED)
  28. add_library(Lua::Lua INTERFACE IMPORTED)
  29. set_target_properties(Lua::Lua PROPERTIES
  30. INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
  31. INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
  32. )
  33. endif()
  34. add_library(RmlUi::External::Lua ALIAS Lua::Lua)
  35. set(friendly_message "Lua bindings enabled")
  36. if(RMLUI_LUA_BINDINGS_LIBRARY STREQUAL "lua_as_cxx")
  37. string(APPEND friendly_message " with Lua compiled as C++")
  38. endif()
  39. report_dependency_found_or_error("Lua" Lua::Lua "${friendly_message}")
  40. unset(friendly_message)
  41. endif()
  42. if(RMLUI_LUA_BINDINGS AND RMLUI_LUA_BINDINGS_LIBRARY STREQUAL "luajit")
  43. if(NOT TARGET LuaJIT::LuaJIT)
  44. find_package("LuaJIT" REQUIRED)
  45. add_library(LuaJIT::LuaJIT INTERFACE IMPORTED)
  46. set_target_properties(LuaJIT::LuaJIT PROPERTIES
  47. INTERFACE_LINK_LIBRARIES "${LUAJIT_LIBRARY}"
  48. INTERFACE_INCLUDE_DIRECTORIES "${LUAJIT_INCLUDE_DIR}"
  49. )
  50. endif()
  51. add_library(RmlUi::External::Lua ALIAS LuaJIT::LuaJIT)
  52. report_dependency_found_or_error("Lua" LuaJIT::LuaJIT "Lua bindings enabled with LuaJIT")
  53. endif()
  54. if(NOT RMLUI_IS_CONFIG_FILE)
  55. if(RMLUI_TRACY_PROFILING AND RMLUI_TRACY_CONFIGURATION)
  56. enable_configuration_type(Tracy Release ON)
  57. else()
  58. enable_configuration_type(Tracy Release OFF)
  59. endif()
  60. endif()
  61. if(RMLUI_HARFBUZZ_SAMPLE)
  62. if(NOT RMLUI_FONT_ENGINE STREQUAL "freetype")
  63. message(FATAL_ERROR "The HarfBuzz sample requires the default (FreeType) font engine to be enabled. Please set RMLUI_FONT_ENGINE accordingly or disable RMLUI_HARFBUZZ_SAMPLE.")
  64. endif()
  65. find_package("HarfBuzz")
  66. report_dependency_found_or_error("HarfBuzz" harfbuzz::harfbuzz "HarfBuzz library available for samples")
  67. endif()
  68. if(RMLUI_TRACY_PROFILING)
  69. find_package(Tracy CONFIG QUIET)
  70. if(RMLUI_IS_CONFIG_FILE)
  71. report_dependency_found_or_error("Tracy" Tracy::TracyClient)
  72. endif()
  73. if(NOT TARGET Tracy::TracyClient)
  74. message(STATUS "Trying to add Tracy from subdirectory 'Dependencies/tracy'.")
  75. add_subdirectory("Dependencies/tracy")
  76. if(NOT TARGET Tracy::TracyClient)
  77. message(FATAL_ERROR "Tracy client not found. Either "
  78. "(a) make sure target Tracy::TracyClient is available from parent project, "
  79. "(b) Tracy can be found as a config package, or "
  80. "(c) Tracy source files are located in 'Dependencies/Tracy'.")
  81. endif()
  82. if(RMLUI_IS_ROOT_PROJECT)
  83. # Tracy does not export its targets to the build tree. Do that for it here, otherwise CMake will emit an
  84. # error about target `TracyClient` not being located in any export set.
  85. export(EXPORT TracyConfig
  86. NAMESPACE Tracy::
  87. FILE TracyTargets.cmake
  88. )
  89. endif()
  90. endif()
  91. endif()