summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Elliott <elliottc@objectcomputing.com>2022-11-15 07:28:29 -0600
committerChad Elliott <elliottc@objectcomputing.com>2022-11-15 07:28:29 -0600
commit1d04f7001338262563dd1e527015366a6bf2fa23 (patch)
tree0df1927f8bd2e721027ff879397efd2955862854
parentfe2179434123896ad860c6ae3f092c7ab86f4c84 (diff)
downloadMPC-1d04f7001338262563dd1e527015366a6bf2fa23.tar.gz
Added a template function to help determine if a variable value is a CMake macro usage. This allows us to handle those values in a special way in the template to allow conditionally linking in libraries.
-rw-r--r--modules/TemplateParser.pm38
-rw-r--r--templates/cmake.mpd11
2 files changed, 47 insertions, 2 deletions
diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm
index f8fddaef..d2dd92e6 100644
--- a/modules/TemplateParser.pm
+++ b/modules/TemplateParser.pm
@@ -69,6 +69,7 @@ my %keywords = ('if' => 0,
'reverse' => $get_type|$perform_type,
'sort' => $get_type|$perform_type,
'uniq' => $get_type|$perform_type,
+ 'cmake_macro' => $get_type|$perform_type|$doif_type,
'multiple' => $get_type|$doif_type|$get_combined_type,
'starts_with' => $get_type|$doif_type|$get_combined_type,
'ends_with' => $get_type|$doif_type|$get_combined_type,
@@ -1721,6 +1722,43 @@ sub handle_basename {
}
+sub actual_cmake_macro {
+ my($self, $value) = @_;
+ return $1 if ($value =~ /^\$\{(\w+)\}$/);
+ return '';
+}
+
+
+sub perform_cmake_macro {
+ my($self, $value) = @_;
+ my @val;
+ foreach my $val (@$value) {
+ push(@val, $self->actual_cmake_macro($val));
+ }
+ return @val;
+}
+
+
+sub get_cmake_macro {
+ my($self, $name) = @_;
+ return $self->actual_cmake_macro($self->get_value_with_default($name));
+}
+
+
+sub doif_cmake_macro {
+ my($self, $value) = @_;
+ return (defined $value && $value ne '');
+}
+
+
+sub handle_cmake_macro {
+ my($self, $name) = @_;
+
+ $self->append_current(
+ $self->actual_cmake_macro($self->get_value_with_default($name)));
+}
+
+
sub handle_basenoextension {
my($self, $name) = @_;
my $val = $self->tp_basename($self->get_value_with_default($name));
diff --git a/templates/cmake.mpd b/templates/cmake.mpd
index f3e20dd9..9d929dd4 100644
--- a/templates/cmake.mpd
+++ b/templates/cmake.mpd
@@ -13,10 +13,17 @@ find_package(<%package%> REQUIRED)
set(SOURCE_FILES_<%uc(normalize(project_name))%> <%source_files%>)
<%if(libs || lit_libs || pure_libs)%>
+<%foreach(libs)%>
+<%if(cmake_macro(lib))%>
+if(<%cmake_macro(lib)%>)
+ set(<%cmake_macro(lib)%>_DEFINED TRUE)
+endif()
+<%endif%>
+<%endfor%>
if(CMAKE_CONFIGURATION_TYPES)
-set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%> <%foreach(configurations)%><%fornotfirst(" ")%>$<$<CONFIG:<%configuration%>>:<%foreach(libs)%><%fornotfirst(" ")%><%lib%>${LIBRARY_DECORATOR}<%lib_modifier%><%endfor%>><%fornotlast("\n")%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
+set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%> <%foreach(configurations)%><%fornotfirst(" ")%>$<$<CONFIG:<%configuration%>>:<%foreach(libs)%><%fornotfirst(" ")%><%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR}<%lib_modifier%>,><%else%><%lib%>${LIBRARY_DECORATOR}<%lib_modifier%><%endif%><%endfor%>><%fornotlast("\n")%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
else()
-set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%lib%>${LIBRARY_DECORATOR}<%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
+set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR},><%else%><%lib%>${LIBRARY_DECORATOR}<%endif%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
endif()
<%endif%>
set(PROJECT_TARGET_<%uc(normalize(project_name))%> <%if(exename)%><%exename%><%else%><%if(sharedname)%><%sharedname%>${LIBRARY_DECORATOR}<%else%><%if(staticname)%><%staticname%>${LIBRARY_DECORATOR}<%else%><%project_name%>${LIBRARY_DECORATOR}<%endif%><%endif%><%endif%>)