Switch Windows to CMake (#60629)
* 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
diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart
index 2fe310c..c3b566e 100644
--- a/packages/flutter_tools/lib/src/project.dart
+++ b/packages/flutter_tools/lib/src/project.dart
@@ -329,6 +329,27 @@
File get podManifestLock;
}
+/// Represents a CMake-based sub-project.
+///
+/// This defines interfaces common to Windows and Linux projects.
+abstract class CmakeBasedProject {
+ /// The parent of this project.
+ FlutterProject get parent;
+
+ /// Whether the subproject (either Windows or Linux) exists in the Flutter project.
+ bool existsSync();
+
+ /// The native project CMake specification.
+ File get cmakeFile;
+
+ /// Contains definitions for FLUTTER_ROOT, LOCAL_ENGINE, and more flags for
+ /// the build.
+ File get generatedCmakeConfigFile;
+
+ /// Includable CMake with rules and variables for plugin builds.
+ File get generatedPluginCmakeFile;
+}
+
/// Represents the iOS sub-project of a Flutter project.
///
/// Instances will reflect the contents of the `ios/` sub-folder of
@@ -995,18 +1016,28 @@
}
/// The Windows sub project
-class WindowsProject extends FlutterProjectPlatform {
- WindowsProject._(this.project);
+class WindowsProject extends FlutterProjectPlatform implements CmakeBasedProject {
+ WindowsProject._(this.parent);
- final FlutterProject project;
+ @override
+ final FlutterProject parent;
@override
String get pluginConfigKey => WindowsPlugin.kConfigKey;
@override
- bool existsSync() => _editableDirectory.existsSync() && solutionFile.existsSync();
+ bool existsSync() => _editableDirectory.existsSync() && cmakeFile.existsSync();
- Directory get _editableDirectory => project.directory.childDirectory('windows');
+ @override
+ File get cmakeFile => _editableDirectory.childFile('CMakeLists.txt');
+
+ @override
+ File get generatedCmakeConfigFile => ephemeralDirectory.childFile('generated_config.cmake');
+
+ @override
+ File get generatedPluginCmakeFile => managedDirectory.childFile('generated_plugins.cmake');
+
+ Directory get _editableDirectory => parent.directory.childDirectory('windows');
/// The directory in the project that is managed by Flutter. As much as
/// possible, files that are edited by Flutter tooling after initial project
@@ -1018,24 +1049,6 @@
/// checked in should live here.
Directory get ephemeralDirectory => managedDirectory.childDirectory('ephemeral');
- /// Contains definitions for FLUTTER_ROOT, LOCAL_ENGINE, and more flags for
- /// the build.
- File get generatedPropertySheetFile => ephemeralDirectory.childFile('Generated.props');
-
- /// Contains configuration to add plugins to the build.
- File get generatedPluginPropertySheetFile => managedDirectory.childFile('GeneratedPlugins.props');
-
- // The MSBuild project file.
- File get vcprojFile => _editableDirectory.childFile('Runner.vcxproj');
-
- // The MSBuild solution file.
- File get solutionFile => _editableDirectory.childFile('Runner.sln');
-
- /// The file where the VS build will write the name of the built app.
- ///
- /// Ideally this will be replaced in the future with inspection of the project.
- File get nameFile => ephemeralDirectory.childFile('exe_filename');
-
/// The directory to write plugin symlinks.
Directory get pluginSymlinkDirectory => ephemeralDirectory.childDirectory('.plugin_symlinks');
@@ -1043,15 +1056,16 @@
}
/// The Linux sub project.
-class LinuxProject extends FlutterProjectPlatform {
- LinuxProject._(this.project);
+class LinuxProject extends FlutterProjectPlatform implements CmakeBasedProject {
+ LinuxProject._(this.parent);
- final FlutterProject project;
+ @override
+ final FlutterProject parent;
@override
String get pluginConfigKey => LinuxPlugin.kConfigKey;
- Directory get _editableDirectory => project.directory.childDirectory('linux');
+ Directory get _editableDirectory => parent.directory.childDirectory('linux');
/// The directory in the project that is managed by Flutter. As much as
/// possible, files that are edited by Flutter tooling after initial project
@@ -1066,14 +1080,13 @@
@override
bool existsSync() => _editableDirectory.existsSync();
- /// The Linux project CMake specification.
+ @override
File get cmakeFile => _editableDirectory.childFile('CMakeLists.txt');
- /// Contains definitions for FLUTTER_ROOT, LOCAL_ENGINE, and more flags for
- /// the build.
+ @override
File get generatedCmakeConfigFile => ephemeralDirectory.childFile('generated_config.cmake');
- /// Includable CMake with rules and variables for plugin builds.
+ @override
File get generatedPluginCmakeFile => managedDirectory.childFile('generated_plugins.cmake');
/// The directory to write plugin symlinks.