Merge branch 'dbus-1.10'
[platform/upstream/dbus.git] / cmake / modules / MacrosAutotools.cmake
1 #
2 # cmake package for autotools support
3 #
4 # @Author Ralf Habacker
5
6
7 #
8 # load autotools configure file into an internal list named _configure_ac
9 #
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}")
17 endmacro()
18
19 # extracts version information from autoconf config file
20 # and set related cmake variables
21
22 # returns  
23 #   ${prefix}_VERSION
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
31
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})
42 endmacro()
43
44 #
45 # Defines package related variables (PACKAGE_..., PACKAGE and VERSION)
46 # as done by autotools.
47 #
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:
51 #
52 # config.h.template
53 #   ...
54 #   @AUTOPACKAGE_CONFIG_H_TEMPLATE@
55 #   ...
56 #
57 macro(autopackage name version url support_url)
58     # Define to the full name of this package.
59     set(PACKAGE_NAME ${name})
60
61     # Define to the version of this package.
62     set(PACKAGE_VERSION ${version})
63
64     # Define to the home page for this package.
65     set(PACKAGE_URL ${url})
66
67     # Define to the address where bug reports for this package should be sent.
68     set(PACKAGE_BUGREPORT ${support_url})
69
70     # Define to the full name and version of this package.
71     set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
72
73     # Define to the one symbol short name of this package.
74     set(PACKAGE_TARNAME ${PACKAGE_NAME})
75
76     set(PACKAGE ${name})
77     set(VERSION ${DBUS_VERSION_STRING})
78
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@\"
82
83 /* Define to the full name of this package. */
84 #define PACKAGE_NAME \"@PACKAGE_NAME@\"
85
86 /* Define to the full name and version of this package. */
87 #define PACKAGE_STRING \"@PACKAGE_STRING@\"
88
89 /* Define to the one symbol short name of this package. */
90 #define PACKAGE_TARNAME \"@PACKAGE_TARNAME@\"
91
92 /* Define to the home page for this package. */
93 #define PACKAGE_URL \"@PACKAGE_URL@\"
94
95 /* Define to the version of this package. */
96 #define PACKAGE_VERSION \"@PACKAGE_VERSION@\"
97
98 /* defined by autotools package */
99 #define PACKAGE \"@PACKAGE@\"
100 #define VERSION \"@VERSION@\"
101 " AUTOPACKAGE_CONFIG_H_TEMPLATE)
102 endmacro(autopackage)
103
104 #
105 # define a cmake variable from autotools AC_DEFINE statement
106 #
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})
115         endif()
116     endforeach()
117 endmacro()
118
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}")
137             else()
138                 set(file ${key})
139                 string(TOLOWER ${file} filename)
140                 set(check "check_include_file(${filename}.h     ${full_key})")
141                 set(config_define "#cmakedefine ${full_key}")
142             endif()
143             if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*")
144                 message("${check}")
145             endif()
146             if(NOT _config_h_cmake_raw MATCHES "${full_key}")
147                 message("${config_define}")
148             endif()
149         endif()
150     endforeach()
151 endmacro(autoheaderchecks)
152
153 #
154 # parses config.h template and create cmake equivalent 
155 # not implemented yet
156
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})
165                 # find #undef lines
166                 # append to config.h #define <variable-name> <variable-content>
167         endforeach()
168 endmacro()