mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* First pass at CMake files; untested * First pass of adding CMake generation logic on Windows * Misc fixes * Get bundling working, start incoprorating CMake build into tool * Fix debug, exe name. * Add resources * Move cmake.dart * Rip out all the vcxproj/solution plumbing * Fix plugin cmake generation * Build with cmake rather than calling VS directly * Adjust Windows plugin template to match standard header directory structure * Pass config selection when building * Partially fix multi-config handling * Rev template version * Share the CMake generation instead of splitting it out * VS build/run cycle works, with slightly awkward requirement to always build all * Update manifest * Plugin template fixes * Minor adjustments * Build install as part of build command, instead of separately * Test cleanup * Update Linux test for adjusted generated CMake approach * Plugin test typo fix * Add missing stub file for project test * Add a constant for VS generator
56 lines
2.0 KiB
Dart
56 lines
2.0 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'project.dart';
|
|
|
|
/// Extracts the `BINARY_NAME` from a project's CMake file.
|
|
///
|
|
/// Returns `null` if it cannot be found.
|
|
String getCmakeExecutableName(CmakeBasedProject project) {
|
|
if (!project.cmakeFile.existsSync()) {
|
|
return null;
|
|
}
|
|
final RegExp nameSetPattern = RegExp(r'^\s*set\(BINARY_NAME\s*"(.*)"\s*\)\s*$');
|
|
for (final String line in project.cmakeFile.readAsLinesSync()) {
|
|
final RegExpMatch match = nameSetPattern.firstMatch(line);
|
|
if (match != null) {
|
|
return match.group(1);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String _escapeBackslashes(String s) {
|
|
return s.replaceAll(r'\', r'\\');
|
|
}
|
|
|
|
/// Writes a generated CMake configuration file for [project], including
|
|
/// variables expected by the build template and an environment variable list
|
|
/// for calling back into Flutter.
|
|
void writeGeneratedCmakeConfig(String flutterRoot, CmakeBasedProject project, Map<String, String> environment) {
|
|
// Only a limited set of variables are needed by the CMake files themselves,
|
|
// the rest are put into a list to pass to the re-entrant build step.
|
|
final String escapedFlutterRoot = _escapeBackslashes(flutterRoot);
|
|
final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path);
|
|
final StringBuffer buffer = StringBuffer('''
|
|
# Generated code do not commit.
|
|
file(TO_CMAKE_PATH "$escapedFlutterRoot" FLUTTER_ROOT)
|
|
file(TO_CMAKE_PATH "$escapedProjectDir" PROJECT_DIR)
|
|
|
|
# Environment variables to pass to tool_backend.sh
|
|
list(APPEND FLUTTER_TOOL_ENVIRONMENT
|
|
"FLUTTER_ROOT=\\"$escapedFlutterRoot\\""
|
|
"PROJECT_DIR=\\"$escapedProjectDir\\""
|
|
''');
|
|
for (final String key in environment.keys) {
|
|
final String value = _escapeBackslashes(environment[key]);
|
|
buffer.writeln(' "$key=\\"$value\\""');
|
|
}
|
|
buffer.writeln(')');
|
|
|
|
project.generatedCmakeConfigFile
|
|
..createSync(recursive: true)
|
|
..writeAsStringSync(buffer.toString());
|
|
}
|