summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2017-04-10 22:37:00 +0200
committerRalf Habacker <ralf.habacker@freenet.de>2017-04-10 22:37:00 +0200
commit119f8811c4e64d099c3917f107f1acc68843ba1c (patch)
tree3daa9189559780066643621f3c98d248752af6b6
parenteb56619aedc667c0d10b2e9630802c24c1a617a3 (diff)
Try to implement auto_ax_compiler_flags.auto-ax-compiler-flags
-rw-r--r--cmake/CMakeLists.txt2
-rw-r--r--cmake/modules/MacrosAutotools.cmake161
2 files changed, 163 insertions, 0 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 1d08c6a52..9b2b96c48 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -24,6 +24,8 @@ endif()
include(MacrosAutotools)
autoinit(../configure.ac)
autoversion(dbus)
+auto_ax_compiler_flags(cflags cxxflags ldflags)
+auto_disable_warnings()
if(EXISTS ../config.h.in)
autoheaderchecks(../config.h.in ConfigureChecks.cmake config.h.cmake)
diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake
index 8bb83cdf3..bba1f4a7a 100644
--- a/cmake/modules/MacrosAutotools.cmake
+++ b/cmake/modules/MacrosAutotools.cmake
@@ -3,6 +3,9 @@
#
# @Author Ralf Habacker
#
+if(COMMAND cmake_policy)
+ cmake_policy(SET CMP0007 NEW)
+endif()
#
# load autotools configure file into an internal list named _configure_ac
@@ -166,3 +169,161 @@ macro(autoconfig template output)
# append to config.h #define <variable-name> <variable-content>
endforeach()
endmacro()
+
+#
+# Parse an m4 macro defined in configure.ac and return macro elements as list
+#
+# The supported format is 'NAME([xxx],[xxx],...)' where each element can be in a
+# separate line.
+#
+# The ',' separated elements are returned as as list with ';' removed from any element
+#
+function(auto_parse_macro search result)
+ set(in_macro 0)
+ set(content "")
+ # parse configure_ac
+ foreach(line ${_configure_ac})
+ if(line MATCHES ".*${search}.*")
+ set(in_macro 1)
+ string(REGEX REPLACE "^.*${search}\\((.*)$" "\\1" _line ${line})
+ string(STRIP ${_line} content)
+ elseif(in_macro EQUAL 1)
+ if(line MATCHES ".*dnl.*")
+ # skip
+ elseif(line MATCHES "\\)$")
+ string(STRIP ${line} _line)
+ string(REGEX REPLACE "^[ ]*(.*)\\)$" "\\1" _line ${_line})
+ set(content "${content}${_line}")
+ string(REPLACE "[" "" content ${content})
+ string(REPLACE "]" "" content ${content})
+ string(REPLACE ";" "" content ${content})
+ string(REPLACE "," ";" content ${content})
+ set(${result} "${content}" PARENT_SCOPE)
+ set(in_macro 0)
+ return()
+ else()
+ string(STRIP ${line} _line)
+ if(NOT _line STREQUAL "")
+ set(content "${content}${_line}")
+ endif()
+ endif()
+ endif()
+ endforeach()
+endfunction()
+
+#
+# Fetch compiler warning flags from autotools AX_COMPILER_FLAGS_XXX macro
+#
+# @param cflags variable returning defined warning flags for compiling C code
+# @param cxxflags variable returning warning flags for compiling C++ code
+# @param ldflags variable returning warning flags for the linker
+#
+# The returned flags are extracted from [EXTRA-BASE-CFLAGS] parameters of
+# AX_COMPILER_FLAGS_XXX macro, see
+# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html
+# for details
+#
+function(auto_ax_compiler_flags cflags cxxflags ldflags)
+ auto_parse_macro("AX_COMPILER_FLAGS_CFLAGS" "flags")
+ list(LENGTH flags len)
+ if (len GREATER 3)
+ list(GET flags 3 var)
+ set(${cflags} "${var}" PARENT_SCOPE)
+ endif()
+ auto_parse_macro("AX_COMPILER_FLAGS_CXXFLAGS" "flags")
+ list(LENGTH flags len)
+ if (len GREATER 3)
+ list(GET flags 3 var)
+ set(${cxxflags} "${var}" PARENT_SCOPE)
+ endif()
+ auto_parse_macro("AX_COMPILER_FLAGS_LDFLAGS" "flags")
+ list(LENGTH flags len)
+ if (len GREATER 3)
+ list(GET flags 3 var)
+ set(${ldflags} "${var}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
+#if test x$enable_asserts = xno; then
+# ....
+# if test x$enable_embedded_tests = xyes; then
+
+function(auto_parse_shell_variable name result)
+ set(in_variable 0)
+ set(in_if 0)
+ foreach(line ${_configure_ac})
+ if(line MATCHES "^(# |dnl).*$")
+ #message("SKIP ${line}")
+ continue()
+ elseif(line MATCHES "^[\t ]*if.*")
+ message("+++if ${line} ${in_if}")
+ string(REGEX REPLACE "^[\t ]*if[\t ]+test[\t ]+(.*)[\t ]+then$" "\\1" condition ${line})
+ string(REGEX REPLACE "x[$]*" "" condition ${condition})
+ string(REGEX REPLACE "\"" "" condition ${condition})
+ set(conditions_${in_if} "${condition}")
+ message("CONDITIONS ${${conditions}_${in_if}}")
+ message("CURRENT CONDITION ${condition}")
+ message("+++if ${line} ${in_if} end")
+ MATH(EXPR in_if "${in_if}+1")
+ elseif(line MATCHES "^[\t ]*fi$")
+ message("+++fi ${line} ${in_if}")
+ MATH(EXPR in_if "${in_if}-1")
+ message("+++fi ${line} ${in_if} end")
+ elseif(line MATCHES "^[ ]*else$")
+ message("+++else ${line} ${in_if}")
+ # handle else case
+ elseif(line MATCHES "^[ ]*else[ ]+if.*$")
+ message("+++else if${line} ${in_if}")
+ string(REGEX REPLACE "^[\t ]*else[ ]+if[\t ]+test[\t ]+(.*)[\t ]+then$" "\\1" condition ${line})
+ string(REGEX REPLACE "x[$]*" "" condition ${condition})
+ string(REGEX REPLACE "\"" "" condition ${condition})
+ set(conditions_${in_if} "${condition}")
+ message("CONDITIONS ${${conditions}_${in_if}}")
+ message("CURRENT CONDITION ${condition}")
+ message("+++elseif ${line} ${in_if} end")
+ elseif(in_if GREATER 0)
+ # handle entries
+ endif()
+ continue()
+ if(line MATCHES "^.*${name}.*$")
+ message("MATCHES ${line}")
+ message("======== ${conditions}")
+ string(REGEX REPLACE "^[\t ]*${name}\"(.*)$" "\\1" _line ${line})
+ string(REPLACE "\"" "" _line ${_line})
+ set(content "${content}${_line}")
+ message("+++++++ ${content}")
+ # single line warning
+ if(line MATCHES ".*\"$")
+ set(${result} "${content}" PARENT_SCOPE)
+ set(in_variable 0)
+ else()
+ set(in_variable 1)
+ endif()
+ elseif(in_variable EQUAL 1)
+ if(line MATCHES "\"$")
+ message("END ${line}")
+ string(STRIP ${line} _line)
+ string(REGEX REPLACE "^[ ]*(.*)\"$" "\\1" _line ${_line})
+ set(content "${content}${_line}")
+ string(REPLACE "\"" "" content ${content})
+ set(${result} "${content}" PARENT_SCOPE)
+ set(in_variable 0)
+ else()
+ message("ADD ${line}")
+ string(STRIP ${line} _line)
+ if(NOT _line STREQUAL "")
+ set(content "${content}${_line}")
+ endif()
+ endif()
+ else()
+ #message("OTHER ${line}")
+ endif()
+ endforeach()
+endfunction()
+
+# fetch disable warnings from autotools build system
+function(auto_disable_warnings)
+ auto_parse_shell_variable("DISABLE_WARNINGS" "warnings")
+ message("?????? ${warnings}")
+endfunction(auto_disable_warnings)