@@ -22,11 +22,13 @@ public record ExternalProject(String name, String gitUrl, String gitTag) {}
2222 private final List <ExternalProject > externalProjects = new ArrayList <>();
2323 private final List <VcpkgObject > vcpkgObjects = new ArrayList <>();
2424 private final Set <String > vcpkgDependencies = new LinkedHashSet <>(); // Want to element keep order (to make it easier for a human to read).
25+ private final Set <String > fetchedVcpkgDependencies = new LinkedHashSet <>();
2526 private final Set <String > linkLibraries = new LinkedHashSet <>();
2627 private final Set <String > sources = new LinkedHashSet <>();
2728 private final Set <String > extraFiles = new LinkedHashSet <>();
2829 private String description = "Description" ;
2930 private String author = "" ;
31+ private final List <VcpkgConfigurationObject .Registry > registries = new ArrayList <>();
3032
3133 public CMakeBuilder (FileSystem fileSystem , Github github ) {
3234 this .fileSystem = fileSystem ;
@@ -38,11 +40,25 @@ public CMakeBuilder addExternalProjects(String name, String gitUrl, String gitTa
3840 return this ;
3941 }
4042
43+ public CMakeBuilder addRegistry (String owner , String repo , String ... packages ) {
44+ String commitSha = github .fetchLatestCommitSHA (owner , repo );
45+ var registry = new VcpkgConfigurationObject .Registry ();
46+ registry .setKind ("git" );
47+ registry .setBaseline (commitSha );
48+ registry .setRepository (Github .getRepositoryUrl (owner , repo ));
49+ if (packages != null && packages .length > 0 ) {
50+ registry .setPackages (List .of (packages ));
51+ }
52+ registries .add (registry );
53+ return this ;
54+ }
55+
4156 public CMakeBuilder addExternalProjectsWithDependencies (String owner , String repo ) {
42- var repositoryUrl = github .getRepositoryUrl (owner , repo );
57+ var repositoryUrl = Github .getRepositoryUrl (owner , repo );
4358 String commitSha = github .fetchLatestCommitSHA (owner , repo );
4459 var vcpkgObject = github .fetchVcpkgObject (owner , repo , commitSha );
4560 vcpkgObjects .add (vcpkgObject );
61+ fetchedVcpkgDependencies .addAll (vcpkgObject .getDependencies ());
4662 return addExternalProjects (repo , repositoryUrl , commitSha );
4763 }
4864
@@ -94,12 +110,13 @@ public void buildFiles() {
94110 fileSystem .copyResourceTo ("CMakePresets.json" );
95111 addExtraFile ("vcpkg.json" );
96112 saveVcpkgJson ();
113+ saveVcpkgConfigurationJson ();
97114
98115 fileSystem .copyResourceTo ("gitattributes" ,".gitattributes" );
99116 fileSystem .copyResourceTo ("gitignore" , ".gitignore" );
100117
101118 if (!externalProjects .isEmpty ()) {
102- fileSystem .saveFileFromTemplate (Map .of ("externalProjects" , externalProjects ), "ExternalFetchContent.ftl " );
119+ fileSystem .saveFileFromTemplate (Map .of ("externalProjects" , externalProjects ), "ExternalFetchContent.cmake " );
103120 addExtraFile ("ExternalFetchContent.cmake" );
104121 }
105122
@@ -123,12 +140,29 @@ private void saveGithubAction() {
123140 fileSystem .saveFileFromTemplate (data , ".github/workflows/ci.yml" );
124141 }
125142
143+ private void saveVcpkgConfigurationJson () {
144+ var newVcpkgConfiguration = new VcpkgConfigurationObject ();
145+ var defaultRegistry = new VcpkgConfigurationObject .DefaultRegistry ();
146+ newVcpkgConfiguration .setDefaultRegistry (defaultRegistry );
147+ defaultRegistry .setKind ("git" );
148+ var commitSHA = github .fetchLatestCommitSHA ("microsoft" , "vcpkg" );
149+ defaultRegistry .setBaseline (commitSHA );
150+ defaultRegistry .setRepository (Github .getRepositoryUrl ("microsoft" , "vcpkg" ));
151+
152+ if (!registries .isEmpty ()) {
153+ newVcpkgConfiguration .setRegistries (registries );
154+ }
155+
156+ fileSystem .saveToFile (newVcpkgConfiguration , "vcpkg-configuration.json" );
157+ }
158+
126159 private void saveVcpkgJson () {
127160 var newVcpkgObject = new VcpkgObject ();
128161 newVcpkgObject .setName (fileSystem .getProjectName ().toLowerCase ());
129162 newVcpkgObject .setDescription (description );
130163
131164 vcpkgDependencies .forEach (newVcpkgObject ::addDependency );
165+ fetchedVcpkgDependencies .forEach (newVcpkgObject ::addDependency );
132166
133167 if (testProject ) {
134168 newVcpkgObject .addDependency ("gtest" );
0 commit comments