summaryrefslogtreecommitdiff
path: root/cmake/helpers/EflMacros.cmake
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-25 14:50:04 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-01-25 19:29:20 -0200
commitfd8865d0d048cc4b03adb7422a5cd67b5e33ba0a (patch)
tree59bc99c1ee72c0af831d055663c45b13641c04e0 /cmake/helpers/EflMacros.cmake
parent4d21d6c56a697e0cfaa11cee5a6fb3f16739ddac (diff)
cmake: EFL_OPTION() now supports DEPENDS to handle conditionals.
This is now used by ENABLE_SYSTEMD and ENABLE_VALGRIND, which moves to "common.cmake" since they are shared among multiple libraries. With that I found that LINK_FLAGS is indeed a string, not a CMake List (space separated, not ";"), then fix that so compilation actually works.
Diffstat (limited to '')
-rw-r--r--cmake/helpers/EflMacros.cmake112
1 files changed, 92 insertions, 20 deletions
diff --git a/cmake/helpers/EflMacros.cmake b/cmake/helpers/EflMacros.cmake
index 2f91e8a63a..c212d70bc1 100644
--- a/cmake/helpers/EflMacros.cmake
+++ b/cmake/helpers/EflMacros.cmake
@@ -28,7 +28,9 @@ unset(EFL_ALL_LIBS CACHE)
28unset(EFL_ALL_TESTS CACHE) 28unset(EFL_ALL_TESTS CACHE)
29unset(EFL_PKG_CONFIG_MISSING_OPTIONAL CACHE) 29unset(EFL_PKG_CONFIG_MISSING_OPTIONAL CACHE)
30 30
31# EFL_OPTION(Name Help Default) 31# EFL_OPTION(Name Help Default [STRING|BOOL|FILEPATH|PATH]
32# [CHOICE c1;...;cN]
33# [DEPENDS "COND1; COND2; NOT COND3" FAILED_VALUE])
32# 34#
33# Declare an option() that will be automatically printed by 35# Declare an option() that will be automatically printed by
34# EFL_OPTIONS_SUMMARY() 36# EFL_OPTIONS_SUMMARY()
@@ -36,33 +38,84 @@ unset(EFL_PKG_CONFIG_MISSING_OPTIONAL CACHE)
36# To extend the EFL_OPTIONS_SUMMARY() message, use 38# To extend the EFL_OPTIONS_SUMMARY() message, use
37# EFL_OPTION_SET_MESSAGE(Name Message) 39# EFL_OPTION_SET_MESSAGE(Name Message)
38function(EFL_OPTION _name _help _defval) 40function(EFL_OPTION _name _help _defval)
41
42 cmake_parse_arguments(PARAMS "" "" "CHOICE;DEPENDS" ${ARGN})
43
39 set(_type) 44 set(_type)
40 set(_vartype) 45 set(_vartype)
41 set(_choices) 46 set(_choices)
42 list(LENGTH ARGN _argc) 47
48 list(LENGTH PARAMS_UNPARSED_ARGUMENTS _argc)
43 if(_argc LESS 1) 49 if(_argc LESS 1)
44 set(_type BOOL) 50 set(_type BOOL)
45 set(_vartype BOOL) 51 set(_vartype BOOL)
46 else() 52 else()
47 list(GET ARGN 0 _type) 53 list(GET PARAMS_UNPARSED_ARGUMENTS 0 _type)
48 set(_vartype ${_type}) 54 set(_vartype ${_type})
49 list(REMOVE_AT ARGN 0) 55 list(REMOVE_AT PARAMS_UNPARSED_ARGUMENTS 0)
50 endif() 56 endif()
51 if(${_vartype} STREQUAL "CHOICE") 57
52 set(_type STRING) 58 if(PARAMS_CHOICE)
53 SET_GLOBAL(EFL_OPTION_CHOICES_${_name} "${ARGN}" "Possible values for ${_name}") 59 set(_type CHOICE)
54 set(_choices " (Choices: ${ARGN})") 60 set(_vartype STRING)
61 SET_GLOBAL(EFL_OPTION_CHOICES_${_name} "${PARAMS_CHOICE}" "Possible values for ${_name}")
62 set(_choices " (Choices: ${PARAMS_CHOICE})")
63 endif()
64
65 if(_type STREQUAL "BOOL")
66 # force ON/OFF representation
67 if(_defval)
68 set(_defval ON)
69 else()
70 set(_defval OFF)
71 endif()
55 endif() 72 endif()
56 73
57 LIST_APPEND_GLOBAL(EFL_ALL_OPTIONS ${_name}) 74 LIST_APPEND_GLOBAL(EFL_ALL_OPTIONS ${_name})
58 75
59 SET_GLOBAL(EFL_OPTION_DEFAULT_${_name} "${_defval}" "Default value for ${_name}") 76 SET_GLOBAL(EFL_OPTION_DEFAULT_${_name} "${_defval}" "Default value for ${_name}")
60 SET_GLOBAL(EFL_OPTION_TYPE_${_name} "${_vartype}" "Type of ${_name}") 77 SET_GLOBAL(EFL_OPTION_TYPE_${_name} "${_vartype}" "Type of ${_name}")
61 set(${_name} ${_defval} CACHE ${_type} "${_help}${_choices}") 78
62 option(${_name} "${_help}${_choices}" ${_defval}) 79 set(_available ON)
80 if(PARAMS_DEPENDS)
81 list(LENGTH PARAMS_DEPENDS _count)
82 list(GET PARAMS_DEPENDS 0 _deps)
83 list(GET PARAMS_DEPENDS 1 _deps_failure_value)
84 if(_deps_failure_value STREQUAL "NOTFOUND")
85 message(FATAL_ERROR "EFL_OPTION(${_name}) has DEPENDS but no value when dependencies fail")
86 endif()
87
88 set(_missing_deps "")
89 foreach(_d ${_deps})
90 if(${_d})
91 else()
92 set(_available OFF)
93 list(APPEND _missing_deps "${_d}")
94 endif()
95 endforeach()
96 endif()
97
98 if(_available)
99 if(DEFINED EFL_OPTION_ORIGINAL_VALUE_${_name})
100 set(${_name} ${EFL_OPTION_ORIGINAL_VALUE_${_name}} CACHE ${_type} "${_help}${_choices}" FORCE)
101 unset(EFL_OPTION_ORIGINAL_VALUE_${_name} CACHE)
102 else()
103 set(${_name} ${_defval} CACHE ${_type} "${_help}${_choices}")
104 endif()
105 unset(EFL_OPTION_DEPENDS_MISSING_${_name} CACHE)
106 option(${_name} "${_help}${_choices}" "${${_name}}")
107 else()
108 if(NOT DEFINED EFL_OPTION_ORIGINAL_VALUE_${_name})
109 if(DEFINED ${_name})
110 SET_GLOBAL(EFL_OPTION_ORIGINAL_VALUE_${_name} "${${_name}}")
111 endif()
112 endif()
113 SET_GLOBAL(EFL_OPTION_DEPENDS_MISSING_${_name} "${_missing_deps}")
114 set(${_name} "${_deps_failure_value}" CACHE "${_type}" "Missing dependencies (${_help}${_choices})" FORCE)
115 endif()
63 116
64 if(_choices) 117 if(_choices)
65 list(FIND ARGN "${${_name}}" _ret) 118 list(FIND PARAMS_CHOICE "${${_name}}" _ret)
66 if(${_ret} EQUAL -1) 119 if(${_ret} EQUAL -1)
67 message(FATAL_ERROR "Invalid choice ${_name}=${${_name}}${_choices}") 120 message(FATAL_ERROR "Invalid choice ${_name}=${${_name}}${_choices}")
68 endif() 121 endif()
@@ -86,7 +139,9 @@ function(EFL_OPTIONS_SUMMARY)
86 foreach(_o ${EFL_ALL_OPTIONS}) 139 foreach(_o ${EFL_ALL_OPTIONS})
87 set(_v ${${_o}}) 140 set(_v ${${_o}})
88 set(_d ${EFL_OPTION_DEFAULT_${_o}}) 141 set(_d ${EFL_OPTION_DEFAULT_${_o}})
89 if("${_v}" STREQUAL "${_d}") 142 if(EFL_OPTION_DEPENDS_MISSING_${_o})
143 set(_i "requires: ${EFL_OPTION_DEPENDS_MISSING_${_o}}, was: ${EFL_OPTION_ORIGINAL_VALUE_${_o}}")
144 elseif("${_v}" STREQUAL "${_d}")
90 set(_i "default") 145 set(_i "default")
91 else() 146 else()
92 set(_i "default: ${_d}") 147 set(_i "default: ${_d}")
@@ -737,10 +792,15 @@ function(EFL_LIB _target)
737 792
738 EFL_PKG_CONFIG_EVAL(${_target} "${PKG_CONFIG_REQUIRES_PRIVATE}" "${PKG_CONFIG_REQUIRES}") 793 EFL_PKG_CONFIG_EVAL(${_target} "${PKG_CONFIG_REQUIRES_PRIVATE}" "${PKG_CONFIG_REQUIRES}")
739 794
740 set(_link_flags ${${_target}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS} ${${_target}_PKG_CONFIG_REQUIRES_LDFLAGS}) 795 set(__link_flags ${${_target}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS} ${${_target}_PKG_CONFIG_REQUIRES_LDFLAGS})
741 set(__compile_flags ${${_target}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS} ${${_target}_PKG_CONFIG_REQUIRES_CFLAGS} -DPACKAGE_DATA_DIR=\\"${CMAKE_INSTALL_FULL_DATADIR}/${_target}/\\") 796 set(__compile_flags ${${_target}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS} ${${_target}_PKG_CONFIG_REQUIRES_CFLAGS} -DPACKAGE_DATA_DIR=\\"${CMAKE_INSTALL_FULL_DATADIR}/${_target}/\\")
797
798 set(_link_flags)
799 foreach(_l ${__link_flags})
800 set(_link_flags "${_link_flags} ${_l}")
801 endforeach()
802
742 set(_compile_flags) 803 set(_compile_flags)
743 # CMake uses string for COMPILE_FLAGS but list for LINK_FLAGS... :-/
744 foreach(_c ${__compile_flags}) 804 foreach(_c ${__compile_flags})
745 set(_compile_flags "${_compile_flags} ${_c}") 805 set(_compile_flags "${_compile_flags} ${_c}")
746 endforeach() 806 endforeach()
@@ -931,14 +991,18 @@ function(EFL_BIN _binname)
931 set_target_properties(${_bintarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) 991 set_target_properties(${_bintarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
932 endif() 992 endif()
933 993
934 # CMake uses string for COMPILE_FLAGS but list for LINK_FLAGS... :-/ 994 set(_link_flags)
995 foreach(_l ${${_bintarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS})
996 set(_link_flags "${_link_flags} ${_l}")
997 endforeach()
998
935 set(_compile_flags) 999 set(_compile_flags)
936 foreach(_c ${${_bintarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS}) 1000 foreach(_c ${${_bintarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS})
937 set(_compile_flags "${_compile_flags} ${_c}") 1001 set(_compile_flags "${_compile_flags} ${_c}")
938 endforeach() 1002 endforeach()
939 1003
940 set_target_properties(${_bintarget} PROPERTIES 1004 set_target_properties(${_bintarget} PROPERTIES
941 LINK_FLAGS "${${_bintarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS}" 1005 LINK_FLAGS "${_link_flags}"
942 COMPILE_FLAGS "${_compile_flags}") 1006 COMPILE_FLAGS "${_compile_flags}")
943 1007
944 if(INSTALL_DIR) 1008 if(INSTALL_DIR)
@@ -1049,14 +1113,18 @@ function(EFL_TEST _testname)
1049 set_target_properties(${_testtarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) 1113 set_target_properties(${_testtarget} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
1050 endif() 1114 endif()
1051 1115
1052 # CMake uses string for COMPILE_FLAGS but list for LINK_FLAGS... :-/ 1116 set(_link_flags)
1117 foreach(_l ${${_testtarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS})
1118 set(_link_flags "${_link_flags} ${_l}")
1119 endforeach()
1120
1053 set(_compile_flags) 1121 set(_compile_flags)
1054 foreach(_c ${${_testtarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS}) 1122 foreach(_c ${${_testtarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS})
1055 set(_compile_flags "${_compile_flags} ${_c}") 1123 set(_compile_flags "${_compile_flags} ${_c}")
1056 endforeach() 1124 endforeach()
1057 1125
1058 set_target_properties(${_testtarget} PROPERTIES 1126 set_target_properties(${_testtarget} PROPERTIES
1059 LINK_FLAGS "${${_testtarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS}" 1127 LINK_FLAGS "${_link_flags}"
1060 COMPILE_FLAGS "${_compile_flags}" 1128 COMPILE_FLAGS "${_compile_flags}"
1061 LIBRARY_OUTPUT_DIRECTORY "${_testbindir}" 1129 LIBRARY_OUTPUT_DIRECTORY "${_testbindir}"
1062 RUNTIME_OUTPUT_DIRECTORY "${_testbindir}") 1130 RUNTIME_OUTPUT_DIRECTORY "${_testbindir}")
@@ -1167,14 +1235,18 @@ function(EFL_MODULE _modname)
1167 1235
1168 target_compile_definitions(${_modtarget} PRIVATE ${DEFINITIONS}) 1236 target_compile_definitions(${_modtarget} PRIVATE ${DEFINITIONS})
1169 1237
1170 # CMake uses string for COMPILE_FLAGS but list for LINK_FLAGS... :-/ 1238 set(_link_flags)
1239 foreach(_l ${${_modtarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS})
1240 set(_link_flags "${_link_flags} ${_l}")
1241 endforeach()
1242
1171 set(_compile_flags) 1243 set(_compile_flags)
1172 foreach(_c ${${_modtarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS}) 1244 foreach(_c ${${_modtarget}_PKG_CONFIG_REQUIRES_PRIVATE_CFLAGS})
1173 set(_compile_flags "${_compile_flags} ${_c}") 1245 set(_compile_flags "${_compile_flags} ${_c}")
1174 endforeach() 1246 endforeach()
1175 1247
1176 set_target_properties(${_modtarget} PROPERTIES 1248 set_target_properties(${_modtarget} PROPERTIES
1177 LINK_FLAGS "${${_modtarget}_PKG_CONFIG_REQUIRES_PRIVATE_LDFLAGS}" 1249 LINK_FLAGS "${_link_flags}"
1178 COMPILE_FLAGS "${_compile_flags}" 1250 COMPILE_FLAGS "${_compile_flags}"
1179 LIBRARY_OUTPUT_DIRECTORY "${_modoutdir}" 1251 LIBRARY_OUTPUT_DIRECTORY "${_modoutdir}"
1180 ARCHIVE_OUTPUT_DIRECTORY "${_modoutdir}" 1252 ARCHIVE_OUTPUT_DIRECTORY "${_modoutdir}"