summaryrefslogtreecommitdiff
path: root/cmake/MacrosAutotools.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/MacrosAutotools.cmake')
-rw-r--r--cmake/MacrosAutotools.cmake47
1 files changed, 47 insertions, 0 deletions
diff --git a/cmake/MacrosAutotools.cmake b/cmake/MacrosAutotools.cmake
new file mode 100644
index 0000000..08c95d1
--- /dev/null
+++ b/cmake/MacrosAutotools.cmake
@@ -0,0 +1,47 @@
+#
+# @Author Ralf Habacker
+#
+# extracts version information from autoconf config file
+# and set related cmake variables
+#
+# returns
+# ${prefix}_VERSION
+# ${prefix}_VERSION_STRING
+# ${prefix}_MAJOR_VERSION
+# ${prefix}_MINOR_VERSION
+# ${prefix}_MICRO_VERSION
+#
+macro(autoversion config prefix)
+ file (READ ${config} _configure_ac)
+ string(TOUPPER ${prefix} prefix_upper)
+ string (REGEX REPLACE ".*${prefix}_major_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_minor_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_micro_version[]]*,[ ]*([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac})
+ set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION})
+ set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
+
+endmacro()
+
+#
+# parses config.h template and create cmake equivalent
+# not implemented yet
+#
+macro(autoconfig template output)
+ file(READ ${template} contents)
+ # Convert file contents into a CMake list (where each element in the list
+ # is one line of the file)
+ STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
+ STRING(REGEX REPLACE "\n" ";" contents "${contents}")
+ #message(STATUS ${contents})
+ foreach(line ${contents})
+ if(line MATCHES "#undef HAVE")
+ STRING(REGEX REPLACE "#undef (.*)$" "#cmakedefine \\1 @\\1@" line "${line}")
+ elseif(line MATCHES "#undef")
+ STRING(REGEX REPLACE "#undef (.*)$" "#cmakedefine \\1 \"@\\1@\"" line "${line}")
+ endif()
+ #message(STATUS ${line})
+ # append to config.h #define <variable-name> <variable-content>
+ set(outlines "${outlines}\n${line}")
+ endforeach()
+ file(WRITE ${output} ${outlines})
+endmacro()