CMakeLists.txt 3.4 KB

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