summaryrefslogtreecommitdiff
path: root/cmake/helpers/EflMacros.cmake
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 /cmake/helpers/EflMacros.cmake
parente8f2bdb079598ff406a2c8010cc8745d47ecc010 (diff)
cmake: move functions to EflMacros.cmake
Diffstat (limited to 'cmake/helpers/EflMacros.cmake')
-rw-r--r--cmake/helpers/EflMacros.cmake140
1 files changed, 140 insertions, 0 deletions
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