Skip to content

Commit

Permalink
Set proper cmake versions for different C/C++ versions
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Mar 30, 2024
1 parent 0ffb13c commit d0515e8
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
53 changes: 52 additions & 1 deletion kmake/src/Exporters/CMakeExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
49 changes: 48 additions & 1 deletion lib/kmake/Exporters/CMakeExporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/kmake/Exporters/CMakeExporter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0515e8

Please sign in to comment.