summaryrefslogtreecommitdiff
path: root/cmake/helpers/EflMacros.cmake
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-20 12:58:21 -0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-01-23 18:23:40 +0100
commit3d5abc081f59dda9887dbacc8e8ab24c96d5ee65 (patch)
treee0a208eea958e4bf95c8e56efcd76e8c4b925c62 /cmake/helpers/EflMacros.cmake
parente1b98ca4f2148b752cf35246c4435733dc08a547 (diff)
EflMacros: major improvements towards usability.
Stick to one target per directory and remove prefix from variables, makes it cleaner and easier to use. Document variables used and use a more consistent name that matches CMake properties.
Diffstat (limited to 'cmake/helpers/EflMacros.cmake')
-rw-r--r--cmake/helpers/EflMacros.cmake552
1 files changed, 396 insertions, 156 deletions
diff --git a/cmake/helpers/EflMacros.cmake b/cmake/helpers/EflMacros.cmake
index 034e5e3ed2..4665a03a80 100644
--- a/cmake/helpers/EflMacros.cmake
+++ b/cmake/helpers/EflMacros.cmake
@@ -119,20 +119,155 @@ function(EFL_FINALIZE)
119 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS}) 119 add_custom_target(all-tests DEPENDS ${EFL_ALL_TESTS})
120endfunction() 120endfunction()
121 121
122# EFL_FILES_TO_ABSOLUTE(Var Source_Dir Binary_Dir [file1 ... fileN])
123#
124# Convert list of files to absolute path. If not absolute, then
125# check inside Source_Dir and if it fails assumes it's inside Binary_Dir
126function(EFL_FILES_TO_ABSOLUTE _var _srcdir _bindir)
127 set(_lst "")
128 foreach(f ${ARGN})
129 if(EXISTS "${f}")
130 list(APPEND _lst "${f}")
131 elseif(EXISTS "${_srcdir}/${f}")
132 list(APPEND _lst "${_srcdir}/${f}")
133 else()
134 list(APPEND _lst "${_bindir}/${f}")
135 endif()
136 endforeach()
137 set(${_var} "${_lst}" PARENT_SCOPE)
138endfunction()
139
140# _EFL_LIB_PROCESS_MODULES_INTERNAL()
141#
142# Internal function to process modules of current EFL_LIB()
143function(_EFL_LIB_PROCESS_MODULES_INTERNAL)
144 if(EXISTS ${EFL_MODULES_SOURCE_DIR}/CMakeLists.txt)
145 message(FATAL_ERROR "${EFL_MODULES_SOURCE_DIR}/CMakeLists.txt shouldn't exist. Modules are expected to be defined in their own directory.")
146 else()
147 file(GLOB modules RELATIVE ${EFL_MODULES_SOURCE_DIR} ${EFL_MODULES_SOURCE_DIR}/*)
148 foreach(module ${modules})
149 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${module})
150 set(EFL_MODULE_SCOPE ${module})
151
152 include(${EFL_MODULES_SOURCE_DIR}/${module}/CMakeLists.txt OPTIONAL)
153
154 file(GLOB submodules RELATIVE ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE} ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/*)
155 foreach(submodule ${submodules})
156 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${submodule})
157 EFL_MODULE(${submodule})
158 endif()
159 unset(submodule)
160 unset(submodules)
161 endforeach()
162 else()
163 set(EFL_MODULE_SCOPE)
164 EFL_MODULE(${module})
165 endif()
166 unset(EFL_MODULE_SCOPE)
167 endforeach()
168 endif()
169
170 if(${EFL_LIB_CURRENT}_MODULES)
171 add_custom_target(${EFL_LIB_CURRENT}-modules DEPENDS ${${EFL_LIB_CURRENT}_MODULES})
172 endif()
173endfunction()
174
175# _EFL_LIB_PROCESS_BINS_INTERNAL()
176#
177# Internal function to process bins of current EFL_LIB()
178function(_EFL_LIB_PROCESS_BINS_INTERNAL)
179 if(EXISTS ${EFL_BIN_SOURCE_DIR}/CMakeLists.txt)
180 EFL_BIN(${EFL_LIB_CURRENT})
181 else()
182 file(GLOB bins RELATIVE ${EFL_BIN_SOURCE_DIR} ${EFL_BIN_SOURCE_DIR}/*)
183 foreach(bin ${bins})
184 if(IS_DIRECTORY ${EFL_BIN_SOURCE_DIR}/${bin})
185 EFL_BIN(${bin})
186 endif()
187 endforeach()
188 endif()
189
190 if(${EFL_LIB_CURRENT}_BINS)
191 add_custom_target(${EFL_LIB_CURRENT}-bins DEPENDS ${${EFL_LIB_CURRENT}_BINS})
192 endif()
193endfunction()
194
195# _EFL_LIB_PROCESS_TESTS_INTERNAL()
196#
197# Internal function to process tests of current EFL_LIB()
198function(_EFL_LIB_PROCESS_TESTS_INTERNAL)
199 if(EXISTS ${EFL_TESTS_SOURCE_DIR}/CMakeLists.txt)
200 EFL_TEST(${EFL_LIB_CURRENT})
201 else()
202 file(GLOB tests RELATIVE ${EFL_TESTS_SOURCE_DIR} ${EFL_TESTS_SOURCE_DIR}/*)
203 foreach(test ${tests})
204 if(IS_DIRECTORY ${EFL_TESTS_SOURCE_DIR}/${test})
205 EFL_TEST(${test})
206 endif()
207 endforeach()
208 endif()
209
210 if(${EFL_LIB_CURRENT}_TESTS)
211 add_custom_target(${EFL_LIB_CURRENT}-tests DEPENDS ${${EFL_LIB_CURRENT}_TESTS})
212 LIST_APPEND_GLOBAL(EFL_ALL_TESTS ${EFL_LIB_CURRENT}-tests)
213 endif()
214endfunction()
215
122# EFL_LIB(Name) 216# EFL_LIB(Name)
123# 217#
124# adds a library ${Name} automatically setting: 218# adds a library ${Name} automatically setting object/target
125# - target_include_directories to ${Name}_INCLUDE_DIRECTORIES 219# properties based on script-modifiable variables:
126# - target_include_directories(SYSTEM) to ${Name}_SYSTEM_INCLUDE_DIRECTORIES 220# - INCLUDE_DIRECTORIES: results in target_include_directories
127# - OUTPUT_NAME to ${Name}_OUTPUT_NAME 221# - SYSTEM_INCLUDE_DIRECTORIES: results in target_include_directories(SYSTEM)
128# - SOURCES to ${Name}_SOURCES 222# - OUTPUT_NAME
129# - HEADER to ${Name}_HEADERS (to be installed) 223# - SOURCES
130# - VERSION to ${Name}_VERSION (defaults to project version) 224# - PUBLIC_HEADERS
131# - SOVERSION to ${Name}_SOURCES (defaults to project major version) 225# - VERSION (defaults to project version)
132# - OBJECT_DEPENDS to ${Name}_DEPENDENCIES 226# - SOVERSION (defaults to project major version)
133# - target_link_libraries() to ${Name}_LIBRARIES 227# - LIBRARY_TYPE: SHARED or STATIC, defaults to SHARED
134# - target_compile_definitions() to ${Name}_DEFINITIONS 228# - OBJECT_DEPENDS: say this object depends on other files (ie: includes)
135# - compile tests in ${Name}_TESTS using EFL_TEST() 229# - DEPENDENCIES: results in add_dependencies()
230# - LIBRARIES: results in target_link_libraries()
231# - DEFINITIONS: target_compile_definitions()
232#
233# Defines the following variables that can be used within the included files:
234# - EFL_LIB_CURRENT to ${Name}
235# - EFL_LIB_SOURCE_DIR to source dir of ${Name} libraries
236# - EFL_LIB_BINARY_DIR to binary dir of ${Name} libraries
237# - EFL_BIN_SOURCE_DIR to source dir of ${Name} executables
238# - EFL_BIN_BINARY_DIR to binary dir of ${Name} executables
239# - EFL_MODULES_SOURCE_DIR to source dir of ${Name} modules
240# - EFL_MODULES_BINARY_DIR to binary dir of ${Name} modules
241# - EFL_TESTS_SOURCE_DIR to source dir of ${Name} tests
242# - EFL_TESTS_BINARY_DIR to binary dir of ${Name} tests
243#
244# Modules are processed like:
245# - loop for directories in src/modules/${EFL_LIB_CURRENT}:
246# - if a src/modules/${EFL_LIB_CURRENT}/${Module}/CMakeLists.txt
247# use variables as documented in EFL_MODULE()
248# - otherwise loop for scoped-modules in
249# src/modules/${EFL_LIB_CURRENT}/${EFL_MODULE_SCOPE}/CMakeLists.txt
250# and use variables as documented in EFL_MODULE()
251#
252# EFL_MODULE() will handle MODULE_TYPE=ON;OFF;STATIC, handling
253# dependencies and installation in the proper path, considering
254# ${EFL_MODULE_SCOPE} whenever it's set.
255#
256# Binaries and tests are processed similarly:
257# - if src/bin/${EFL_LIB_CURRENT}/CMakeLists.txt exist, then use
258# variables as documented in EFL_BIN() or EFL_TEST(). The target
259# will be called ${EFL_LIB_CURRENT}-bin or ${EFL_LIB_CURRENT}-test
260# and the test OUTPUT_NAME defaults to ${EFL_LIB_CURRENT}_suite.
261# - otherwise loop for directories in src/bin/${EFL_LIB_CURRENT} and
262# for each src/bin/${EFL_LIB_CURRENT}/${Entry}/CMakeLists.txt use
263# variables as documented in EFL_BIN() or EFL_TEST(). Binaries
264# must provide an unique name that will be used as both target and
265# OUTPUT_NAME. Tests will generate targets
266# ${EFL_LIB_CURRENT}-test-${Entry}, while OUTPUT_NAME is ${Entry}.
267#
268# NOTE: src/modules/${EFL_LIB_CURRENT}/CMakeLists.txt is not
269# allowed as it makes no sense to have a single module named
270# after the library.
136# 271#
137function(EFL_LIB _target) 272function(EFL_LIB _target)
138 set(EFL_LIB_CURRENT ${_target}) 273 set(EFL_LIB_CURRENT ${_target})
@@ -145,73 +280,67 @@ function(EFL_LIB _target)
145 set(EFL_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/${_target}) 280 set(EFL_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/${_target})
146 set(EFL_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/tests/${_target}) 281 set(EFL_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/tests/${_target})
147 282
148 set(${_target}_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) 283 set(INCLUDE_DIRECTORIES)
149 set(${_target}_SOVERSION ${PROJECT_VERSION_MAJOR}) 284 set(SYSTEM_INCLUDE_DIRECTORIES)
150 set(${_target}_LIBRARY_TYPE SHARED) 285 set(OUTPUT_NAME)
286 set(SOURCES)
287 set(PUBLIC_HEADERS)
288 set(VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
289 set(SOVERSION ${PROJECT_VERSION_MAJOR})
290 set(LIBRARY_TYPE SHARED)
291 set(OBJECT_DEPENDS)
292 set(DEPENDENCIES)
293 set(LIBRARIES)
294 set(DEFINITIONS)
151 295
152 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/${_target}.cmake OPTIONAL) 296 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/${_target}.cmake OPTIONAL)
153 include(${EFL_LIB_SOURCE_DIR}/CMakeLists.txt OPTIONAL) 297 include(${EFL_LIB_SOURCE_DIR}/CMakeLists.txt OPTIONAL)
154 include(${EFL_BIN_SOURCE_DIR}/CMakeLists.txt OPTIONAL) 298 if(LIBRARY_TYPE STREQUAL SHARED AND NOT PUBLIC_HEADERS)
155 include(${EFL_MODULES_SOURCE_DIR}/CMakeLists.txt OPTIONAL) 299 message(FATAL_ERROR "Shared libraries must install public headers!")
156 include(${EFL_TESTS_SOURCE_DIR}/CMakeLists.txt OPTIONAL) 300 endif()
157
158 set(_headers "")
159 foreach(f ${${_target}_HEADERS})
160 if(EXISTS "${EFL_LIB_SOURCE_DIR}/${f}")
161 list(APPEND _headers "${EFL_LIB_SOURCE_DIR}/${f}")
162 else()
163 list(APPEND _headers "${EFL_LIB_BINARY_DIR}/${f}")
164 endif()
165 endforeach()
166
167 set(_sources "")
168 foreach(f ${${_target}_SOURCES})
169 if(EXISTS "${EFL_LIB_SOURCE_DIR}/${f}")
170 list(APPEND _sources "${EFL_LIB_SOURCE_DIR}/${f}")
171 else()
172 list(APPEND _sources "${EFL_LIB_BINARY_DIR}/${f}")
173 endif()
174 endforeach()
175 301
176 set(_deps "") 302 EFL_FILES_TO_ABSOLUTE(_headers ${EFL_LIB_SOURCE_DIR} ${EFL_LIB_BINARY_DIR}
177 foreach(f ${${_target}_DEPENDENCIES}) 303 ${PUBLIC_HEADERS})
178 if(EXISTS "${EFL_LIB_SOURCE_DIR}/${f}") 304 EFL_FILES_TO_ABSOLUTE(_sources ${EFL_LIB_SOURCE_DIR} ${EFL_LIB_BINARY_DIR}
179 list(APPEND _deps "${EFL_LIB_SOURCE_DIR}/${f}") 305 ${SOURCES})
180 else() 306 EFL_FILES_TO_ABSOLUTE(_obj_deps ${EFL_LIB_SOURCE_DIR} ${EFL_LIB_BINARY_DIR}
181 list(APPEND _deps "${EFL_LIB_BINARY_DIR}/${f}") 307 ${OBJECT_DEPENDS})
182 endif()
183 endforeach()
184 308
185 add_library(${_target} ${${_target}_LIBRARY_TYPE} ${_sources} ${_headers}) 309 add_library(${_target} ${LIBRARY_TYPE} ${_sources} ${_headers})
186 set_target_properties(${_target} PROPERTIES 310 set_target_properties(${_target} PROPERTIES
187 FRAMEWORK TRUE 311 FRAMEWORK TRUE
188 PUBLIC_HEADER "${_headers}" 312 PUBLIC_HEADER "${_headers}"
189 OBJECT_DEPENDS "${_deps}") 313 OBJECT_DEPENDS "${_obj_deps}")
190 314
191 if(${_target}_LIBRARIES) 315 if(DEPENDENCIES)
192 target_link_libraries(${_target} ${${_target}_LIBRARIES}) 316 add_dependencies(${_target} ${DEPENDENCIES})
317 endif()
318
319 if(LIBRARIES)
320 target_link_libraries(${_target} ${LIBRARIES})
193 endif() 321 endif()
194 322
195 target_include_directories(${_target} PUBLIC 323 target_include_directories(${_target} PUBLIC
196 ${${_target}_INCLUDE_DIRECTORIES} 324 ${INCLUDE_DIRECTORIES}
197 ${EFL_LIB_SOURCE_DIR} 325 ${EFL_LIB_SOURCE_DIR}
326 ${EFL_LIB_BINARY_DIR}
198 ) 327 )
199 if(${_target}_SYSTEM_INCLUDE_DIRECTORIES) 328 if(SYSTEM_INCLUDE_DIRECTORIES)
200 target_include_directories(${_target} SYSTEM PUBLIC ${${_target}_SYSTEM_INCLUDE_DIRECTORIES}) 329 target_include_directories(${_target} SYSTEM PUBLIC ${SYSTEM_INCLUDE_DIRECTORIES})
201 endif() 330 endif()
202 331
203 if(${_target}_DEFINITIONS) 332 if(DEFINITIONS)
204 target_compile_definitions(${_target} PRIVATE ${${_target}_DEFINITIONS}) 333 target_compile_definitions(${_target} PRIVATE ${DEFINITIONS})
205 endif() 334 endif()
206 335
207 if(${_target}_OUTPUT_NAME) 336 if(OUTPUT_NAME)
208 set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${${_target}_OUTPUT_NAME}) 337 set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
209 endif() 338 endif()
210 339
211 if(${_target}_VERSION AND ${_target}_SOVERSION) 340 if(VERSION AND SOVERSION)
212 set_target_properties(${_target} PROPERTIES 341 set_target_properties(${_target} PROPERTIES
213 VERSION ${${_target}_VERSION} 342 VERSION ${VERSION}
214 SOVERSION ${${_target}_SOVERSION}) 343 SOVERSION ${SOVERSION})
215 endif() 344 endif()
216 345
217 install(TARGETS ${_target} 346 install(TARGETS ${_target}
@@ -220,40 +349,125 @@ function(EFL_LIB _target)
220 ARCHIVE DESTINATION lib 349 ARCHIVE DESTINATION lib
221 LIBRARY DESTINATION lib) 350 LIBRARY DESTINATION lib)
222 351
223 file(GLOB modules RELATIVE ${EFL_MODULES_SOURCE_DIR} ${EFL_MODULES_SOURCE_DIR}/*) 352 # do not leak those into binaries, modules or tests
224 foreach(module ${modules}) 353 unset(_sources)
225 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${module}) 354 unset(_headers)
226 set(EFL_MODULE_SCOPE ${module}) 355 unset(_obj_deps)
227 356 unset(INCLUDE_DIRECTORIES)
228 include(${EFL_MODULES_SOURCE_DIR}/${module}/CMakeLists.txt OPTIONAL) 357 unset(SYSTEM_INCLUDE_DIRECTORIES)
229 358 unset(OUTPUT_NAME)
230 file(GLOB submodules RELATIVE ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE} ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/*) 359 unset(SOURCES)
231 foreach(submodule ${submodules}) 360 unset(PUBLIC_HEADERS)
232 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${submodule}) 361 unset(VERSION)
233 EFL_MODULE(${submodule}) 362 unset(SOVERSION)
234 endif() 363 unset(LIBRARY_TYPE)
235 unset(submodule) 364 unset(OBJECT_DEPENDS)
236 unset(submodules) 365 unset(DEPENDENCIES)
237 endforeach() 366 unset(LIBRARIES)
238 else() 367 unset(DEFINITIONS)
239 set(EFL_MODULE_SCOPE) 368
240 EFL_MODULE(${module}) 369 include(${EFL_BIN_SOURCE_DIR}/CMakeLists.txt OPTIONAL)
241 endif() 370
242 unset(EFL_MODULE_SCOPE) 371 _EFL_LIB_PROCESS_BINS_INTERNAL()
243 endforeach() 372 _EFL_LIB_PROCESS_MODULES_INTERNAL()
244 unset(module) 373 _EFL_LIB_PROCESS_TESTS_INTERNAL()
245 unset(modules)
246 374
247 foreach(t ${${_target}_TESTS})
248 EFL_TEST(${t})
249 endforeach()
250 unset(t)
251 add_custom_target(${_target}-tests DEPENDS ${${_target}_TESTS})
252 add_custom_target(${_target}-modules DEPENDS ${${_target}_MODULES})
253 LIST_APPEND_GLOBAL(EFL_ALL_LIBS ${_target}) 375 LIST_APPEND_GLOBAL(EFL_ALL_LIBS ${_target})
254 LIST_APPEND_GLOBAL(EFL_ALL_TESTS ${_target}-tests)
255endfunction() 376endfunction()
256 377
378# EFL_BIN(Name)
379#
380# Adds a binary (executable) for ${EFL_LIB_CURRENT} using
381# ${EFL_BIN_SOURCE_DIR} and ${EFL_BIN_BINARY_DIR}
382#
383# Settings:
384# - INCLUDE_DIRECTORIES: results in target_include_directories
385# - SYSTEM_INCLUDE_DIRECTORIES: results in target_include_directories(SYSTEM)
386# - OUTPUT_NAME
387# - SOURCES
388# - OBJECT_DEPENDS: say this object depends on other files (ie: includes)
389# - DEPENDENCIES: results in add_dependencies(), defaults to
390# ${EFL_LIB_CURRENT}-modules
391# - LIBRARIES: results in target_link_libraries()
392# - DEFINITIONS: target_compile_definitions()
393# - INSTALL_DIR: defaults to bin. If empty, won't install.
394#
395# NOTE: it's meant to be called by files included by EFL_LIB() or similar,
396# otherwise you need to prepare the environment yourself.
397function(EFL_BIN _binname)
398 set(INCLUDE_DIRECTORIES)
399 set(SYSTEM_INCLUDE_DIRECTORIES)
400 set(OUTPUT_NAME ${_binname})
401 set(SOURCES)
402 set(OBJECT_DEPENDS)
403 if(TARGET ${EFL_LIB_CURRENT}-modules)
404 set(DEPENDENCIES ${EFL_LIB_CURRENT}-modules)
405 else()
406 set(DEPENDENCIES)
407 endif()
408 set(LIBRARIES)
409 set(DEFINITIONS)
410 set(INSTALL ON)
411 set(INSTALL_DIR bin)
412
413 if(_binname STREQUAL ${EFL_LIB_CURRENT})
414 set(_binsrcdir "${EFL_BIN_SOURCE_DIR}")
415 set(_binbindir "${EFL_BIN_BINARY_DIR}")
416 set(_bintarget "${EFL_LIB_CURRENT}-bin") # otherwise target would exist
417 else()
418 set(_binsrcdir "${EFL_BIN_SOURCE_DIR}/${_binname}")
419 set(_binbindir "${EFL_BIN_BINARY_DIR}/${_binname}")
420 set(_bintarget "${_binname}")
421 endif()
422
423 include(${_binsrcdir}/CMakeLists.txt)
424
425 if(NOT SOURCES)
426 message(WARNING "${_binsrcdir}/CMakeLists.txt defines no SOURCES")
427 return()
428 endif()
429 if(PUBLIC_HEADERS)
430 message(WARNING "${_binsrcdir}/CMakeLists.txt should not define PUBLIC_HEADERS, it's not to be installed.")
431 endif()
432
433 EFL_FILES_TO_ABSOLUTE(_sources ${_binsrcdir} ${_binbindir} ${SOURCES})
434 EFL_FILES_TO_ABSOLUTE(_obj_deps ${_binsrcdir} ${_binbindir} ${OBJECT_DEPENDS})
435
436 add_executable(${_bintarget} ${_sources})
437
438 if(_obj_deps)
439 set_target_properties(${_bintarget} PROPERTIES
440 OBJECT_DEPENDS "${_obj_deps}")
441 endif()
442
443 if(DEPENDENCIES)
444 add_dependencies(${_bintarget} ${DEPENDENCIES})
445 endif()
446
447 target_include_directories(${_bintarget} PRIVATE
448 ${_binrcdir}
449 ${_binbindir}
450 ${INCLUDE_DIRECTORIES})
451 if(SYSTEM_INCLUDE_DIRECTORIES)
452 target_include_directories(${_bintarget} SYSTEM PRIVATE
453 ${SYSTEM_INCLUDE_DIRECTORIES})
454 endif()
455 target_link_libraries(${_bintarget}
456 ${EFL_LIB_CURRENT}
457 ${LIBRARIES})
458
459 if(DEFINITIONS)
460 target_compile_definitions(${_bintarget} PRIVATE ${DEFINITIONS})
461 endif()
462
463 if(OUTPUT_NAME)
464 set_target_properties(${_bintarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
465 endif()
466
467 if(INSTALL_DIR)
468 install(TARGETS ${_bintarget} RUNTIME DESTINATION ${INSTALL_DIR})
469 endif()
470endfunction()
257 471
258# EFL_TEST(Name) 472# EFL_TEST(Name)
259# 473#
@@ -261,13 +475,15 @@ endfunction()
261# ${EFL_TESTS_SOURCE_DIR} and ${EFL_TESTS_BINARY_DIR} 475# ${EFL_TESTS_SOURCE_DIR} and ${EFL_TESTS_BINARY_DIR}
262# 476#
263# Settings: 477# Settings:
264# - include_directories to ${Name}_INCLUDE_DIRECTORIES 478# - INCLUDE_DIRECTORIES: results in target_include_directories
265# - include_directories(SYSTEM) to ${Name}_SYSTEM_INCLUDE_DIRECTORIES 479# - SYSTEM_INCLUDE_DIRECTORIES: results in target_include_directories(SYSTEM)
266# - OUTPUT_NAME to ${Name}_OUTPUT_NAME 480# - OUTPUT_NAME
267# - SOURCES to ${Name}_SOURCES 481# - SOURCES
268# - target_link_libraries() to ${Name}_LIBRARIES (${EFL_LIB_CURRENT} 482# - OBJECT_DEPENDS: say this object depends on other files (ie: includes)
269# is automatic) 483# - DEPENDENCIES: results in add_dependencies(), defaults to
270# - target_compile_definitions() to ${Name}_DEFINITIONS 484# ${EFL_LIB_CURRENT}-modules
485# - LIBRARIES: results in target_link_libraries()
486# - DEFINITIONS: target_compile_definitions()
271# 487#
272# NOTE: it's meant to be called by files included by EFL_LIB() or similar, 488# NOTE: it's meant to be called by files included by EFL_LIB() or similar,
273# otherwise you need to prepare the environment yourself. 489# otherwise you need to prepare the environment yourself.
@@ -276,56 +492,85 @@ function(EFL_TEST _testname)
276 message(STATUS "${EFL_LIB_CURRENT} test ${_testname} ignored since no 'check' library was found.") 492 message(STATUS "${EFL_LIB_CURRENT} test ${_testname} ignored since no 'check' library was found.")
277 return() 493 return()
278 endif() 494 endif()
279 set(_sources "")
280 foreach(f ${${_testname}_SOURCES})
281 if(EXISTS "${EFL_TESTS_SOURCE_DIR}/${f}")
282 list(APPEND _sources "${EFL_TESTS_SOURCE_DIR}/${f}")
283 else()
284 list(APPEND _sources "${EFL_TESTS_BINARY_DIR}/${f}")
285 endif()
286 endforeach()
287 add_executable(${_testname} EXCLUDE_FROM_ALL ${_sources})
288 495
289 set(_deps "") 496 set(INCLUDE_DIRECTORIES)
290 foreach(f ${${_testname}_DEPENDENCIES}) 497 set(SYSTEM_INCLUDE_DIRECTORIES)
291 if(EXISTS "${EFL_TESTS_SOURCE_DIR}/${f}") 498 set(OUTPUT_NAME ${_testname})
292 list(APPEND _deps "${EFL_TESTS_SOURCE_DIR}/${f}") 499 set(SOURCES)
293 else() 500 set(OBJECT_DEPENDS)
294 list(APPEND _deps "${EFL_TESTS_BINARY_DIR}/${f}") 501 if(TARGET ${EFL_LIB_CURRENT}-modules)
295 endif() 502 set(DEPENDENCIES ${EFL_LIB_CURRENT}-modules)
296 endforeach() 503 else()
297 add_dependencies(${_testname} ${EFL_LIB_CURRENT}-modules) 504 set(DEPENDENCIES)
298 set_target_properties(${_testname} PROPERTIES OBJECT_DEPENDS "${_deps}") 505 endif()
299 506 set(LIBRARIES)
300 target_include_directories(${_testname} PRIVATE 507 set(DEFINITIONS)
301 ${EFL_TESTS_SOURCE_DIR} 508
302 ${EFL_TESTS_BINARY_DIR} 509 if(_testname STREQUAL ${EFL_LIB_CURRENT})
303 ${${_testname}_INCLUDE_DIRECTORIES}) 510 set(_testsrcdir "${EFL_TESTS_SOURCE_DIR}")
304 target_include_directories(${_testname} SYSTEM PRIVATE 511 set(_testbindir "${EFL_TESTS_BINARY_DIR}")
305 ${${_testname}_SYSTEM_INCLUDE_DIRECTORIES} 512 set(_testtarget "${EFL_LIB_CURRENT}-test") # otherwise target would exist
513 set(OUTPUT_NAME "${EFL_LIB_CURRENT}_suite") # backward compatible
514 else()
515 set(_testsrcdir "${EFL_TESTS_SOURCE_DIR}/${_testname}")
516 set(_testbindir "${EFL_TESTS_BINARY_DIR}/${_testname}")
517 set(_testtarget "${EFL_LIB_CURRENT}-test-${_testname}")
518 endif()
519
520 include(${_testsrcdir}/CMakeLists.txt)
521
522 if(NOT SOURCES)
523 message(WARNING "${_testsrcdir}/CMakeLists.txt defines no SOURCES")
524 return()
525 endif()
526 if(PUBLIC_HEADERS)
527 message(WARNING "${_testsrcdir}/CMakeLists.txt should not define PUBLIC_HEADERS, it's not to be installed.")
528 endif()
529
530 EFL_FILES_TO_ABSOLUTE(_sources ${_testsrcdir} ${_testbindir} ${SOURCES})
531 EFL_FILES_TO_ABSOLUTE(_obj_deps ${_testsrcdir} ${_testbindir} ${OBJECT_DEPENDS})
532
533 add_executable(${_testtarget} EXCLUDE_FROM_ALL ${_sources})
534
535 if(_obj_deps)
536 set_target_properties(${_testtarget} PROPERTIES
537 OBJECT_DEPENDS "${_obj_deps}")
538 endif()
539
540 if(DEPENDENCIES)
541 add_dependencies(${_testtarget} ${DEPENDENCIES})
542 endif()
543
544 target_include_directories(${_testtarget} PRIVATE
545 ${_testrcdir}
546 ${_testbindir}
547 ${INCLUDE_DIRECTORIES})
548 target_include_directories(${_testtarget} SYSTEM PRIVATE
549 ${SYSTEM_INCLUDE_DIRECTORIES}
306 ${CHECK_INCLUDE_DIRS}) 550 ${CHECK_INCLUDE_DIRS})
307 target_link_libraries(${_testname} 551 target_link_libraries(${_testtarget}
308 ${EFL_LIB_CURRENT} 552 ${EFL_LIB_CURRENT}
309 ${${_testname}_LIBRARIES} 553 ${LIBRARIES}
310 ${CHECK_LIBRARIES}) 554 ${CHECK_LIBRARIES})
311 555
312 target_compile_definitions(${_testname} PRIVATE 556 target_compile_definitions(${_testtarget} PRIVATE
313 "-DTESTS_SRC_DIR=\"${EFL_TESTS_SOURCE_DIR}\"" 557 "-DTESTS_SRC_DIR=\"${_testrcdir}\""
314 "-DTESTS_BUILD_DIR=\"${EFL_TESTS_BINARY_DIR}\"" 558 "-DTESTS_BUILD_DIR=\"${_testbindir}\""
315 "-DTESTS_WD=\"${PROJECT_BINARY_DIR}\"" 559 "-DTESTS_WD=\"${PROJECT_BINARY_DIR}\""
316 "-DPACKAGE_BUILD_DIR=\"1\"" 560 "-DPACKAGE_BUILD_DIR=\"1\""
317 ${${_testname}_DEFINITIONS} 561 ${DEFINITIONS}
318 ) 562 )
319 563
320 if(${_testname}_OUTPUT_NAME) 564 if(OUTPUT_NAME)
321 set_target_properties(${_testname} PROPERTIES OUTPUT_NAME ${${_testname}_OUTPUT_NAME}) 565 set_target_properties(${_testtarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
322 endif() 566 endif()
323 567
324 set_target_properties(${_testname} PROPERTIES 568 set_target_properties(${_testtarget} PROPERTIES
325 LIBRARY_OUTPUT_DIRECTORY "${EFL_TESTS_BINARY_DIR}" 569 LIBRARY_OUTPUT_DIRECTORY "${_testbindir}"
326 RUNTIME_OUTPUT_DIRECTORY "${EFL_TESTS_BINARY_DIR}") 570 RUNTIME_OUTPUT_DIRECTORY "${_testbindir}")
327 571
328 add_test(NAME ${_testname} COMMAND ${_testname}) 572 add_test(NAME ${_testname} COMMAND ${_testtarget})
573 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_TESTS ${_testtarget})
329endfunction() 574endfunction()
330 575
331# EFL_MODULE(Name) 576# EFL_MODULE(Name)
@@ -337,27 +582,34 @@ endfunction()
337# 582#
338# To keep it simple to use, user is only expected to define variables: 583# To keep it simple to use, user is only expected to define variables:
339# - SOURCES 584# - SOURCES
340# - DEPENDENCIES 585# - OBJECT_DEPENDS
341# - LIBRARIES 586# - LIBRARIES
342# - INCLUDE_DIRECTORIES 587# - INCLUDE_DIRECTORIES
343# - SYSTEM_INCLUDE_DIRECTORIES 588# - SYSTEM_INCLUDE_DIRECTORIES
344# - DEFINITIONS 589# - DEFINITIONS
590# - MODULE_TYPE: one of ON;OFF;STATIC, defaults to ON
591# - INSTALL_DIR: defaults to
592# lib/${EFL_LIB_CURRENT}/modules/${EFL_MODULE_SCOPE}/${Name}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}/.
593# If empty, won't install.
345# 594#
346# NOTE: since the file will be included it shouldn't mess with global variables! 595# NOTE: since the file will be included it shouldn't mess with global variables!
347function(EFL_MODULE _modname) 596function(EFL_MODULE _modname)
348 if(EFL_MODULE_SCOPE) 597 if(EFL_MODULE_SCOPE)
349 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${_modname}) 598 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${_modname})
599 set(_modoutdir lib/${EFL_LIB_CURRENT}/modules/${EFL_MODULE_SCOPE}/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
350 else() 600 else()
351 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${_modname}) 601 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${_modname})
602 set(_modoutdir lib/${EFL_LIB_CURRENT}/modules/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
352 endif() 603 endif()
353 604
354 set(SOURCES) 605 set(SOURCES)
355 set(DEPENDENCIES) 606 set(OBJECT_DEPENDS)
356 set(LIBRARIES) 607 set(LIBRARIES)
357 set(INCLUDE_DIRECTORIES) 608 set(INCLUDE_DIRECTORIES)
358 set(SYSTEM_INCLUDE_DIRECTORIES) 609 set(SYSTEM_INCLUDE_DIRECTORIES)
359 set(DEFINITIONS) 610 set(DEFINITIONS)
360 set(MODULE_TYPE "ON") 611 set(MODULE_TYPE "ON")
612 set(INSTALL_DIR ${_modoutdir})
361 613
362 include(${_modsrcdir}/CMakeLists.txt) 614 include(${_modsrcdir}/CMakeLists.txt)
363 615
@@ -365,19 +617,19 @@ function(EFL_MODULE _modname)
365 message(WARNING "${_modsrcdir}/CMakeLists.txt defines no SOURCES") 617 message(WARNING "${_modsrcdir}/CMakeLists.txt defines no SOURCES")
366 return() 618 return()
367 endif() 619 endif()
620 if(PUBLIC_HEADERS)
621 message(WARNING "${_modsrcdir}/CMakeLists.txt should not define PUBLIC_HEADERS, it's not to be installed.")
622 endif()
368 623
369 if(EFL_MODULE_SCOPE) 624 if(EFL_MODULE_SCOPE)
370 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${EFL_MODULE_SCOPE}/${_modname}) 625 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${EFL_MODULE_SCOPE}/${_modname})
371 set(_modtarget ${EFL_LIB_CURRENT}-module-${EFL_MODULE_SCOPE}-${_modname}) 626 set(_modtarget ${EFL_LIB_CURRENT}-module-${EFL_MODULE_SCOPE}-${_modname})
372 set(_modoutdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EFL_LIB_CURRENT}/modules/${EFL_MODULE_SCOPE}/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
373 else() 627 else()
374 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${_modname}) 628 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${_modname})
375 set(_modtarget ${EFL_LIB_CURRENT}-module-${_modname}) 629 set(_modtarget ${EFL_LIB_CURRENT}-module-${_modname})
376 set(_modoutdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EFL_LIB_CURRENT}/modules/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
377 endif() 630 endif()
378 631
379 if("${MODULE_TYPE}" STREQUAL "OFF") 632 if("${MODULE_TYPE}" STREQUAL "OFF")
380 message(WARNING "${_modsrcdir} disabled")
381 return() 633 return()
382 elseif("${MODULE_TYPE}" STREQUAL "STATIC") 634 elseif("${MODULE_TYPE}" STREQUAL "STATIC")
383 set(_modtype STATIC) 635 set(_modtype STATIC)
@@ -385,27 +637,12 @@ function(EFL_MODULE _modname)
385 set(_modtype MODULE) 637 set(_modtype MODULE)
386 endif() 638 endif()
387 639
388 set(_sources "") 640 EFL_FILES_TO_ABSOLUTE(_sources ${_modsrcdir} ${_modbindir} ${SOURCES})
389 foreach(f ${SOURCES}) 641 EFL_FILES_TO_ABSOLUTE(_obj_deps ${_modsrcdir} ${_modbindir} ${OBJECT_DEPENDS})
390 if(EXISTS "${_modsrcdir}/${f}")
391 list(APPEND _sources "${_modsrcdir}/${f}")
392 else()
393 list(APPEND _sources "${_modbindir}/${f}")
394 endif()
395 endforeach()
396
397 set(_deps "")
398 foreach(f ${DEPENDENCIES})
399 if(EXISTS "${_modsrcdir}/${f}")
400 list(APPEND _deps "${_modsrcdir}/${f}")
401 else()
402 list(APPEND _deps "${_modbindir}/${f}")
403 endif()
404 endforeach()
405 642
406 add_library(${_modtarget} ${_modtype} ${_sources}) 643 add_library(${_modtarget} ${_modtype} ${_sources})
407 set_target_properties(${_modtarget} PROPERTIES 644 set_target_properties(${_modtarget} PROPERTIES
408 OBJECT_DEPENDS "${_deps}" 645 OBJECT_DEPENDS "${_obj_deps}"
409 PREFIX "" 646 PREFIX ""
410 OUTPUT_NAME "module") 647 OUTPUT_NAME "module")
411 648
@@ -436,5 +673,8 @@ function(EFL_MODULE _modname)
436 else() 673 else()
437 target_link_libraries(${_modtarget} ${EFL_LIB_CURRENT}) 674 target_link_libraries(${_modtarget} ${EFL_LIB_CURRENT})
438 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_MODULES ${_modtarget}) 675 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_MODULES ${_modtarget})
676 if(INSTALL_DIR)
677 install(TARGETS ${_modtarget} LIBRARY DESTINATION "${INSTALL_DIR}")
678 endif()
439 endif() 679 endif()
440endfunction() 680endfunction()