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})
119 macro(autoheaderchecks config_h_in configure_checks_file config_h_cmake)
120 file(READ ${configure_checks_file} configure_checks_file_raw)
121 file(READ ${config_h_in} _config_h_in_raw)
122 file(READ ${config_h_cmake} _config_h_cmake_raw)
123 STRING(REGEX REPLACE ";" "\\\\;" _config_h_in "${_config_h_in_raw}")
124 STRING(REGEX REPLACE "\n" ";" _config_h_in "${_config_h_in}")
125 foreach(line ${_config_h_in})
126 #message(STATUS ${line})
127 if(line MATCHES ".*HAVE_.*_H.*")
128 string (REGEX REPLACE ".*HAVE_(.*)_H.*" "\\1" key ${line})
129 set(full_key "HAVE_${key}_H")
130 if(key MATCHES ".*_.*")
131 string(REGEX MATCH "^[A-Z0-9]+" dir ${key})
132 string(REGEX MATCH "[A-Z0-9]+$" file ${key})
133 string(TOLOWER ${dir} dirname)
134 string(TOLOWER ${file} filename)
135 set(check "check_include_file(${dirname}/${filename}.h ${full_key})")
136 set(config_define "#cmakedefine ${full_key}")
139 string(TOLOWER ${file} filename)
140 set(check "check_include_file(${filename}.h ${full_key})")
141 set(config_define "#cmakedefine ${full_key}")
143 if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*")
146 if(NOT _config_h_cmake_raw MATCHES "${full_key}")
147 message("${config_define}")
151 endmacro(autoheaderchecks)
154 # parses config.h template and create cmake equivalent
155 # not implemented yet
157 macro(autoconfig template output)
158 file(READ ${template} contents)
159 # Convert file contents into a CMake list (where each element in the list
160 # is one line of the file)
161 STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
162 STRING(REGEX REPLACE "\n" ";" contents "${contents}")
163 foreach(line contents)
164 message(STATUS ${line})
166 # append to config.h #define <variable-name> <variable-content>