/ linux / flutter / CMakeLists.txt
CMakeLists.txt
 1  # This file controls Flutter-level build steps. It should not be edited.
 2  cmake_minimum_required(VERSION 3.10)
 3  
 4  set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
 5  
 6  # Configuration provided via flutter tool.
 7  include(${EPHEMERAL_DIR}/generated_config.cmake)
 8  
 9  # TODO: Move the rest of this into files in ephemeral. See
10  # https://github.com/flutter/flutter/issues/57146.
11  
12  # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
13  # which isn't available in 3.10.
14  function(list_prepend LIST_NAME PREFIX)
15  	set(NEW_LIST "")
16  	foreach(element ${${LIST_NAME}})
17  		list(APPEND NEW_LIST "${PREFIX}${element}")
18  	endforeach(element)
19  	set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
20  endfunction()
21  
22  # === Flutter Library ===
23  # System-level dependencies.
24  find_package(PkgConfig REQUIRED)
25  pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
26  pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
27  pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
28  
29  set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
30  
31  # Published to parent scope for install step.
32  set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
33  set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
34  set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
35  set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
36  
37  list(APPEND FLUTTER_LIBRARY_HEADERS
38  	"fl_basic_message_channel.h"
39  	"fl_binary_codec.h"
40  	"fl_binary_messenger.h"
41  	"fl_dart_project.h"
42  	"fl_engine.h"
43  	"fl_json_message_codec.h"
44  	"fl_json_method_codec.h"
45  	"fl_message_codec.h"
46  	"fl_method_call.h"
47  	"fl_method_channel.h"
48  	"fl_method_codec.h"
49  	"fl_method_response.h"
50  	"fl_plugin_registrar.h"
51  	"fl_plugin_registry.h"
52  	"fl_standard_message_codec.h"
53  	"fl_standard_method_codec.h"
54  	"fl_string_codec.h"
55  	"fl_value.h"
56  	"fl_view.h"
57  	"flutter_linux.h"
58  )
59  list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
60  add_library(flutter INTERFACE)
61  target_include_directories(flutter INTERFACE
62  	"${EPHEMERAL_DIR}"
63  )
64  target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
65  target_link_libraries(flutter INTERFACE
66  	PkgConfig::GTK
67  	PkgConfig::GLIB
68  	PkgConfig::GIO
69  )
70  add_dependencies(flutter flutter_assemble)
71  
72  # === Flutter tool backend ===
73  # _phony_ is a non-existent file to force this command to run every time,
74  # since currently there's no way to get a full input/output list from the
75  # flutter tool.
76  add_custom_command(
77  	OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
78  		${CMAKE_CURRENT_BINARY_DIR}/_phony_
79  	COMMAND ${CMAKE_COMMAND} -E env
80  		${FLUTTER_TOOL_ENVIRONMENT}
81  		"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
82  			${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
83  	VERBATIM
84  )
85  add_custom_target(flutter_assemble DEPENDS
86  	"${FLUTTER_LIBRARY}"
87  	${FLUTTER_LIBRARY_HEADERS}
88  )