1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
10 ##############################################################################
11 # @file DoxyFilter/CMake.pm
12 # @brief Doxygen filter for CMake.
15 ##############################################################################
17 package BASIS::DoxyFilter::CMake;
18 use base BASIS::DoxyFilter;
20 # ============================================================================
22 # ============================================================================
24 # ----------------------------------------------------------------------------
25 ## @brief Constructs a CMake Doxygen filter.
30 ['start', qr/^\s*if\s*\(/, undef, 'start'], # discard if()'s such that
32 # associated with next
33 # block that is supposed
34 # to be in the then branch.
36 ['start', qr/^\s*include\s*\((.+)\)\s*(#.*)?$/, \&_include, 'start'],
38 ['start', qr/^\s*option\s*\(\s*(\w+)\s+(\"([^\"]|\\\")*[^\\]\")\s+(ON|OFF)\s*\)\s*(#.*)?$/, \&_option, 'start'],
39 ['start', qr/^\s*option(.*)[^\)]\s*(#.*)?$/, \&_option_begin, 'option'],
40 ['option', qr/(^|^.*\s+)\"([^\"]|\\\")*$/, \&_option_line, 'option_doc'],
41 ['option_doc', qr/(^|^.*[^\\])\".*\s+\"([^\"]|\\\")*$/, \&_option_line, 'option_doc'],
42 ['option_doc', qr/(^|^.*[^\\])\".*\)\s*(#.*)?$/, \&_option_end, 'start'],
43 ['option_doc', qr/(^|^.*[^\\])\".*$/, \&_option_line, 'option'],
44 ['option_doc', qr/.*/, \&_option_line, 'option_doc'],
45 ['option', qr/^.*\)\s*(#.*)?$/, \&_option_end, 'start'],
46 ['option', qr/.*$/, \&_option_line, 'option'],
48 ['start', qr/^\s*(set|basis_set_if_empty|basis_set_if_not_set|basis_set_script_path)\s*\(\s*(\w+)\s+(.*)\s*\)\s*(#.*)?$/, \&_set_nocache, 'start'],
49 ['start', qr/^\s*(set|basis_set_if_empty|basis_set_if_not_set|basis_set_script_path)\s*\(\s*(\w+)\s+(.*)\s+CACHE\s+(\w+)\s+(.*)\)\s*(#.*)?$/, \&_set_cache, 'start'],
50 ['start', qr/^\s*(set|basis_set_if_empty|basis_set_if_not_set|basis_set_script_path)(.*)[^\)]\s*(#.*)?$/, \&_set_begin, 'set'],
51 ['set', qr/(^|^.*\s+)\"([^\"]|\\\")*$/, \&_set_line, 'set_value'],
52 ['set_value', qr/(^|^.*[^\\])\".*\s+\"([^\"]|\\\")*$/, \&_set_line, 'set_value'],
53 ['set_value', qr/(^|^.*[^\\])\".*\)\s*(#.*)?$/, \&_set_end, 'start'],
54 ['set_value', qr/(^|^.*[^\\])\".*$/, \&_set_line, 'set'],
55 ['set_value', qr/.*/, \&_set_line, 'set_value'],
56 ['set', qr/^.*\)\s*(#.*)?$/, \&_set_end, 'start'],
57 ['set', qr/.*$/, \&_set_line, 'set'],
59 ['start', qr/^\s*(macro|function)\s*\(\s*(\w+)(\s+[^\)]*)?\)\s*(#.*)?$/, \&_fndef, 'fnbody'],
60 ['start', qr/^\s*(macro|function)\s*\(\s*(\w+)(\s+[^\)]*)?\s*(#.*)?$/, \&_fndef_begin, 'fndef'],
61 ['fndef', qr/^[^\)]*$/, \&_fndef_line, 'fndef'],
62 ['fndef', qr/^.*\)\s*(#.*)?$/, \&_fndef_end, 'fnbody'],
63 ['fnbody', qr/^\s*end(macro|function)\s*\(\s*(\w+)?\s*\)\s*(#.*)?$/, undef, 'start'],
64 ['fnbody', qr/^\s*end(macro|function)\s*.*[^\)]\s*(#.*)?$/, undef, 'fnend'],
65 ['fnend', qr/^.*\)\s*(#.*)?$/, undef, 'start'],
69 # ============================================================================
71 # ============================================================================
73 # ----------------------------------------------------------------------------
75 # ----------------------------------------------------------------------------
77 # ----------------------------------------------------------------------------
80 my ($self, $module) = @_;
81 $module =~ s/^\s*\"?//;
82 $module =~ s/\"?\s*$//;
83 $module =~ s/\${(CMAKE_CURRENT_LIST_DIR|BASIS_MODULE_PATH|\${NS}MODULE_PATH)}|\@BASIS_MODULE_PATH\@//;
84 $module =~ s/ (OPTIONAL|NO_POLICY_SCOPE)//g;
85 $module =~ s/\.cmake$//;
86 $self->_append("#include \"$module.cmake\"");
89 # ----------------------------------------------------------------------------
91 # ----------------------------------------------------------------------------
93 # ----------------------------------------------------------------------------
97 $self->_option_append($self->{'line'});
100 # ----------------------------------------------------------------------------
104 my $line = $self->{'line'};
105 $line =~ s/\s*#.*$//;
106 $self->{'buffer'} = "$line";
109 # ----------------------------------------------------------------------------
113 my $line = $self->{'line'};
114 $line =~ s/\s*#.*$//;
115 $self->{'buffer'} .= " $line";
118 # ----------------------------------------------------------------------------
122 my $line = $self->{'line'};
123 $self->{'buffer'} .= " $line";
124 $self->_option_append($self->{'buffer'});
127 # ----------------------------------------------------------------------------
130 my ($self, $line) = @_;
131 if ($line =~ /^\s*option\s*\(\s*(\w+)\s+(\"([^\"]|\\\")*[^\\]\")\s+(ON|OFF)\s*\)\s*(#.*)?$/) {
134 $self->_append("option $name = $default;");
138 # ----------------------------------------------------------------------------
140 # ----------------------------------------------------------------------------
142 # ----------------------------------------------------------------------------
145 my ($self, $setfn, $name, $value, $type) = @_;
147 $self->_append("$type $name;");
150 # ----------------------------------------------------------------------------
153 my ($self, $setfn, $name, $value) = @_;
154 $self->_append("cmake $name;");
157 # ----------------------------------------------------------------------------
161 my $line = $self->{'line'};
162 $line =~ s/\s*#.*$//;
163 $self->{'buffer'} = "$line";
166 # ----------------------------------------------------------------------------
170 my $line = $self->{'line'};
171 $line =~ s/\s*#.*$//;
172 $self->{'buffer'} .= " $line";
175 # ----------------------------------------------------------------------------
179 my $line = $self->{'line'};
180 $self->{'buffer'} .= " $line";
181 if ($self->{'buffer'} =~ /\s*(set|basis_set_if_empty|basis_set_if_not_set)\s*\(\s*(\w+)\s+(\"([^\"]|\\\")*[^\\]\"|[^\s]+)(\s+PARENT_SCOPE|\s+CACHE\s+(\w+)\s+(.*))?\s*\)\s*$/) {
185 $type = lc $6 if defined $6;
186 $value =~ s/^\s*\"?//;
187 $value =~ s/\"?\s*$//;
188 $self->_append("$type $name = \"$value\"");
192 # ----------------------------------------------------------------------------
194 # ----------------------------------------------------------------------------
196 # ----------------------------------------------------------------------------
199 my ($self, $dummy, $name) = @_;
200 if ($name =~ m/^_/) {
203 $self->_fndef_append($self->{'line'});
207 # ----------------------------------------------------------------------------
210 my ($self, $dummy, $name) = @_;
211 if ($name =~ m/^_/) {
214 $self->{'buffer'} = "$self->{'line'}";
218 # ----------------------------------------------------------------------------
222 $self->{'buffer'} .= " $self->{'line'}" unless $self->{'skip'};
225 # ----------------------------------------------------------------------------
229 if ($self->{'skip'}) {
233 $self->{'buffer'} .= " $self->{'line'}";
234 $self->_fndef_append($self->{'buffer'});
238 # ----------------------------------------------------------------------------
241 my ($self, $line) = @_;
242 if ($line =~ /^\s*(macro|function)\s*\(\s*(\w+)(\s+[^\)]*)?\)\s*(#.*)?$/) {
250 @params = split /\s+/, $params;
251 for (my $i = 0; $i <= $#params; $i++) {
253 foreach my $paramdoc (@{$self->{'params'}}) {
254 if ($paramdoc->{'name'} eq $params[$i]) {
255 $dir = $paramdoc->{'dir'};
259 $params[$i] = "$dir $params[$i]";
262 foreach my $paramdoc (@{$self->{'params'}}) {
263 push @params, $paramdoc->{'dir'} . " " . $paramdoc->{'name'}
264 if $paramdoc->{'name'} =~ /^ARG(N|V[0-9])$/;
266 $self->_append("/// \@returns Nothing.") if not $self->{'returndoc'};
267 $self->_append("$type $name(" . join(', ', @params) . ");");