CMakeLists.txt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid)
  23. set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
  24. # Published to parent scope for install step.
  25. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
  26. set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
  27. set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
  28. set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
  29. list(APPEND FLUTTER_LIBRARY_HEADERS
  30. "fl_basic_message_channel.h"
  31. "fl_binary_codec.h"
  32. "fl_binary_messenger.h"
  33. "fl_dart_project.h"
  34. "fl_engine.h"
  35. "fl_json_message_codec.h"
  36. "fl_json_method_codec.h"
  37. "fl_message_codec.h"
  38. "fl_method_call.h"
  39. "fl_method_channel.h"
  40. "fl_method_codec.h"
  41. "fl_method_response.h"
  42. "fl_plugin_registrar.h"
  43. "fl_plugin_registry.h"
  44. "fl_standard_message_codec.h"
  45. "fl_standard_method_codec.h"
  46. "fl_string_codec.h"
  47. "fl_value.h"
  48. "fl_view.h"
  49. "flutter_linux.h"
  50. )
  51. list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
  52. add_library(flutter INTERFACE)
  53. target_include_directories(flutter INTERFACE
  54. "${EPHEMERAL_DIR}"
  55. )
  56. target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
  57. target_link_libraries(flutter INTERFACE
  58. PkgConfig::GTK
  59. PkgConfig::GLIB
  60. PkgConfig::GIO
  61. PkgConfig::BLKID
  62. )
  63. add_dependencies(flutter flutter_assemble)
  64. # === Flutter tool backend ===
  65. # _phony_ is a non-existent file to force this command to run every time,
  66. # since currently there's no way to get a full input/output list from the
  67. # flutter tool.
  68. add_custom_command(
  69. OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
  70. ${CMAKE_CURRENT_BINARY_DIR}/_phony_
  71. COMMAND ${CMAKE_COMMAND} -E env
  72. ${FLUTTER_TOOL_ENVIRONMENT}
  73. "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
  74. linux-x64 ${CMAKE_BUILD_TYPE}
  75. )
  76. add_custom_target(flutter_assemble DEPENDS
  77. "${FLUTTER_LIBRARY}"
  78. ${FLUTTER_LIBRARY_HEADERS}
  79. )