CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # This file controls Flutter-level build steps. It should not be edited.
  2. cmake_minimum_required(VERSION 3.14)
  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. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
  9. # Set fallback configurations for older versions of the flutter tool.
  10. if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
  11. set(FLUTTER_TARGET_PLATFORM "windows-x64")
  12. endif()
  13. # === Flutter Library ===
  14. set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
  15. # Published to parent scope for install step.
  16. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
  17. set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
  18. set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
  19. set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
  20. list(APPEND FLUTTER_LIBRARY_HEADERS
  21. "flutter_export.h"
  22. "flutter_windows.h"
  23. "flutter_messenger.h"
  24. "flutter_plugin_registrar.h"
  25. "flutter_texture_registrar.h"
  26. )
  27. list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
  28. add_library(flutter INTERFACE)
  29. target_include_directories(flutter INTERFACE
  30. "${EPHEMERAL_DIR}"
  31. )
  32. target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
  33. add_dependencies(flutter flutter_assemble)
  34. # === Wrapper ===
  35. list(APPEND CPP_WRAPPER_SOURCES_CORE
  36. "core_implementations.cc"
  37. "standard_codec.cc"
  38. )
  39. list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
  40. list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
  41. "plugin_registrar.cc"
  42. )
  43. list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
  44. list(APPEND CPP_WRAPPER_SOURCES_APP
  45. "flutter_engine.cc"
  46. "flutter_view_controller.cc"
  47. )
  48. list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
  49. # Wrapper sources needed for a plugin.
  50. add_library(flutter_wrapper_plugin STATIC
  51. ${CPP_WRAPPER_SOURCES_CORE}
  52. ${CPP_WRAPPER_SOURCES_PLUGIN}
  53. )
  54. apply_standard_settings(flutter_wrapper_plugin)
  55. set_target_properties(flutter_wrapper_plugin PROPERTIES
  56. POSITION_INDEPENDENT_CODE ON)
  57. set_target_properties(flutter_wrapper_plugin PROPERTIES
  58. CXX_VISIBILITY_PRESET hidden)
  59. target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
  60. target_include_directories(flutter_wrapper_plugin PUBLIC
  61. "${WRAPPER_ROOT}/include"
  62. )
  63. add_dependencies(flutter_wrapper_plugin flutter_assemble)
  64. # Wrapper sources needed for the runner.
  65. add_library(flutter_wrapper_app STATIC
  66. ${CPP_WRAPPER_SOURCES_CORE}
  67. ${CPP_WRAPPER_SOURCES_APP}
  68. )
  69. apply_standard_settings(flutter_wrapper_app)
  70. target_link_libraries(flutter_wrapper_app PUBLIC flutter)
  71. target_include_directories(flutter_wrapper_app PUBLIC
  72. "${WRAPPER_ROOT}/include"
  73. )
  74. add_dependencies(flutter_wrapper_app flutter_assemble)
  75. # === Flutter tool backend ===
  76. # _phony_ is a non-existent file to force this command to run every time,
  77. # since currently there's no way to get a full input/output list from the
  78. # flutter tool.
  79. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
  80. set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
  81. add_custom_command(
  82. OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
  83. ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
  84. ${CPP_WRAPPER_SOURCES_APP}
  85. ${PHONY_OUTPUT}
  86. COMMAND ${CMAKE_COMMAND} -E env
  87. ${FLUTTER_TOOL_ENVIRONMENT}
  88. "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
  89. ${FLUTTER_TARGET_PLATFORM} $<CONFIG>
  90. VERBATIM
  91. )
  92. add_custom_target(flutter_assemble DEPENDS
  93. "${FLUTTER_LIBRARY}"
  94. ${FLUTTER_LIBRARY_HEADERS}
  95. ${CPP_WRAPPER_SOURCES_CORE}
  96. ${CPP_WRAPPER_SOURCES_PLUGIN}
  97. ${CPP_WRAPPER_SOURCES_APP}
  98. )