CMakeLists.txt 3.4 KB

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