Skip to content

Commit 255592d

Browse files
authored
[linux] Improve example Makefile (#244)
- Clearly separates out and documents the variables that are most likely to need to change if copying the example app. - Better differentiate between paths that are relative to the example and paths that are relative to the FDE repository, since apps using FDE would not be expected to be in the same directory the way the example is. - Add a minimal "release" mode that enables that flag to disable Dart asserts, as on macOS and Windows. - Remove the output directory override that puts the example app in the same output directory as the GN build (when building with GN). Combining them makes it less clear what's specific to the example, and what's part of building the library itself.
1 parent 54fac78 commit 255592d

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

example/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ Run `make -C example/linux_fde/`. The example binary and its resources will be
3636
in `example/build/linux_fde`, and can be run from there:
3737

3838
```
39-
$ ./example/build/linux_fde/flutter_embedder_example
39+
$ ./example/build/linux_fde/debug/flutter_embedder_example
40+
```
41+
42+
To build a version with Dart asserts disabled (and thus no DEBUG banner),
43+
run `make BUILD=release` instead, then launch it with:
44+
45+
```
46+
$ ./example/build/linux_fde/release/flutter_embedder_example
4047
```
4148

4249
### macOS

example/linux_fde/Makefile

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,30 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Example-specific variables.
16+
# To modify this Makefile for a different application, these are the values
17+
# that are mostly likely to need to be changed.
18+
19+
# The location of the flutter-desktop-embedding repository.
20+
FDE_ROOT=$(CURDIR)/../..
21+
# The C++ code for the embedder application.
22+
SOURCES=flutter_embedder_example.cc
23+
# Plugins to include (from the flutter-desktop-embedding plugins/ directory).
24+
PLUGIN_NAMES=color_panel file_chooser menubar
25+
26+
27+
# Default build type. For a release build, set BUILD=release.
28+
# Currently this only sets NDEBUG, which is used to control the flags passed
29+
# to the Flutter engine in the example shell, and not the complation settings
30+
# (e.g., optimization level) of the C++ code.
31+
BUILD:=debug
32+
1533
# Dependency locations
16-
PROJECT_ROOT=$(CURDIR)/../..
17-
FLUTTER_EMBEDDER_LIB_DIR=$(PROJECT_ROOT)/library/linux
1834
FLUTTER_APP_DIR=$(CURDIR)/..
1935
FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build
20-
PLUGINS_DIR=$(PROJECT_ROOT)/plugins
21-
TOOLS_DIR=$(PROJECT_ROOT)/tools
36+
FLUTTER_EMBEDDER_LIB_DIR=$(FDE_ROOT)/library/linux
37+
PLUGINS_DIR=$(FDE_ROOT)/plugins
38+
TOOLS_DIR=$(FDE_ROOT)/tools
2239
FLUTTER_DIR=$(shell $(TOOLS_DIR)/flutter_location)
2340

2441
# Libraries
@@ -28,7 +45,6 @@ FLUTTER_EMBEDDER_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME)
2845
FLUTTER_ENGINE_LIB_NAME=flutter_engine
2946
FLUTTER_ENGINE_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
3047

31-
PLUGIN_NAMES=color_panel file_chooser menubar
3248
PLUGIN_LIB_NAME_PREFIX=flutter_embedder_
3349
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
3450
,$(PLUGINS_DIR)/$(plugin)/linux/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
@@ -38,7 +54,7 @@ ALL_LIBS=$(FLUTTER_EMBEDDER_LIB) $(FLUTTER_ENGINE_LIB) $(PLUGIN_LIBS)
3854
# Headers
3955
PLUGIN_DIRS=$(patsubst %,$(PLUGINS_DIR)/%/linux,$(PLUGIN_NAMES))
4056
LIBRARY_DIRS=$(FLUTTER_EMBEDDER_LIB_DIR) $(PLUGIN_DIRS)
41-
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(PROJECT_ROOT)/library/include
57+
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(FDE_ROOT)/library/include
4258

4359
# Tools
4460
BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets
@@ -51,7 +67,7 @@ FLUTTER_ASSETS_NAME=flutter_assets
5167
FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME)
5268

5369
# Output bundle structure and targets
54-
OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux_fde
70+
OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux_fde/$(BUILD)
5571
OUT_DATA_DIR=$(OUT_DIR)/data
5672
OUT_LIB_DIR=$(OUT_DIR)/lib
5773

@@ -61,7 +77,7 @@ ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(OUT_LIB_DIR)/$(notdir $(lib)))
6177

6278
# Overrides for the optional GN build.
6379
ifdef USE_GN
64-
GN_OUT_DIR=$(PROJECT_ROOT)/out
80+
GN_OUT_DIR=$(FDE_ROOT)/out
6581

6682
# The GN build places all libraries at the top level of the output directory.
6783
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
@@ -82,7 +98,9 @@ endif
8298

8399
# Build settings
84100
CXX=g++ -std=c++14
85-
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3)
101+
CXXFLAGS.release=-DNDEBUG
102+
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3) \
103+
$(CXXFLAGS.$(BUILD))
86104
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
87105
ifdef USE_GN
88106
CPPFLAGS+=-DUSE_FLATTENED_INCLUDES
@@ -94,8 +112,6 @@ LDFLAGS=-L$(OUT_LIB_DIR) \
94112
$(patsubst %,-l$(PLUGIN_LIB_NAME_PREFIX)%,$(PLUGIN_NAMES)) \
95113
-Wl,-rpath=\$$ORIGIN/lib
96114

97-
SOURCES=flutter_embedder_example.cc
98-
99115
# Targets
100116

101117
.PHONY: all

0 commit comments

Comments
 (0)