From d0515e88a555325a7255a2fbcaf692949a366362 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sat, 30 Mar 2024 18:18:11 +0100 Subject: [PATCH] Set proper cmake versions for different C/C++ versions --- kmake/src/Exporters/CMakeExporter.ts | 53 +++++++++++++++++++++++- lib/kmake/Exporters/CMakeExporter.js | 49 +++++++++++++++++++++- lib/kmake/Exporters/CMakeExporter.js.map | 2 +- 3 files changed, 101 insertions(+), 3 deletions(-) diff --git a/kmake/src/Exporters/CMakeExporter.ts b/kmake/src/Exporters/CMakeExporter.ts index febebb7cda..1e8fdb249f 100644 --- a/kmake/src/Exporters/CMakeExporter.ts +++ b/kmake/src/Exporters/CMakeExporter.ts @@ -17,9 +17,60 @@ export class CMakeExporter extends Exporter { this.writeFile(path.resolve(to, name, 'CMakeLists.txt')); - this.p('cmake_minimum_required(VERSION 3.10)'); // should be 3.12 to support c++20, 3.20 to support c++23 and 3.21 to support c17/c23 + let cmakeVersion = '3.10'; + + switch (project.cppStd) { + case 'gnu++03': + case 'c++03': + case 'gnu++11': + case 'c++11': + case 'gnu++14': + case 'c++14': + case 'gnu++17': + case 'c++17': + break; + case 'gnu++2a': + case 'c++2a': + case 'gnu++20': + case 'c++20': + cmakeVersion = '3.12'; + break; + case 'gnu++2b': + case 'c++2b': + case 'gnu++23': + case 'c++23': + cmakeVersion = '3.20'; + break; + default: + break; + } + + switch (project.cStd) { + case 'gnu9x': + case 'gnu99': + case 'c9x': + case 'c99': + case 'gnu1x': + case 'gnu11': + case 'c1x': + case 'c11': + break; + case 'gnu18': + case 'gnu17': + case 'c18': + case 'c17': + case 'gnu2x': + case 'c2x': + cmakeVersion = '3.21'; + break; + default: + break; + } + + this.p('cmake_minimum_required(VERSION ' + cmakeVersion + ')'); this.p('project(' + name + ')'); + switch (project.cppStd) { case 'gnu++03': case 'c++03': diff --git a/lib/kmake/Exporters/CMakeExporter.js b/lib/kmake/Exporters/CMakeExporter.js index a41014573c..8b4ce2d80a 100644 --- a/lib/kmake/Exporters/CMakeExporter.js +++ b/lib/kmake/Exporters/CMakeExporter.js @@ -10,7 +10,54 @@ class CMakeExporter extends Exporter_1.Exporter { async exportSolution(project, from, to, platform, vrApi, options) { let name = project.getSafeName(); this.writeFile(path.resolve(to, name, 'CMakeLists.txt')); - this.p('cmake_minimum_required(VERSION 3.10)'); // should be 3.12 to support c++20, 3.20 to support c++23 and 3.21 to support c17/c23 + let cmakeVersion = '3.10'; + switch (project.cppStd) { + case 'gnu++03': + case 'c++03': + case 'gnu++11': + case 'c++11': + case 'gnu++14': + case 'c++14': + case 'gnu++17': + case 'c++17': + break; + case 'gnu++2a': + case 'c++2a': + case 'gnu++20': + case 'c++20': + cmakeVersion = '3.12'; + break; + case 'gnu++2b': + case 'c++2b': + case 'gnu++23': + case 'c++23': + cmakeVersion = '3.20'; + break; + default: + break; + } + switch (project.cStd) { + case 'gnu9x': + case 'gnu99': + case 'c9x': + case 'c99': + case 'gnu1x': + case 'gnu11': + case 'c1x': + case 'c11': + break; + case 'gnu18': + case 'gnu17': + case 'c18': + case 'c17': + case 'gnu2x': + case 'c2x': + cmakeVersion = '3.21'; + break; + default: + break; + } + this.p('cmake_minimum_required(VERSION ' + cmakeVersion + ')'); this.p('project(' + name + ')'); switch (project.cppStd) { case 'gnu++03': diff --git a/lib/kmake/Exporters/CMakeExporter.js.map b/lib/kmake/Exporters/CMakeExporter.js.map index 6a21b2840a..2975456cc5 100644 --- a/lib/kmake/Exporters/CMakeExporter.js.map +++ b/lib/kmake/Exporters/CMakeExporter.js.map @@ -1 +1 @@ -{"version":3,"file":"CMakeExporter.js","sourceRoot":"","sources":["../../../kmake/src/Exporters/CMakeExporter.ts"],"names":[],"mappings":";;;AAEA,6BAA6B;AAK7B,uDAAoD;AAEpD,MAAa,aAAc,SAAQ,mBAAQ;IAC1C,YAAY,OAAY;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgB,EAAE,IAAY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G,EAAE,CAAC;QACnB,KAAK,IAAI,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE;YAClC,SAAS,IAAI,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;SAC/B;QACD,IAAI,CAAC,CAAC,CAAC,wBAAwB,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAAC,CAAC;QAEjE,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD;AAxHD,sCAwHC"} \ No newline at end of file +{"version":3,"file":"CMakeExporter.js","sourceRoot":"","sources":["../../../kmake/src/Exporters/CMakeExporter.ts"],"names":[],"mappings":";;;AAEA,6BAA6B;AAK7B,uDAAoD;AAEpD,MAAa,aAAc,SAAQ,mBAAQ;IAC1C,YAAY,OAAY;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgB,EAAE,IAAY,EAAE,EAAU,EAAE,QAAgB,EAAE,KAAU,EAAE,OAAY;QAC1G,IAAI,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAEjC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAEzD,IAAI,YAAY,GAAG,MAAM,CAAC;QAE1B,QAAQ,OAAO,CAAC,MAAM,EAAE;YACvB,KAAK,SAAS,CAAC;YACf,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC;YACf,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC;YACf,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC;YACf,KAAK,OAAO;gBACX,MAAM;YACP,KAAK,SAAS,CAAC;YACf,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC;YACf,KAAK,OAAO;gBACX,YAAY,GAAG,MAAM,CAAC;gBACtB,MAAM;YACP,KAAK,SAAS,CAAC;YACf,KAAK,OAAO,CAA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