2 # cmake package for autotools support
4 # @Author Ralf Habacker
8 # load autotools configure file into an internal list named _configure_ac
10 macro(autoinit config)
11 set(_configure_ac_name ${config})
12 file(READ ${config} _configure_ac_raw)
13 # Convert file contents into a CMake list (where each element in the list
14 # is one line of the file)
15 STRING(REGEX REPLACE ";" "\\\\;" _configure_ac "${_configure_ac_raw}")
16 STRING(REGEX REPLACE "\n" ";" _configure_ac "${_configure_ac}")
19 # extracts version information from autoconf config file
20 # and set related cmake variables
24 # ${prefix}_VERSION_STRING
25 # ${prefix}_MAJOR_VERSION
26 # ${prefix}_MINOR_VERSION
27 # ${prefix}_MICRO_VERSION
28 # ${prefix}_LIBRARY_AGE
29 # ${prefix}_LIBRARY_REVISION
30 # ${prefix}_LIBRARY_CURRENT
32 macro(autoversion prefix)
33 string(TOUPPER ${prefix} prefix_upper)
34 string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac_raw})
35 string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac_raw})
36 string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac_raw})
37 set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION})
38 set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
39 string (REGEX REPLACE ".*LT_AGE=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_configure_ac_raw})
40 string (REGEX REPLACE ".*LT_CURRENT=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_configure_ac_raw})
41 string (REGEX REPLACE ".*LT_REVISION=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_configure_ac_raw})
45 # Defines package related variables (PACKAGE_..., PACKAGE and VERSION)
46 # as done by autotools.
48 # Additional it defines a cmake variable named PACKAGE_CONFIG_H_TEMPLATE
49 # which could be placed in config.h templates to have those variables
50 # defined at code level like shown below:
54 # @AUTOPACKAGE_CONFIG_H_TEMPLATE@
57 macro(autopackage name version url support_url)
58 # Define to the full name of this package.
59 set(PACKAGE_NAME ${name})
61 # Define to the version of this package.
62 set(PACKAGE_VERSION ${version})
64 # Define to the home page for this package.
65 set(PACKAGE_URL ${url})
67 # Define to the address where bug reports for this package should be sent.
68 set(PACKAGE_BUGREPORT ${support_url})
70 # Define to the full name and version of this package.
71 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
73 # Define to the one symbol short name of this package.
74 set(PACKAGE_TARNAME ${PACKAGE_NAME})
77 set(VERSION ${DBUS_VERSION_STRING})
79 string(CONFIGURE "/* generated by cmake macro autopackage */\n
80 /* Define to the address where bug reports for this package should be sent. */
81 #define PACKAGE_BUGREPORT \"@PACKAGE_BUGREPORT@\"
83 /* Define to the full name of this package. */
84 #define PACKAGE_NAME \"@PACKAGE_NAME@\"
86 /* Define to the full name and version of this package. */
87 #define PACKAGE_STRING \"@PACKAGE_STRING@\"
89 /* Define to the one symbol short name of this package. */
90 #define PACKAGE_TARNAME \"@PACKAGE_TARNAME@\"
92 /* Define to the home page for this package. */
93 #define PACKAGE_URL \"@PACKAGE_URL@\"
95 /* Define to the version of this package. */
96 #define PACKAGE_VERSION \"@PACKAGE_VERSION@\"
98 /* defined by autotools package */
99 #define PACKAGE \"@PACKAGE@\"
100 #define VERSION \"@VERSION@\"
101 " AUTOPACKAGE_CONFIG_H_TEMPLATE)
102 endmacro(autopackage)
105 # define a cmake variable from autotools AC_DEFINE statement
107 macro(autodefine name)
108 foreach(line ${_configure_ac})
109 if(line MATCHES ".*AC_DEFINE(.*${name}.*).*")
110 string (REGEX REPLACE ".*AC_DEFINE(.*).*" "\\1" value ${line})
111 string (REGEX REPLACE ".*,(.*),.*" "\\1" value2 ${value})
112 string (REPLACE "[" "" value3 ${value2})
113 string (REPLACE "]" "" value4 ${value3})
114 set(${name} ${value4})
120 # fetch compiler warnings settings from autotools
122 # @param target_warnings the variable name which will contain the warnings keys
123 # @param target_disabled_warnings the variable name which will contain the disabled warnings keys
125 macro(autocompilerwarnings target_warnings target_disabled_warnings)
129 foreach(line ${_configure_ac})
130 if(line MATCHES ".*TP_COMPILER_WARNINGS.*")
132 string(REGEX REPLACE "^.*TP_COMPILER_WARNINGS\\((.*)$" "\\1" temp ${line})
133 set(content "${content}${temp}")
134 elseif(in_warnings EQUAL 1)
135 if(line MATCHES ".*dnl.*")
137 elseif(line MATCHES "\\)$")
138 string(REGEX REPLACE "(.*)\\)$" "\\1" temp ${line})
139 set(content "${content}${temp}")
142 string(STRIP ${line} _line)
143 if(NOT _line STREQUAL "")
144 set(content "${content}${line}")
150 # extract macro parts
151 string(REPLACE ";" "#" temp ${content})
152 string(REPLACE "[" "" temp ${temp})
153 string(REPLACE "]" "" temp ${temp})
154 string(REPLACE "," ";" alist ${temp})
155 list(GET alist 0 flag_name)
156 list(GET alist 2 warnings_flag)
157 list(GET alist 3 no_warnings_flag)
158 string(REPLACE "#" ";" warnings_list ${warnings_flag})
159 string(REPLACE "#" ";" no_warnings_list ${no_warnings_flag})
160 list(REMOVE_AT no_warnings_list 0)
163 foreach(warning ${warnings_list})
164 string(STRIP ${warning} _warning)
165 if(NOT _warning STREQUAL "")
166 set(warnings "${warnings} ${_warning}")
169 set(${target_warnings} "${warnings}")
172 foreach(warning ${no_warnings_list})
173 string(STRIP ${warning} _warning)
174 if(NOT _warning STREQUAL "")
175 set(warnings "${warnings} ${_warning}")
178 set(${target_disabled_warnings} "${warnings}")
180 message("autocompilerwarnings returns: warnings: ${${target_warnings}} disabled_warnings: ${${target_disabled_warnings}}")
184 macro(autoheaderchecks config_h_in configure_checks_file config_h_cmake)
185 file(READ ${configure_checks_file} configure_checks_file_raw)
186 file(READ ${config_h_in} _config_h_in_raw)
187 file(READ ${config_h_cmake} _config_h_cmake_raw)
188 STRING(REGEX REPLACE ";" "\\\\;" _config_h_in "${_config_h_in_raw}")
189 STRING(REGEX REPLACE "\n" ";" _config_h_in "${_config_h_in}")
190 foreach(line ${_config_h_in})
191 #message(STATUS ${line})
192 if(line MATCHES ".*HAVE_.*_H.*")
193 string (REGEX REPLACE ".*HAVE_(.*)_H.*" "\\1" key ${line})
194 set(full_key "HAVE_${key}_H")
195 if(key MATCHES ".*_.*")
196 string(REGEX MATCH "^[A-Z0-9]+" dir ${key})
197 string(REGEX MATCH "[A-Z0-9]+$" file ${key})
198 string(TOLOWER ${dir} dirname)
199 string(TOLOWER ${file} filename)
200 set(check "check_include_file(${dirname}/${filename}.h ${full_key})")
201 set(config_define "#cmakedefine ${full_key}")
204 string(TOLOWER ${file} filename)
205 set(check "check_include_file(${filename}.h ${full_key})")
206 set(config_define "#cmakedefine ${full_key}")
208 if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*")
211 if(NOT _config_h_cmake_raw MATCHES "${full_key}")
212 message("${config_define}")
216 endmacro(autoheaderchecks)
219 # parses config.h template and create cmake equivalent
220 # not implemented yet
222 macro(autoconfig template output)
223 file(READ ${template} contents)
224 # Convert file contents into a CMake list (where each element in the list
225 # is one line of the file)
226 STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
227 STRING(REGEX REPLACE "\n" ";" contents "${contents}")
228 foreach(line contents)
229 message(STATUS ${line})
231 # append to config.h #define <variable-name> <variable-content>