CMakeLists.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # This file controls Flutter-level build steps. It should not be edited.
  2. cmake_minimum_required(VERSION 3.10)
  3. set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
  4. # Configuration provided via flutter tool.
  5. include(${EPHEMERAL_DIR}/generated_config.cmake)
  6. # TODO: Move the rest of this into files in ephemeral. See
  7. # https://github.com/flutter/flutter/issues/57146.
  8. # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
  9. # which isn't available in 3.10.
  10. function(list_prepend LIST_NAME PREFIX)
  11. set(NEW_LIST "")
  12. foreach(element ${${LIST_NAME}})
  13. list(APPEND NEW_LIST "${PREFIX}${element}")
  14. endforeach(element)
  15. set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
  16. endfunction()
  17. # === Flutter Library ===
  18. # System-level dependencies.
  19. find_package(PkgConfig REQUIRED)
  20. pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
  21. pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
  22. pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
  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. )
  62. add_dependencies(flutter flutter_assemble)
  63. # === Flutter tool backend ===
  64. # _phony_ is a non-existent file to force this command to run every time,
  65. # since currently there's no way to get a full input/output list from the
  66. # flutter tool.
  67. add_custom_command(
  68. OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
  69. ${CMAKE_CURRENT_BINARY_DIR}/_phony_
  70. COMMAND ${CMAKE_COMMAND} -E env
  71. ${FLUTTER_TOOL_ENVIRONMENT}
  72. "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
  73. ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
  74. VERBATIM
  75. )
  76. add_custom_target(flutter_assemble DEPENDS
  77. "${FLUTTER_LIBRARY}"
  78. ${FLUTTER_LIBRARY_HEADERS}
  79. )