summaryrefslogtreecommitdiff
path: root/modules/CMakeProjectCreator.pm
diff options
context:
space:
mode:
Diffstat (limited to 'modules/CMakeProjectCreator.pm')
-rw-r--r--modules/CMakeProjectCreator.pm105
1 files changed, 105 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;