summaryrefslogtreecommitdiff
path: root/cmake/helpers/EflMacros.cmake
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-20 13:53:56 -0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-01-23 18:23:40 +0100
commitd9815a6837f1e06def0641da285863f87729683f (patch)
tree7ff20525c2876382bef6247108f823b0f3c82459 /cmake/helpers/EflMacros.cmake
parent3d5abc081f59dda9887dbacc8e8ab24c96d5ee65 (diff)
CMake: move eina binaries to single dir, add helper macros.
For one-source directories, be smart and just define SOURCES to that, will reduce the number of too-simplistic CMakeLists.txt in our tree. This also fixes problems with libraries, they should be private, not public. So specify both kinds as different variables.
Diffstat (limited to 'cmake/helpers/EflMacros.cmake')
-rw-r--r--cmake/helpers/EflMacros.cmake85
1 files changed, 63 insertions, 22 deletions
diff --git a/cmake/helpers/EflMacros.cmake b/cmake/helpers/EflMacros.cmake
index 4665a03a80..1c2c752107 100644
--- a/cmake/helpers/EflMacros.cmake
+++ b/cmake/helpers/EflMacros.cmake
@@ -137,6 +137,49 @@ function(EFL_FILES_TO_ABSOLUTE _var _srcdir _bindir)
137 set(${_var} "${_lst}" PARENT_SCOPE) 137 set(${_var} "${_lst}" PARENT_SCOPE)
138endfunction() 138endfunction()
139 139
140# _EFL_INCLUDE_OR_DETECT(Name Source_Dir)
141#
142# Internal macro that will include(${Source_Dir}/CMakeLists.txt) if
143# that exists, otherwise will check if there is a single source file,
144# in that case it will automatically define SOURCES to that (including
145# extras such as headers and .eo)
146#
147# Name is only used to print out messages when it's auto-detected.
148macro(_EFL_INCLUDE_OR_DETECT _name _srcdir)
149 if(EXISTS ${_srcdir}/CMakeLists.txt)
150 include(${_srcdir}/CMakeLists.txt)
151 else()
152 # doc says it's not recommended because it can't know if more files
153 # were added, but we're doing this explicitly to handle one file.
154 file(GLOB _autodetect_files RELATIVE ${_srcdir}
155 ${_srcdir}/*.c
156 ${_srcdir}/*.h
157 ${_srcdir}/*.hh
158 ${_srcdir}/*.cxx
159 ${_srcdir}/*.cpp
160 ${_srcdir}/*.eo
161 )
162 list(LENGTH _autodetect_files _autodetect_files_count)
163 if(_autodetect_files_count GREATER 1)
164 message(WARNING "${_name}: ${_srcdir} contains no CMakeLists.txt and contains more than one source file. Don't know what to do, then ignored.")
165 elseif(_autodetect_files_count EQUAL 1)
166 file(GLOB SOURCES RELATIVE ${_srcdir}
167 ${_srcdir}/*.c
168 ${_srcdir}/*.h
169 ${_srcdir}/*.hh
170 ${_srcdir}/*.cxx
171 ${_srcdir}/*.cpp
172 ${_srcdir}/*.eo
173 )
174 message(STATUS "${_name} auto-detected as: ${SOURCES}")
175 else()
176 message(STATUS "${_name} contains no auto-detectable sources.")
177 endif()
178 unset(_autodetect_files_count)
179 unset(_autodetect_files)
180 endif()
181endmacro()
182
140# _EFL_LIB_PROCESS_MODULES_INTERNAL() 183# _EFL_LIB_PROCESS_MODULES_INTERNAL()
141# 184#
142# Internal function to process modules of current EFL_LIB() 185# Internal function to process modules of current EFL_LIB()
@@ -149,8 +192,6 @@ function(_EFL_LIB_PROCESS_MODULES_INTERNAL)
149 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${module}) 192 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${module})
150 set(EFL_MODULE_SCOPE ${module}) 193 set(EFL_MODULE_SCOPE ${module})
151 194
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}/*) 195 file(GLOB submodules RELATIVE ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE} ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/*)
155 foreach(submodule ${submodules}) 196 foreach(submodule ${submodules})
156 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${submodule}) 197 if(IS_DIRECTORY ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${submodule})
@@ -227,7 +268,8 @@ endfunction()
227# - LIBRARY_TYPE: SHARED or STATIC, defaults to SHARED 268# - LIBRARY_TYPE: SHARED or STATIC, defaults to SHARED
228# - OBJECT_DEPENDS: say this object depends on other files (ie: includes) 269# - OBJECT_DEPENDS: say this object depends on other files (ie: includes)
229# - DEPENDENCIES: results in add_dependencies() 270# - DEPENDENCIES: results in add_dependencies()
230# - LIBRARIES: results in target_link_libraries() 271# - LIBRARIES: results in target_link_libraries(LINK_PRIVATE)
272# - PUBLIC_LIBRARIES: results in target_link_libraries(LINK_PUBLIC)
231# - DEFINITIONS: target_compile_definitions() 273# - DEFINITIONS: target_compile_definitions()
232# 274#
233# Defines the following variables that can be used within the included files: 275# Defines the following variables that can be used within the included files:
@@ -291,6 +333,7 @@ function(EFL_LIB _target)
291 set(OBJECT_DEPENDS) 333 set(OBJECT_DEPENDS)
292 set(DEPENDENCIES) 334 set(DEPENDENCIES)
293 set(LIBRARIES) 335 set(LIBRARIES)
336 set(PUBLIC_LIBRARIES)
294 set(DEFINITIONS) 337 set(DEFINITIONS)
295 338
296 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/${_target}.cmake OPTIONAL) 339 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/${_target}.cmake OPTIONAL)
@@ -317,7 +360,10 @@ function(EFL_LIB _target)
317 endif() 360 endif()
318 361
319 if(LIBRARIES) 362 if(LIBRARIES)
320 target_link_libraries(${_target} ${LIBRARIES}) 363 target_link_libraries(${_target} LINK_PRIVATE ${LIBRARIES})
364 endif()
365 if(PUBLIC_LIBRARIES)
366 target_link_libraries(${_target} LINK_PRIVATE ${PUBLIC_LIBRARIES})
321 endif() 367 endif()
322 368
323 target_include_directories(${_target} PUBLIC 369 target_include_directories(${_target} PUBLIC
@@ -364,10 +410,9 @@ function(EFL_LIB _target)
364 unset(OBJECT_DEPENDS) 410 unset(OBJECT_DEPENDS)
365 unset(DEPENDENCIES) 411 unset(DEPENDENCIES)
366 unset(LIBRARIES) 412 unset(LIBRARIES)
413 unset(PUBLIC_LIBRARIES)
367 unset(DEFINITIONS) 414 unset(DEFINITIONS)
368 415
369 include(${EFL_BIN_SOURCE_DIR}/CMakeLists.txt OPTIONAL)
370
371 _EFL_LIB_PROCESS_BINS_INTERNAL() 416 _EFL_LIB_PROCESS_BINS_INTERNAL()
372 _EFL_LIB_PROCESS_MODULES_INTERNAL() 417 _EFL_LIB_PROCESS_MODULES_INTERNAL()
373 _EFL_LIB_PROCESS_TESTS_INTERNAL() 418 _EFL_LIB_PROCESS_TESTS_INTERNAL()
@@ -420,7 +465,7 @@ function(EFL_BIN _binname)
420 set(_bintarget "${_binname}") 465 set(_bintarget "${_binname}")
421 endif() 466 endif()
422 467
423 include(${_binsrcdir}/CMakeLists.txt) 468 _EFL_INCLUDE_OR_DETECT("Binary ${_bintarget}" ${_binsrcdir})
424 469
425 if(NOT SOURCES) 470 if(NOT SOURCES)
426 message(WARNING "${_binsrcdir}/CMakeLists.txt defines no SOURCES") 471 message(WARNING "${_binsrcdir}/CMakeLists.txt defines no SOURCES")
@@ -452,7 +497,7 @@ function(EFL_BIN _binname)
452 target_include_directories(${_bintarget} SYSTEM PRIVATE 497 target_include_directories(${_bintarget} SYSTEM PRIVATE
453 ${SYSTEM_INCLUDE_DIRECTORIES}) 498 ${SYSTEM_INCLUDE_DIRECTORIES})
454 endif() 499 endif()
455 target_link_libraries(${_bintarget} 500 target_link_libraries(${_bintarget} LINK_PRIVATE
456 ${EFL_LIB_CURRENT} 501 ${EFL_LIB_CURRENT}
457 ${LIBRARIES}) 502 ${LIBRARIES})
458 503
@@ -517,7 +562,7 @@ function(EFL_TEST _testname)
517 set(_testtarget "${EFL_LIB_CURRENT}-test-${_testname}") 562 set(_testtarget "${EFL_LIB_CURRENT}-test-${_testname}")
518 endif() 563 endif()
519 564
520 include(${_testsrcdir}/CMakeLists.txt) 565 _EFL_INCLUDE_OR_DETECT("Test ${_testtarget}" ${_testsrcdir})
521 566
522 if(NOT SOURCES) 567 if(NOT SOURCES)
523 message(WARNING "${_testsrcdir}/CMakeLists.txt defines no SOURCES") 568 message(WARNING "${_testsrcdir}/CMakeLists.txt defines no SOURCES")
@@ -548,7 +593,7 @@ function(EFL_TEST _testname)
548 target_include_directories(${_testtarget} SYSTEM PRIVATE 593 target_include_directories(${_testtarget} SYSTEM PRIVATE
549 ${SYSTEM_INCLUDE_DIRECTORIES} 594 ${SYSTEM_INCLUDE_DIRECTORIES}
550 ${CHECK_INCLUDE_DIRS}) 595 ${CHECK_INCLUDE_DIRS})
551 target_link_libraries(${_testtarget} 596 target_link_libraries(${_testtarget} LINK_PRIVATE
552 ${EFL_LIB_CURRENT} 597 ${EFL_LIB_CURRENT}
553 ${LIBRARIES} 598 ${LIBRARIES}
554 ${CHECK_LIBRARIES}) 599 ${CHECK_LIBRARIES})
@@ -597,9 +642,13 @@ function(EFL_MODULE _modname)
597 if(EFL_MODULE_SCOPE) 642 if(EFL_MODULE_SCOPE)
598 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${EFL_MODULE_SCOPE}/${_modname}) 643 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}) 644 set(_modoutdir lib/${EFL_LIB_CURRENT}/modules/${EFL_MODULE_SCOPE}/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
645 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${EFL_MODULE_SCOPE}/${_modname})
646 set(_modtarget ${EFL_LIB_CURRENT}-module-${EFL_MODULE_SCOPE}-${_modname})
600 else() 647 else()
601 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${_modname}) 648 set(_modsrcdir ${EFL_MODULES_SOURCE_DIR}/${_modname})
602 set(_modoutdir lib/${EFL_LIB_CURRENT}/modules/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) 649 set(_modoutdir lib/${EFL_LIB_CURRENT}/modules/${_modname}/v-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
650 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${_modname})
651 set(_modtarget ${EFL_LIB_CURRENT}-module-${_modname})
603 endif() 652 endif()
604 653
605 set(SOURCES) 654 set(SOURCES)
@@ -611,7 +660,7 @@ function(EFL_MODULE _modname)
611 set(MODULE_TYPE "ON") 660 set(MODULE_TYPE "ON")
612 set(INSTALL_DIR ${_modoutdir}) 661 set(INSTALL_DIR ${_modoutdir})
613 662
614 include(${_modsrcdir}/CMakeLists.txt) 663 _EFL_INCLUDE_OR_DETECT("Module ${_modtarget}" ${_modsrcdir})
615 664
616 if(NOT SOURCES) 665 if(NOT SOURCES)
617 message(WARNING "${_modsrcdir}/CMakeLists.txt defines no SOURCES") 666 message(WARNING "${_modsrcdir}/CMakeLists.txt defines no SOURCES")
@@ -621,14 +670,6 @@ function(EFL_MODULE _modname)
621 message(WARNING "${_modsrcdir}/CMakeLists.txt should not define PUBLIC_HEADERS, it's not to be installed.") 670 message(WARNING "${_modsrcdir}/CMakeLists.txt should not define PUBLIC_HEADERS, it's not to be installed.")
622 endif() 671 endif()
623 672
624 if(EFL_MODULE_SCOPE)
625 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${EFL_MODULE_SCOPE}/${_modname})
626 set(_modtarget ${EFL_LIB_CURRENT}-module-${EFL_MODULE_SCOPE}-${_modname})
627 else()
628 set(_modbindir ${EFL_MODULES_BINARY_DIR}/${_modname})
629 set(_modtarget ${EFL_LIB_CURRENT}-module-${_modname})
630 endif()
631
632 if("${MODULE_TYPE}" STREQUAL "OFF") 673 if("${MODULE_TYPE}" STREQUAL "OFF")
633 return() 674 return()
634 elseif("${MODULE_TYPE}" STREQUAL "STATIC") 675 elseif("${MODULE_TYPE}" STREQUAL "STATIC")
@@ -652,7 +693,7 @@ function(EFL_MODULE _modname)
652 ${INCLUDE_DIRECTORIES}) 693 ${INCLUDE_DIRECTORIES})
653 target_include_directories(${_modtarget} SYSTEM PUBLIC 694 target_include_directories(${_modtarget} SYSTEM PUBLIC
654 ${SYSTEM_INCLUDE_DIRECTORIES}) 695 ${SYSTEM_INCLUDE_DIRECTORIES})
655 target_link_libraries(${_modtarget} ${LIBRARIES}) 696 target_link_libraries(${_modtarget} LINK_PRIVATE ${LIBRARIES})
656 697
657 target_compile_definitions(${_modtarget} PRIVATE ${DEFINITIONS}) 698 target_compile_definitions(${_modtarget} PRIVATE ${DEFINITIONS})
658 699
@@ -662,7 +703,7 @@ function(EFL_MODULE _modname)
662 RUNTIME_OUTPUT_DIRECTORY "${_modoutdir}") 703 RUNTIME_OUTPUT_DIRECTORY "${_modoutdir}")
663 704
664 if("${MODULE_TYPE}" STREQUAL "STATIC") 705 if("${MODULE_TYPE}" STREQUAL "STATIC")
665 target_link_libraries(${EFL_LIB_CURRENT} ${_modtarget}) 706 target_link_libraries(${EFL_LIB_CURRENT} LINK_PRIVATE ${_modtarget})
666 target_include_directories(${_modtarget} PRIVATE 707 target_include_directories(${_modtarget} PRIVATE
667 ${EFL_LIB_SOURCE_DIR} 708 ${EFL_LIB_SOURCE_DIR}
668 ${EFL_LIB_BINARY_DIR}) 709 ${EFL_LIB_BINARY_DIR})
@@ -671,7 +712,7 @@ function(EFL_MODULE _modname)
671 712
672 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_STATIC_MODULES ${_modtarget}) 713 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_STATIC_MODULES ${_modtarget})
673 else() 714 else()
674 target_link_libraries(${_modtarget} ${EFL_LIB_CURRENT}) 715 target_link_libraries(${_modtarget} LINK_PRIVATE ${EFL_LIB_CURRENT})
675 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_MODULES ${_modtarget}) 716 LIST_APPEND_GLOBAL(${EFL_LIB_CURRENT}_MODULES ${_modtarget})
676 if(INSTALL_DIR) 717 if(INSTALL_DIR)
677 install(TARGETS ${_modtarget} LIBRARY DESTINATION "${INSTALL_DIR}") 718 install(TARGETS ${_modtarget} LIBRARY DESTINATION "${INSTALL_DIR}")