|
| 1 | +cmake_minimum_required(VERSION 3.14) |
| 2 | + |
| 3 | +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") |
| 4 | + |
| 5 | +# Configuration provided via flutter tool. |
| 6 | +include(${EPHEMERAL_DIR}/generated_config.cmake) |
| 7 | + |
| 8 | +# TODO: Move the rest of this into files in ephemeral. See |
| 9 | +# https://github.com/flutter/flutter/issues/57146. |
| 10 | +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") |
| 11 | + |
| 12 | +# === Flutter Library === |
| 13 | +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") |
| 14 | + |
| 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 | + |
| 21 | +list(APPEND FLUTTER_LIBRARY_HEADERS |
| 22 | + "flutter_export.h" |
| 23 | + "flutter_windows.h" |
| 24 | + "flutter_messenger.h" |
| 25 | + "flutter_plugin_registrar.h" |
| 26 | + "flutter_texture_registrar.h" |
| 27 | +) |
| 28 | +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") |
| 29 | +add_library(flutter INTERFACE) |
| 30 | +target_include_directories(flutter INTERFACE |
| 31 | + "${EPHEMERAL_DIR}" |
| 32 | +) |
| 33 | +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") |
| 34 | +add_dependencies(flutter flutter_assemble) |
| 35 | + |
| 36 | +# === Wrapper === |
| 37 | +list(APPEND CPP_WRAPPER_SOURCES_CORE |
| 38 | + "core_implementations.cc" |
| 39 | + "standard_codec.cc" |
| 40 | +) |
| 41 | +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") |
| 42 | +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN |
| 43 | + "plugin_registrar.cc" |
| 44 | +) |
| 45 | +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") |
| 46 | +list(APPEND CPP_WRAPPER_SOURCES_APP |
| 47 | + "flutter_engine.cc" |
| 48 | + "flutter_view_controller.cc" |
| 49 | +) |
| 50 | +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") |
| 51 | + |
| 52 | +# Wrapper sources needed for a plugin. |
| 53 | +add_library(flutter_wrapper_plugin STATIC |
| 54 | + ${CPP_WRAPPER_SOURCES_CORE} |
| 55 | + ${CPP_WRAPPER_SOURCES_PLUGIN} |
| 56 | +) |
| 57 | +apply_standard_settings(flutter_wrapper_plugin) |
| 58 | +set_target_properties(flutter_wrapper_plugin PROPERTIES |
| 59 | + POSITION_INDEPENDENT_CODE ON) |
| 60 | +set_target_properties(flutter_wrapper_plugin PROPERTIES |
| 61 | + CXX_VISIBILITY_PRESET hidden) |
| 62 | +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) |
| 63 | +target_include_directories(flutter_wrapper_plugin PUBLIC |
| 64 | + "${WRAPPER_ROOT}/include" |
| 65 | +) |
| 66 | +add_dependencies(flutter_wrapper_plugin flutter_assemble) |
| 67 | + |
| 68 | +# Wrapper sources needed for the runner. |
| 69 | +add_library(flutter_wrapper_app STATIC |
| 70 | + ${CPP_WRAPPER_SOURCES_CORE} |
| 71 | + ${CPP_WRAPPER_SOURCES_APP} |
| 72 | +) |
| 73 | +apply_standard_settings(flutter_wrapper_app) |
| 74 | +target_link_libraries(flutter_wrapper_app PUBLIC flutter) |
| 75 | +target_include_directories(flutter_wrapper_app PUBLIC |
| 76 | + "${WRAPPER_ROOT}/include" |
| 77 | +) |
| 78 | +add_dependencies(flutter_wrapper_app flutter_assemble) |
| 79 | + |
| 80 | +# === Flutter tool backend === |
| 81 | +# _phony_ is a non-existent file to force this command to run every time, |
| 82 | +# since currently there's no way to get a full input/output list from the |
| 83 | +# flutter tool. |
| 84 | +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") |
| 85 | +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) |
| 86 | +add_custom_command( |
| 87 | + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} |
| 88 | + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} |
| 89 | + ${CPP_WRAPPER_SOURCES_APP} |
| 90 | + ${PHONY_OUTPUT} |
| 91 | + COMMAND ${CMAKE_COMMAND} -E env |
| 92 | + ${FLUTTER_TOOL_ENVIRONMENT} |
| 93 | + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" |
| 94 | + windows-x64 $<CONFIG> |
| 95 | + VERBATIM |
| 96 | +) |
| 97 | +add_custom_target(flutter_assemble DEPENDS |
| 98 | + "${FLUTTER_LIBRARY}" |
| 99 | + ${FLUTTER_LIBRARY_HEADERS} |
| 100 | + ${CPP_WRAPPER_SOURCES_CORE} |
| 101 | + ${CPP_WRAPPER_SOURCES_PLUGIN} |
| 102 | + ${CPP_WRAPPER_SOURCES_APP} |
| 103 | +) |
0 commit comments