summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-23 15:58:17 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-23 16:09:50 -0200
commitf59dfc3ab8ca43761540c0f0d1e37c75740aa0f9 (patch)
treee1d2ba8f29888a7becc706c77c99e35903811d95
parente8f2bdb079598ff406a2c8010cc8745d47ecc010 (diff)
cmake: move functions to EflMacros.cmake
-rw-r--r--cmake/helpers/CommonHeaderChecks.cmake139
-rw-r--r--cmake/helpers/EflMacros.cmake140
2 files changed, 140 insertions, 139 deletions
diff --git a/cmake/helpers/CommonHeaderChecks.cmake b/cmake/helpers/CommonHeaderChecks.cmake
index c895f793e0..a106c9db4e 100644
--- a/cmake/helpers/CommonHeaderChecks.cmake
+++ b/cmake/helpers/CommonHeaderChecks.cmake
@@ -1,120 +1,3 @@
1unset(HEADER_FILE_CONTENT CACHE)
2
3# HEADER_CHECK(header [NAME variable] [INCLUDE_FILES extra1.h .. extraN.h])
4#
5# Check if the header file exists, in such case define variable
6# in configuration file.
7#
8# Variable defaults to HAVE_${HEADER}, where HEADER is the uppercase
9# representation of the first parameter. It can be overridden using
10# NAME keyword.
11#
12# To include extra files, then use INCLUDE_FILES keyword.
13function(HEADER_CHECK header)
14 string(TOUPPER HAVE_${header} var)
15 string(REGEX REPLACE "[^a-zA-Z0-9]" "_" var "${var}")
16 string(REGEX REPLACE "_{2,}" "_" var "${var}")
17
18 cmake_parse_arguments(PARAMS "" "NAME" "INCLUDE_FILES" ${ARGN})
19
20 if(PARAMS_NAME)
21 set(var ${PARAMS_NAME})
22 endif()
23
24 set(CMAKE_EXTRA_INCLUDE_FILES "${PARAMS_INCLUDE_FILES}")
25
26 CHECK_INCLUDE_FILE(${header} ${var})
27
28 if(${${var}})
29 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
30 else()
31 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
32 endif()
33endfunction()
34
35# FUNC_CHECK(func [NAME variable]
36# [INCLUDE_FILES header1.h .. headerN.h]
37# [LIBRARIES lib1 ... libN]
38# [DEFINITIONS -DA=1 .. -DN=123]
39# [FLAGS -cmdlineparam1 .. -cmdlineparamN]
40# [CXX])
41#
42# Check if the function exists, in such case define variable in
43# configuration file.
44#
45# Variable defaults to HAVE_${FUNC}, where FUNC is the uppercase
46# representation of the first parameter. It can be overridden using
47# NAME keyword.
48#
49# To define include files use INCLUDE_FILES keyword.
50#
51# To use C++ compiler, use CXX keyword
52function(FUNC_CHECK func)
53 string(TOUPPER HAVE_${func} var)
54 string(REGEX REPLACE "_{2,}" "_" var "${var}")
55
56 cmake_parse_arguments(PARAMS "CXX" "NAME" "INCLUDE_FILES;LIBRARIES;DEFINITIONS;FLAGS" ${ARGN})
57
58 set(CMAKE_REQUIRED_LIBRARIES "${PARAMS_LIBRARIES}")
59 set(CMAKE_REQUIRED_DEFINITIONS "${PARAMS_DEFINITIONS}")
60 set(CMAKE_REQUIRED_FLAGS "${PARAMS_FLAGS}")
61
62 if(PARAMS_CXX)
63 check_cxx_symbol_exists(${func} "${PARAMS_INCLUDE_FILES}" ${var})
64 else()
65 check_symbol_exists(${func} "${PARAMS_INCLUDE_FILES}" ${var})
66 endif()
67
68 if(${${var}} )
69 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
70 else()
71 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
72 endif()
73endfunction()
74
75# TYPE_CHECK(type [NAME variable]
76# [INCLUDE_FILES file1.h ... fileN.h]
77# [LIBRARIES lib1 ... libN]
78# [DEFINITIONS -DA=1 .. -DN=123]
79# [FLAGS -cmdlineparam1 .. -cmdlineparamN]
80# [CXX])
81#
82# Check if the type exists and its size, in such case define variable
83# in configuration file.
84#
85# Variable defaults to HAVE_${TYPE}, where TYPE is the uppercase
86# representation of the first parameter. It can be overridden using
87# NAME keyword.
88#
89# To define include files use INCLUDE_FILES keyword.
90#
91# To use C++ compiler, use CXX keyword
92function(TYPE_CHECK type)
93 string(TOUPPER HAVE_${type} var)
94 string(REGEX REPLACE "_{2,}" "_" var "${var}")
95
96 cmake_parse_arguments(PARAMS "CXX" "NAME" "INCLUDE_FILES;LIBRARIES;DEFINITIONS;FLAGS" ${ARGN})
97
98 set(CMAKE_REQUIRED_LIBRARIES "${PARAMS_LIBRARIES}")
99 set(CMAKE_REQUIRED_DEFINITIONS "${PARAMS_DEFINITIONS}")
100 set(CMAKE_REQUIRED_FLAGS "${PARAMS_FLAGS}")
101 set(CMAKE_EXTRA_INCLUDE_FILES "${PARAMS_INCLUDE_FILES}")
102
103 if(PARAMS_CXX)
104 set(lang CXX)
105 else()
106 set(lang C)
107 endif()
108
109 CHECK_TYPE_SIZE(${type} ${var} LANGUAGE ${lang})
110
111 if(HAVE_${var})
112 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
113 else()
114 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
115 endif()
116endfunction()
117
118 1
119FUNC_CHECK(geteuid INCLUDE_FILES unistd.h) 2FUNC_CHECK(geteuid INCLUDE_FILES unistd.h)
120FUNC_CHECK(getuid INCLUDE_FILES unistd.h) 3FUNC_CHECK(getuid INCLUDE_FILES unistd.h)
@@ -151,25 +34,3 @@ HEADER_CHECK(sys/types.h)
151HEADER_CHECK(execinfo.h) 34HEADER_CHECK(execinfo.h)
152HEADER_CHECK(libunwind.h NAME HAVE_UNWIND) 35HEADER_CHECK(libunwind.h NAME HAVE_UNWIND)
153 36
154# EFL_HEADER_CHECKS_FINALIZE(file)
155#
156# Write the configuration gathered with HEADER_CHECK(), TYPE_CHECK()
157# and FUNC_CHECK() to the given file.
158function(EFL_HEADER_CHECKS_FINALIZE file)
159 file(WRITE ${file}.new ${HEADER_FILE_CONTENT})
160 if (NOT EXISTS ${file})
161 file(RENAME ${file}.new ${file})
162 message(STATUS "${file} was generated.")
163 else()
164 file(MD5 ${file}.new _new_md5)
165 file(MD5 ${file} _old_md5)
166 if(_new_md5 STREQUAL _old_md5)
167 message(STATUS "${file} is unchanged.")
168 else()
169 file(REMOVE ${file})
170 file(RENAME ${file}.new ${file})
171 message(STATUS "${file} was updated.")
172 endif()
173 endif()
174 unset(HEADER_FILE_CONTENT CACHE) # allow to reuse with an empty contents
175endfunction()
diff --git a/cmake/helpers/EflMacros.cmake b/cmake/helpers/EflMacros.cmake
index 516658fae6..dee0c565e7 100644
--- a/cmake/helpers/EflMacros.cmake
+++ b/cmake/helpers/EflMacros.cmake
@@ -127,6 +127,146 @@ function(EFL_FINALIZE)
127 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS}) 127 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS})
128endfunction() 128endfunction()
129 129
130unset(HEADER_FILE_CONTENT CACHE)
131
132# HEADER_CHECK(header [NAME variable] [INCLUDE_FILES extra1.h .. extraN.h])
133#
134# Check if the header file exists, in such case define variable
135# in configuration file.
136#
137# Variable defaults to HAVE_${HEADER}, where HEADER is the uppercase
138# representation of the first parameter. It can be overridden using
139# NAME keyword.
140#
141# To include extra files, then use INCLUDE_FILES keyword.
142function(HEADER_CHECK header)
143 string(TOUPPER HAVE_${header} var)
144 string(REGEX REPLACE "[^a-zA-Z0-9]" "_" var "${var}")
145 string(REGEX REPLACE "_{2,}" "_" var "${var}")
146
147 cmake_parse_arguments(PARAMS "" "NAME" "INCLUDE_FILES" ${ARGN})
148
149 if(PARAMS_NAME)
150 set(var ${PARAMS_NAME})
151 endif()
152
153 set(CMAKE_EXTRA_INCLUDE_FILES "${PARAMS_INCLUDE_FILES}")
154
155 CHECK_INCLUDE_FILE(${header} ${var})
156
157 if(${${var}})
158 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
159 else()
160 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
161 endif()
162endfunction()
163
164# FUNC_CHECK(func [NAME variable]
165# [INCLUDE_FILES header1.h .. headerN.h]
166# [LIBRARIES lib1 ... libN]
167# [DEFINITIONS -DA=1 .. -DN=123]
168# [FLAGS -cmdlineparam1 .. -cmdlineparamN]
169# [CXX])
170#
171# Check if the function exists, in such case define variable in
172# configuration file.
173#
174# Variable defaults to HAVE_${FUNC}, where FUNC is the uppercase
175# representation of the first parameter. It can be overridden using
176# NAME keyword.
177#
178# To define include files use INCLUDE_FILES keyword.
179#
180# To use C++ compiler, use CXX keyword
181function(FUNC_CHECK func)
182 string(TOUPPER HAVE_${func} var)
183 string(REGEX REPLACE "_{2,}" "_" var "${var}")
184
185 cmake_parse_arguments(PARAMS "CXX" "NAME" "INCLUDE_FILES;LIBRARIES;DEFINITIONS;FLAGS" ${ARGN})
186
187 set(CMAKE_REQUIRED_LIBRARIES "${PARAMS_LIBRARIES}")
188 set(CMAKE_REQUIRED_DEFINITIONS "${PARAMS_DEFINITIONS}")
189 set(CMAKE_REQUIRED_FLAGS "${PARAMS_FLAGS}")
190
191 if(PARAMS_CXX)
192 check_cxx_symbol_exists(${func} "${PARAMS_INCLUDE_FILES}" ${var})
193 else()
194 check_symbol_exists(${func} "${PARAMS_INCLUDE_FILES}" ${var})
195 endif()
196
197 if(${${var}} )
198 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
199 else()
200 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
201 endif()
202endfunction()
203
204# TYPE_CHECK(type [NAME variable]
205# [INCLUDE_FILES file1.h ... fileN.h]
206# [LIBRARIES lib1 ... libN]
207# [DEFINITIONS -DA=1 .. -DN=123]
208# [FLAGS -cmdlineparam1 .. -cmdlineparamN]
209# [CXX])
210#
211# Check if the type exists and its size, in such case define variable
212# in configuration file.
213#
214# Variable defaults to HAVE_${TYPE}, where TYPE is the uppercase
215# representation of the first parameter. It can be overridden using
216# NAME keyword.
217#
218# To define include files use INCLUDE_FILES keyword.
219#
220# To use C++ compiler, use CXX keyword
221function(TYPE_CHECK type)
222 string(TOUPPER HAVE_${type} var)
223 string(REGEX REPLACE "_{2,}" "_" var "${var}")
224
225 cmake_parse_arguments(PARAMS "CXX" "NAME" "INCLUDE_FILES;LIBRARIES;DEFINITIONS;FLAGS" ${ARGN})
226
227 set(CMAKE_REQUIRED_LIBRARIES "${PARAMS_LIBRARIES}")
228 set(CMAKE_REQUIRED_DEFINITIONS "${PARAMS_DEFINITIONS}")
229 set(CMAKE_REQUIRED_FLAGS "${PARAMS_FLAGS}")
230 set(CMAKE_EXTRA_INCLUDE_FILES "${PARAMS_INCLUDE_FILES}")
231
232 if(PARAMS_CXX)
233 set(lang CXX)
234 else()
235 set(lang C)
236 endif()
237
238 CHECK_TYPE_SIZE(${type} ${var} LANGUAGE ${lang})
239
240 if(HAVE_${var})
241 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#define ${var} 1\n")
242 else()
243 SET_GLOBAL(HEADER_FILE_CONTENT "${HEADER_FILE_CONTENT}#undef ${var}\n")
244 endif()
245endfunction()
246
247# EFL_HEADER_CHECKS_FINALIZE(file)
248#
249# Write the configuration gathered with HEADER_CHECK(), TYPE_CHECK()
250# and FUNC_CHECK() to the given file.
251function(EFL_HEADER_CHECKS_FINALIZE file)
252 file(WRITE ${file}.new ${HEADER_FILE_CONTENT})
253 if (NOT EXISTS ${file})
254 file(RENAME ${file}.new ${file})
255 message(STATUS "${file} was generated.")
256 else()
257 file(MD5 ${file}.new _new_md5)
258 file(MD5 ${file} _old_md5)
259 if(_new_md5 STREQUAL _old_md5)
260 message(STATUS "${file} is unchanged.")
261 else()
262 file(REMOVE ${file})
263 file(RENAME ${file}.new ${file})
264 message(STATUS "${file} was updated.")
265 endif()
266 endif()
267 unset(HEADER_FILE_CONTENT CACHE) # allow to reuse with an empty contents
268endfunction()
269
130# EFL_FILES_TO_ABSOLUTE(Var Source_Dir Binary_Dir [file1 ... fileN]) 270# EFL_FILES_TO_ABSOLUTE(Var Source_Dir Binary_Dir [file1 ... fileN])
131# 271#
132# Convert list of files to absolute path. If not absolute, then 272# Convert list of files to absolute path. If not absolute, then