summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorChad Elliott <elliottc@objectcomputing.com>2022-10-10 13:22:25 -0500
committerChad Elliott <elliottc@objectcomputing.com>2022-10-10 13:22:25 -0500
commite6d869bed6cacb8efae257d265bb7b97f169d8a5 (patch)
tree5b8ee75794aefd89b741cfe1310fdf5259d0f8b1 /modules
parent44cc597f29aea73d9806324dae77fa2c5a71cb2a (diff)
downloadMPC-e6d869bed6cacb8efae257d265bb7b97f169d8a5.tar.gz
Initial commit of experimental support of CMake.
Diffstat (limited to 'modules')
-rw-r--r--modules/CMakeProjectCreator.pm105
-rw-r--r--modules/CMakeWorkspaceCreator.pm56
2 files changed, 161 insertions, 0 deletions
diff --git a/modules/CMakeProjectCreator.pm b/modules/CMakeProjectCreator.pm
new file mode 100644
index 00000000..991a8a82
--- /dev/null
+++ b/modules/CMakeProjectCreator.pm
@@ -0,0 +1,105 @@
+package CMakeProjectCreator;
+
+# ************************************************************
+# Description : A CMake Project Creator
+# Author : Chad Elliott
+# Create Date : 10/10/2022
+# ************************************************************
+
+# ************************************************************
+# Pragmas
+# ************************************************************
+
+use strict;
+
+use ProjectCreator;
+
+use vars qw(@ISA);
+@ISA = qw(ProjectCreator);
+
+# ************************************************************
+# Data Section
+# ************************************************************
+
+## NOTE: We call the constant as a function to support Perl 5.6.
+my %info = (Creator::cplusplus() => {'template' => 'cmake'});
+
+# ************************************************************
+# Subroutine Section
+# ************************************************************
+
+sub dollar_special {
+ return 1;
+}
+
+sub project_file_prefix {
+ return "CMakeLists.";
+}
+
+sub languageSupported {
+ return defined $info{$_[0]->get_language()};
+}
+
+sub escape_spaces {
+ #my $self = shift;
+ return 1;
+}
+
+sub get_template {
+ return $info{$_[0]->get_language()}->{'template'};
+}
+
+sub fill_value {
+ my($self, $name) = @_;
+
+ if ($name eq 'language') {
+ ## Currently, we only support C++
+ return 'CXX' if ($self->get_language() eq Creator::cplusplus());
+ }
+ elsif ($name eq 'env_includes') {
+ my $includes = $self->get_assignment('includes');
+ if (defined $includes) {
+ $includes = $self->create_array($includes);
+ foreach my $include (@$includes) {
+ $include =~ s/\$\(([^\)]+)\)/\$ENV{$1}/g;
+ }
+ return "@$includes";
+ }
+ }
+ elsif ($name eq 'non_generated_sources') {
+ ## Get our list of source files, which will contain files added by the user
+ ## as well as files generated by custom commands.
+ my $tag = 'source_files';
+ my @list = $self->get_component_list($tag);
+
+ my $ctypes = $self->get_assignment('custom_types');
+ if (defined $ctypes) {
+ $ctypes = $self->create_array($ctypes);
+
+ ## Get a list of files that exist within @list that are generated by
+ ## custom commands.
+ my @added;
+ foreach my $ctype (@$ctypes) {
+ foreach my $file (@list) {
+ $self->list_generated_file($ctype, $tag, \@added, $file);
+ }
+ }
+
+ ## Any file in @added needs to be removed from @list
+ foreach my $added (@added) {
+ for(my $i = 0; $i <= $#list; $i++) {
+ if ($list[$i] eq $added) {
+ splice(@list, $i, 1);
+ $i--;
+ }
+ }
+ }
+ }
+
+ return "@list";
+ }
+
+ return undef;
+}
+
+1;
diff --git a/modules/CMakeWorkspaceCreator.pm b/modules/CMakeWorkspaceCreator.pm
new file mode 100644
index 00000000..6f0aa106
--- /dev/null
+++ b/modules/CMakeWorkspaceCreator.pm
@@ -0,0 +1,56 @@
+package CMakeWorkspaceCreator;
+
+# ************************************************************
+# Description : A CMake Workspace creator
+# Author : Chad Elliott
+# Create Date : 10/10/2022
+# ************************************************************
+
+# ************************************************************
+# Pragmas
+# ************************************************************
+
+use strict;
+use File::Basename;
+
+use CMakeProjectCreator;
+use WorkspaceCreator;
+
+use vars qw(@ISA);
+@ISA = qw(WorkspaceCreator);
+
+# ************************************************************
+# Subroutine Section
+# ************************************************************
+
+sub write_and_compare_file {
+ my($self, $outdir, $oname, $func, @params) = @_;
+ my $status = 1;
+ my $errorString = '';
+
+ ## Rename the first (and hopefully the only) project in the directory to what
+ ## CMake expects.
+ my %dirs;
+ foreach my $entry (@{$self->get_projects()}) {
+ my $dir = dirname($entry);
+ if (!exists $dirs{$dir}) {
+ ## Keep track of the project existing in this directory
+ $dirs{$dir} = 1;
+
+ ## Rename the project file to CMakeLists.txt and if it fails, we need to
+ ## propagate that back to the caller.
+ if (rename($entry, "$dir/CMakeLists.txt") == 0) {
+ $status = 0;
+ $errorString = "Unable to rename $entry";
+ last;
+ }
+ }
+ else {
+ $self->warning("Multiple projects in the same workspace are not supported");
+ }
+ }
+
+ return $status, $errorString;
+}
+
+1;