Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
2,658 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flutter/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# Copyright 2018 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Executable name. | ||
BINARY_NAME=flutter_desktop_example | ||
# Any extra source files to build. | ||
EXTRA_SOURCES= | ||
# Paths of any additional libraries to be bundled in the output directory. | ||
EXTRA_BUNDLED_LIBRARIES= | ||
# Extra flags (e.g., for library dependencies). | ||
SYSTEM_LIBRARIES= | ||
EXTRA_CXXFLAGS= | ||
EXTRA_CPPFLAGS= | ||
EXTRA_LDFLAGS= | ||
|
||
# Default build type. For a release build, set BUILD=release. | ||
# Currently this only sets NDEBUG, which is used to control the flags passed | ||
# to the Flutter engine in the example shell, and not the complation settings | ||
# (e.g., optimization level) of the C++ code. | ||
BUILD=debug | ||
|
||
# Configuration provided via flutter tool. | ||
include flutter/generated_config | ||
|
||
# Dependency locations | ||
FLUTTER_APP_CACHE_DIR=flutter/ | ||
FLUTTER_APP_DIR=$(CURDIR)/.. | ||
FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build | ||
|
||
OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux | ||
OBJ_DIR=$(OUT_DIR)/obj | ||
|
||
# Libraries | ||
FLUTTER_LIB_NAME=flutter_linux_glfw | ||
FLUTTER_LIB=$(FLUTTER_APP_CACHE_DIR)/lib$(FLUTTER_LIB_NAME).so | ||
|
||
# Tools | ||
FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter | ||
LINUX_BUILD=$(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh | ||
|
||
# Resources | ||
ICU_DATA_NAME=icudtl.dat | ||
ICU_DATA_SOURCE=$(FLUTTER_APP_CACHE_DIR)/$(ICU_DATA_NAME) | ||
FLUTTER_ASSETS_NAME=flutter_assets | ||
FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME) | ||
|
||
# Bundle structure | ||
BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD) | ||
BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data | ||
BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib | ||
|
||
BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME) | ||
ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME) | ||
FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/$(notdir $(FLUTTER_LIB)) | ||
ALL_LIBS_OUT=$(FLUTTER_LIB_OUT) \ | ||
$(foreach lib,$(EXTRA_BUNDLED_LIBRARIES),$(BUNDLE_LIB_DIR)/$(notdir $(lib))) | ||
|
||
# Add relevant code from the wrapper library, which is intended to be statically | ||
# built into the client. | ||
# Use abspath for the wrapper root, which can contain relative paths; the | ||
# intermediate build files will be based on the source path, which will cause | ||
# issues if they start with one or more '../'s. | ||
WRAPPER_ROOT=$(abspath $(FLUTTER_APP_CACHE_DIR)/cpp_client_wrapper_glfw) | ||
WRAPPER_SOURCES= \ | ||
$(WRAPPER_ROOT)/flutter_window_controller.cc \ | ||
$(WRAPPER_ROOT)/plugin_registrar.cc \ | ||
$(WRAPPER_ROOT)/engine_method_result.cc | ||
|
||
# Use abspath for extra sources, which may also contain relative paths (see | ||
# note above about WRAPPER_ROOT). | ||
SOURCES=main.cc $(WRAPPER_SOURCES) $(abspath $(EXTRA_SOURCES)) | ||
|
||
# Headers | ||
WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include | ||
INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(WRAPPER_INCLUDE_DIR) | ||
|
||
# Build settings | ||
ifneq ($(strip $(SYSTEM_LIBRARIES)),) | ||
EXTRA_CPPFLAGS+=$(patsubst -I%,-isystem%,$(shell pkg-config --cflags $(SYSTEM_LIBRARIES))) | ||
EXTRA_LDFLAGS+=$(shell pkg-config --libs $(SYSTEM_LIBRARIES)) | ||
endif | ||
CXX=clang++ $(EXTRA_CXXFLAGS) | ||
CXXFLAGS.release=-DNDEBUG | ||
CXXFLAGS=-std=c++14 -Wall -Werror $(CXXFLAGS.$(BUILD)) | ||
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) $(EXTRA_CPPFLAGS) | ||
LDFLAGS=-L$(BUNDLE_LIB_DIR) \ | ||
-l$(FLUTTER_LIB_NAME) \ | ||
$(EXTRA_LDFLAGS) \ | ||
-Wl,-rpath=\$$ORIGIN/lib | ||
|
||
# Intermediate files. | ||
OBJ_FILES=$(SOURCES:%.cc=$(OBJ_DIR)/%.o) | ||
DEPENDENCY_FILES=$(OBJ_FILES:%.o=%.d) | ||
|
||
# Targets | ||
|
||
.PHONY: all | ||
all: $(BIN_OUT) bundle | ||
|
||
# This is a phony target because the flutter tool cannot describe | ||
# its inputs and outputs yet. | ||
.PHONY: sync | ||
sync: flutter/generated_config | ||
$(LINUX_BUILD) linux-x64 $(BUILD) | ||
|
||
.PHONY: bundle | ||
bundle: $(ICU_DATA_OUT) $(ALL_LIBS_OUT) bundleflutterassets | ||
|
||
$(BIN_OUT): $(OBJ_FILES) $(ALL_LIBS_OUT) | ||
mkdir -p $(@D) | ||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJ_FILES) $(LDFLAGS) -o $@ | ||
|
||
$(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE): \ | ||
| sync | ||
|
||
$(FLUTTER_LIB_OUT): $(FLUTTER_LIB) | ||
mkdir -p $(@D) | ||
cp $< $@ | ||
|
||
$(ICU_DATA_OUT): $(ICU_DATA_SOURCE) | ||
mkdir -p $(@D) | ||
cp $< $@ | ||
|
||
-include $(DEPENDENCY_FILES) | ||
|
||
$(OBJ_DIR)/%.o : %.cc | sync | ||
mkdir -p $(@D) | ||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@ | ||
|
||
# Fully re-copy the assets directory on each build to avoid having to keep a | ||
# comprehensive list of all asset files here, which would be fragile to changes | ||
# in the Flutter example (e.g., adding a new font to pubspec.yaml would require | ||
# changes here). | ||
.PHONY: bundleflutterassets | ||
bundleflutterassets: $(FLUTTER_ASSETS_SOURCE) | ||
mkdir -p $(BUNDLE_DATA_DIR) | ||
rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(OUT_DIR); \ | ||
cd $(FLUTTER_APP_DIR); \ | ||
$(FLUTTER_BIN) clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#include <flutter/flutter_window_controller.h> | ||
#include <linux/limits.h> | ||
#include <unistd.h> | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace { | ||
|
||
// Returns the path of the directory containing this executable, or an empty | ||
// string if the directory cannot be found. | ||
std::string GetExecutableDirectory() { | ||
char buffer[PATH_MAX + 1]; | ||
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer)); | ||
if (length > PATH_MAX) { | ||
std::cerr << "Couldn't locate executable" << std::endl; | ||
return ""; | ||
} | ||
std::string executable_path(buffer, length); | ||
size_t last_separator_position = executable_path.find_last_of('/'); | ||
if (last_separator_position == std::string::npos) { | ||
std::cerr << "Unabled to find parent directory of " << executable_path | ||
<< std::endl; | ||
return ""; | ||
} | ||
return executable_path.substr(0, last_separator_position); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, char **argv) { | ||
// Resources are located relative to the executable. | ||
std::string base_directory = GetExecutableDirectory(); | ||
if (base_directory.empty()) { | ||
base_directory = "."; | ||
} | ||
std::string data_directory = base_directory + "/data"; | ||
std::string assets_path = data_directory + "/flutter_assets"; | ||
std::string icu_data_path = data_directory + "/icudtl.dat"; | ||
|
||
// Arguments for the Flutter Engine. | ||
std::vector<std::string> arguments; | ||
|
||
flutter::FlutterWindowController flutter_controller(icu_data_path); | ||
flutter::WindowProperties window_properties = {}; | ||
window_properties.title = "Flutter Desktop Example"; | ||
window_properties.width = 800; | ||
window_properties.height = 600; | ||
|
||
// Start the engine. | ||
if (!flutter_controller.CreateWindow(window_properties, assets_path, | ||
arguments)) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// Run until the window is closed. | ||
while (flutter_controller.RunEventLoopWithTimeout( | ||
std::chrono::milliseconds::max())) { | ||
} | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
xcuserdata | ||
|
||
# Generated by flutter tooling as needed. | ||
Flutter/ephemeral/ | ||
# Created by CocoaPods for plugins. | ||
Pods/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Cocoa | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
@IBOutlet weak var window: NSWindow! | ||
@IBOutlet weak var applicationMenu: NSMenu! | ||
|
||
func applicationWillFinishLaunching(_ notification: Notification) { | ||
// Update UI elements to match the application name. | ||
// TODO: Move this logic to a Flutter framework application delegate. | ||
// See https://github.com/flutter/flutter/issues/32419. | ||
let appName = applicationName() | ||
window.title = appName | ||
for menuItem in applicationMenu.items { | ||
menuItem.title = menuItem.title.replacingOccurrences(of: "APP_NAME", with: appName) | ||
} | ||
} | ||
|
||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { | ||
return true | ||
} | ||
|
||
/** | ||
* Returns the name of the application as set in the Info.plist | ||
*/ | ||
private func applicationName() -> String { | ||
var applicationName: String? = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") | ||
as? String | ||
if applicationName == nil { | ||
applicationName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String | ||
} | ||
return applicationName! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"size" : "16x16", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_16.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "16x16", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_32.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "32x32", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_32.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "32x32", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_64.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "128x128", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_128.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "128x128", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_256.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "256x256", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_256.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "256x256", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_512.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "512x512", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_512.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "512x512", | ||
"idiom" : "mac", | ||
"filename" : "app_icon_1024.png", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.