Merge pull request #224 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / CMakeProjectCreator.pm
blobe1896dc4f1b7d7fef9ca26996bdfa64fb968d73b
1 package CMakeProjectCreator;
3 # ************************************************************
4 # Description : A CMake Project Creator
5 # Author : Chad Elliott
6 # Create Date : 10/10/2022
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use ProjectCreator;
17 use vars qw(@ISA);
18 @ISA = qw(ProjectCreator);
20 # ************************************************************
21 # Subroutine Section
22 # ************************************************************
24 sub pre_generation {
25 my $self = shift;
27 ## For CMake, we are expecting a hybrid of custom types and modules.
28 ## We are turning off all automatic output so that the modules defined
29 ## for CMake can handle these artifacts.
30 foreach my $gentype (keys %{$self->{'generated_exts'}}) {
31 $self->{'generated_exts'}->{$gentype}->{'automatic_out'} = 0;
35 sub default_to_library {
36 ## In case there are only generated source files...
37 return 1;
40 sub need_to_write_project {
41 my $self = shift;
43 ## Because we do not automatically add custom output, it is possible that
44 ## the project only has generated source files and expects them to cause
45 ## an automatic library name to be chosen. If the base
46 ## need_to_write_project() tells us that it's only generated source files
47 ## but the user didn't mark this project as "custom only", then we have to
48 ## override it back to 1 to retain the user provided target name.
49 my $status = $self->SUPER::need_to_write_project();
50 if ($status == 2 && !$self->get_assignment('custom_only')) {
51 $status = 1;
54 return $status;
57 sub get_use_env {
58 ## Override the option getter so that, for CMake, MPC always functions as
59 ## if the -use_env option was supplied on the command line.
60 return 1;
63 sub pre_write_output_file {
64 my $self = shift;
65 return $self->combine_custom_types();
68 sub dollar_special {
69 return 1;
72 sub project_file_prefix {
73 return "CMakeLists.";
76 sub escape_spaces {
77 #my $self = shift;
78 return 1;
81 sub get_dll_exe_template_input_file {
82 return 'cmakeexe';
85 sub get_dll_template_input_file {
86 return 'cmakedll';
89 sub fill_value {
90 my($self, $name) = @_;
92 if ($name eq 'language') {
93 ## Currently, we only support C++
94 return 'CXX' if ($self->get_language() eq Creator::cplusplus());
96 elsif ($name =~ /^env_(\w+)/) {
97 my $dotdir = '${CMAKE_CURRENT_SOURCE_DIR}' .
98 ($1 eq 'libpaths' ? ' ${CMAKE_CURRENT_BINARY_DIR}' : '');
99 my $paths = $self->get_assignment($1);
100 if (defined $paths) {
101 $paths = $self->create_array($paths);
102 foreach my $path (@$paths) {
103 if ($path eq '.') {
104 $path = $dotdir;
106 else {
107 $path =~ s/\$\(([^\)]+)\)/\${$1}/g;
110 return "@$paths";
114 return undef;