CMakeLists.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. cmake_minimum_required(VERSION 3.10)
  2. set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
  3. # Configuration provided via flutter tool.
  4. include(${EPHEMERAL_DIR}/generated_config.cmake)
  5. # TODO: Move the rest of this into files in ephemeral. See
  6. # https://github.com/flutter/flutter/issues/57146.
  7. # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
  8. # which isn't available in 3.10.
  9. function(list_prepend LIST_NAME PREFIX)
  10. set(NEW_LIST "")
  11. foreach(element ${${LIST_NAME}})
  12. list(APPEND NEW_LIST "${PREFIX}${element}")
  13. endforeach(element)
  14. set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
  15. endfunction()
  16. # === Flutter Library ===
  17. # System-level dependencies.
  18. find_package(PkgConfig REQUIRED)
  19. pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
  20. pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
  21. pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
  22. set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
  23. # Published to parent scope for install step.
  24. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
  25. set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
  26. set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
  27. set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
  28. list(APPEND FLUTTER_LIBRARY_HEADERS
  29. "fl_basic_message_channel.h"
  30. "fl_binary_codec.h"
  31. "fl_binary_messenger.h"
  32. "fl_dart_project.h"
  33. "fl_engine.h"
  34. "fl_json_message_codec.h"
  35. "fl_json_method_codec.h"
  36. "fl_message_codec.h"
  37. "fl_method_call.h"
  38. "fl_method_channel.h"
  39. "fl_method_codec.h"
  40. "fl_method_response.h"
  41. "fl_plugin_registrar.h"
  42. "fl_plugin_registry.h"
  43. "fl_standard_message_codec.h"
  44. "fl_standard_method_codec.h"
  45. "fl_string_codec.h"
  46. "fl_value.h"
  47. "fl_view.h"
  48. "flutter_linux.h"
  49. )
  50. list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
  51. add_library(flutter INTERFACE)
  52. target_include_directories(flutter INTERFACE
  53. "${EPHEMERAL_DIR}"
  54. )
  55. target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
  56. target_link_libraries(flutter INTERFACE
  57. PkgConfig::GTK
  58. PkgConfig::GLIB
  59. PkgConfig::GIO
  60. )
  61. add_dependencies(flutter flutter_assemble)
  62. # === Flutter tool backend ===
  63. # _phony_ is a non-existent file to force this command to run every time,
  64. # since currently there's no way to get a full input/output list from the
  65. # flutter tool.
  66. add_custom_command(
  67. OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
  68. ${CMAKE_CURRENT_BINARY_DIR}/_phony_
  69. COMMAND ${CMAKE_COMMAND} -E env
  70. ${FLUTTER_TOOL_ENVIRONMENT}
  71. "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
  72. ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
  73. VERBATIM
  74. )
  75. add_custom_target(flutter_assemble DEPENDS
  76. "${FLUTTER_LIBRARY}"
  77. ${FLUTTER_LIBRARY_HEADERS}
  78. )