Changeset View
Standalone View
cmake/modules/KDevelopMacrosInternal.cmake
1 | # | 1 | # | ||
---|---|---|---|---|---|
2 | # KDevelop Private Macros | 2 | # KDevelop Private Macros | ||
3 | # | 3 | # | ||
4 | # The following macros are defined here: | 4 | # The following macros are defined here: | ||
5 | # | 5 | # | ||
6 | # add_compile_flag_if_supported(<flag> [CXX_ONLY]) | 6 | # add_compile_flag_if_supported(<flag> [CXX_ONLY]) | ||
7 | # add_target_compile_flag_if_supported(<target> <INTERFACE|PUBLIC|PRIVATE> <flag>) | 7 | # add_target_compile_flag_if_supported(<target> <INTERFACE|PUBLIC|PRIVATE> <flag>) | ||
8 | # declare_qt_logging_category(<sourcevarname> HEADER <filename> IDENTIFIER <id> CATEGORY_NAME <name> EXPORT <target> DESCRIPTION <desc>) | 8 | # declare_qt_logging_category(<sourcevarname> | ||
9 | # install_qt_logging_categories(EXPORT <target> FILE <name>) | 9 | # TYPE LIBRARY|PLUGIN|APP [IDENTIFIER <id>] [CATEGORY_BASENAME <name>] | ||
10 | # [HEADER <filename>] [DESCRIPTION <desc>]) | ||||
11 | # install_qt_logging_categories(TYPE LIBRARY|APP_PLUGIN) | ||||
10 | # | 12 | # | ||
11 | #============================================================================= | 13 | #============================================================================= | ||
12 | # Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | 14 | # Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||
13 | # | 15 | # | ||
14 | # Distributed under the OSI-approved BSD License (the "License"); | 16 | # Distributed under the OSI-approved BSD License (the "License"); | ||
15 | # see accompanying file Copyright.txt for details. | 17 | # see accompanying file Copyright.txt for details. | ||
16 | # | 18 | # | ||
17 | # This software is distributed WITHOUT ANY WARRANTY; without even the | 19 | # This software is distributed WITHOUT ANY WARRANTY; without even the | ||
Show All 38 Lines | 56 | function(add_target_compile_flag_if_supported _target _scope _flag) | |||
56 | check_cxx_compiler_flag("${_flag}" "${_varname}") | 58 | check_cxx_compiler_flag("${_flag}" "${_varname}") | ||
57 | 59 | | |||
58 | if (${${_varname}}) | 60 | if (${${_varname}}) | ||
59 | target_compile_options(${_target} ${_scope} "${_flag}") | 61 | target_compile_options(${_target} ${_scope} "${_flag}") | ||
60 | endif() | 62 | endif() | ||
61 | endfunction() | 63 | endfunction() | ||
62 | 64 | | |||
63 | 65 | | |||
64 | # declare_qt_logging_category(<sourcevarname> HEADER <filename> IDENTIFIER <id> CATEGORY_NAME <name> EXPORT <target> DESCRIPTION <desc>) | 66 | # helper method | ||
67 | # _declare_qt_logging_category(<sourcevarname> | ||||
68 | # HEADER <filename> IDENTIFIER <id> CATEGORY_NAME <name> | ||||
69 | # EXPORT <target> DESCRIPTION <desc>) | ||||
65 | # | 70 | # | ||
66 | # Example: | 71 | # Example: | ||
67 | # declare_qt_logging_category(Foo_LIB_SRCS | 72 | # _declare_qt_logging_category(Foo_LIB_SRCS | ||
68 | # HEADER debug.h | 73 | # HEADER debug.h | ||
69 | # IDENTIFIER DOCUMENTATION | 74 | # IDENTIFIER FOO | ||
70 | # CATEGORY_NAME "bar.foo" | 75 | # CATEGORY_NAME "bar.foo" | ||
71 | # DESCRIPTION "The foo of bar" | 76 | # DESCRIPTION "The foo of bar" | ||
72 | # EXPORT BarCategories | 77 | # EXPORT BarCategories | ||
73 | # ) | 78 | # ) | ||
74 | macro(declare_qt_logging_category _sources) | 79 | macro(_declare_qt_logging_category sources) | ||
75 | set(options ) | 80 | set(options ) | ||
76 | set(oneValueArgs HEADER IDENTIFIER CATEGORY_NAME EXPORT DESCRIPTION) | 81 | set(oneValueArgs HEADER IDENTIFIER CATEGORY_NAME EXPORT DESCRIPTION) | ||
77 | set(multiValueArgs) | 82 | set(multiValueArgs) | ||
78 | 83 | | |||
79 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | 84 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
80 | 85 | | |||
81 | if(NOT DEFINED ARGS_HEADER) | 86 | if(NOT DEFINED ARGS_HEADER) | ||
82 | message(FATAL_ERROR "HEADER needs to be defined when calling declare_qt_logging_category().") | 87 | message(FATAL_ERROR "HEADER needs to be defined when calling _declare_qt_logging_category().") | ||
83 | endif() | 88 | endif() | ||
84 | if(NOT DEFINED ARGS_IDENTIFIER) | 89 | if(NOT DEFINED ARGS_IDENTIFIER) | ||
85 | message(FATAL_ERROR "IDENTIFIER needs to be defined when calling declare_qt_logging_category().") | 90 | message(FATAL_ERROR "IDENTIFIER needs to be defined when calling _declare_qt_logging_category().") | ||
86 | endif() | 91 | endif() | ||
87 | if(NOT DEFINED ARGS_CATEGORY_NAME) | 92 | if(NOT DEFINED ARGS_CATEGORY_NAME) | ||
88 | message(FATAL_ERROR "CATEGORY_NAME needs to be defined when calling declare_qt_logging_category().") | 93 | message(FATAL_ERROR "CATEGORY_NAME needs to be defined when calling _declare_qt_logging_category().") | ||
89 | endif() | 94 | endif() | ||
90 | if(NOT DEFINED ARGS_DESCRIPTION) | 95 | if(NOT DEFINED ARGS_DESCRIPTION) | ||
91 | message(FATAL_ERROR "DESCRIPTION needs to be defined when calling declare_qt_logging_category().") | 96 | message(FATAL_ERROR "DESCRIPTION needs to be defined when calling _declare_qt_logging_category().") | ||
92 | endif() | 97 | endif() | ||
93 | 98 | | |||
94 | ecm_qt_declare_logging_category(${_sources} | 99 | ecm_qt_declare_logging_category(${sources} | ||
95 | HEADER ${ARGS_HEADER} | 100 | HEADER ${ARGS_HEADER} | ||
96 | IDENTIFIER ${ARGS_IDENTIFIER} | 101 | IDENTIFIER ${ARGS_IDENTIFIER} | ||
97 | CATEGORY_NAME ${ARGS_CATEGORY_NAME} | 102 | CATEGORY_NAME ${ARGS_CATEGORY_NAME} | ||
98 | ) | 103 | ) | ||
99 | 104 | | |||
100 | # Nasty hack: we create a target just to store all the category data in some build-system global object | 105 | # Nasty hack: we create a target just to store all the category data in some build-system global object | ||
101 | # which then can be accessed from other places like install_qt_logging_categories(). | 106 | # which then can be accessed from other places like _install_qt_logging_categories(). | ||
102 | # we also create it here on first usage, to spare some additional call. | 107 | # we also create it here on first usage, to spare some additional call. | ||
103 | # Better idea how to solve that welcome | 108 | # Better idea how to solve that welcome | ||
104 | set(_targetname "qt_logging_category_${ARGS_EXPORT}") | 109 | set(_targetname "qt_logging_category_${ARGS_EXPORT}") | ||
105 | if (NOT TARGET ${_targetname}) | 110 | if (NOT TARGET ${_targetname}) | ||
106 | add_custom_target(${_targetname}) | 111 | add_custom_target(${_targetname}) | ||
107 | set(_categories ${ARGS_CATEGORY_NAME}) | 112 | set(_categories ${ARGS_CATEGORY_NAME}) | ||
108 | else() | 113 | else() | ||
109 | get_target_property(_value ${_targetname} CATEGORIES) | 114 | get_target_property(_value ${_targetname} CATEGORIES) | ||
110 | set(_categories "${_value};${ARGS_CATEGORY_NAME}") | 115 | set(_categories "${_value};${ARGS_CATEGORY_NAME}") | ||
111 | endif() | 116 | endif() | ||
112 | set_property(TARGET ${_targetname} PROPERTY CATEGORIES "${_categories}") | 117 | set_property(TARGET ${_targetname} PROPERTY CATEGORIES "${_categories}") | ||
113 | set_property(TARGET ${_targetname} PROPERTY "IDENTIFIER_${ARGS_CATEGORY_NAME}" "${ARGS_IDENTIFIER}") | 118 | set_property(TARGET ${_targetname} PROPERTY "IDENTIFIER_${ARGS_CATEGORY_NAME}" "${ARGS_IDENTIFIER}") | ||
114 | set_property(TARGET ${_targetname} PROPERTY "DESCRIPTION_${ARGS_CATEGORY_NAME}" "${ARGS_DESCRIPTION}") | 119 | set_property(TARGET ${_targetname} PROPERTY "DESCRIPTION_${ARGS_CATEGORY_NAME}" "${ARGS_DESCRIPTION}") | ||
115 | endmacro() | 120 | endmacro() | ||
116 | 121 | | |||
117 | 122 | | |||
118 | # install_qt_logging_categories(EXPORT <target> FILE <name>) | 123 | set(_platformlib_qt_logging_categories_export_name "KDevPlatformCategories") | ||
124 | set(_app_plugin_qt_logging_categories_export_name "KDevelopCategories") | ||||
125 | | ||||
126 | | ||||
127 | # declare_qt_logging_category(<sourcevarname> | ||||
128 | # TYPE LIBRARY|PLUGIN|APP [IDENTIFIER <id>] [CATEGORY_BASENAME <name>] | ||||
129 | # [HEADER <filename>] [DESCRIPTION <desc>]) | ||||
130 | # | ||||
131 | # CATEGORY_BASENAME <name> is unused of TYPE APP. | ||||
132 | # IDENTIFIER <id> defaults to upper-case CATEGORY_BASENAME <name>. | ||||
133 | # HEADER <filename> defaults to "debug.h" | ||||
134 | # DESCRIPTION <desc> defaults to CATEGORY_BASENAME <name>. | ||||
135 | # | ||||
136 | # Example: | ||||
137 | # declare_qt_logging_category(Foo_LIB_SRCS | ||||
138 | # TYPE PLUGIN | ||||
kfunk: Way too much code duplication in all those `declare_*_qt_logging_category` calls, IMO... But I… | |||||
The TYPE seems a nice idea to save on the implementation side, will give a try. kossebau: The TYPE seems a nice idea to save on the implementation side, will give a try. | |||||
kfunk: Any reason this is `macro()`? Could be a `function()`, no? | |||||
Macro, because we want to change a variable from the calling scope (the one whose name we get by _sources, which is passed on to ecm_qt_declare_logging_category which is the one actually going to change the very variable.) kossebau: Macro, because we want to change a variable from the calling scope (the one whose name we get… | |||||
Style (sth for a future commit maybe): _sources -> sources or sources_var (to indicate it's an out var) kfunk: Style (sth for a future commit maybe): `_sources` -> `sources` or `sources_var` (to indicate… | |||||
139 | # HEADER foodebug.h | ||||
140 | # IDENTIFIER FOO | ||||
141 | # CATEGORY_BASENAME "foo" | ||||
142 | # ) | ||||
143 | macro(declare_qt_logging_category sources) | ||||
144 | set(options ) | ||||
145 | set(oneValueArgs HEADER IDENTIFIER CATEGORY_BASENAME DESCRIPTION TYPE) | ||||
146 | set(multiValueArgs) | ||||
147 | | ||||
148 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||||
149 | | ||||
150 | if(NOT DEFINED ARGS_TYPE) | ||||
151 | message(FATAL_ERROR "TYPE needs to be defined when calling declare_qt_logging_category().") | ||||
152 | endif() | ||||
153 | if(NOT DEFINED ARGS_IDENTIFIER) | ||||
154 | if(ARGS_TYPE STREQUAL "LIBRARY" OR ARGS_TYPE STREQUAL "PLUGIN") | ||||
155 | string(TOUPPER ${ARGS_CATEGORY_BASENAME} ARGS_IDENTIFIER) | ||||
156 | else() | ||||
157 | message(FATAL_ERROR "IDENTIFIER needs to be defined when calling declare_qt_logging_category().") | ||||
158 | endif() | ||||
159 | endif() | ||||
160 | if(NOT DEFINED ARGS_CATEGORY_BASENAME) | ||||
161 | if(ARGS_TYPE STREQUAL "LIBRARY" OR ARGS_TYPE STREQUAL "PLUGIN") | ||||
162 | message(FATAL_ERROR "CATEGORY_BASENAME needs to be defined when calling declare_qt_logging_category() with TYPE of LIBRARY or PLUGIN.") | ||||
163 | endif() | ||||
164 | endif() | ||||
165 | if(NOT DEFINED ARGS_HEADER) | ||||
166 | set(ARGS_HEADER debug.h) | ||||
167 | endif() | ||||
168 | if(NOT DEFINED ARGS_DESCRIPTION) | ||||
169 | set(ARGS_DESCRIPTION ${ARGS_CATEGORY_BASENAME}) | ||||
170 | endif() | ||||
171 | | ||||
172 | if(ARGS_TYPE STREQUAL "LIBRARY") | ||||
173 | _declare_qt_logging_category(${sources} | ||||
174 | HEADER ${ARGS_HEADER} | ||||
175 | IDENTIFIER ${ARGS_IDENTIFIER} | ||||
176 | CATEGORY_NAME "kdevplatform.${ARGS_CATEGORY_BASENAME}" | ||||
177 | DESCRIPTION "KDevPlatform lib: ${ARGS_DESCRIPTION}" | ||||
178 | EXPORT ${_platformlib_qt_logging_categories_export_name} | ||||
179 | ) | ||||
180 | elseif(ARGS_TYPE STREQUAL "PLUGIN") | ||||
181 | _declare_qt_logging_category(${sources} | ||||
182 | HEADER ${ARGS_HEADER} | ||||
183 | IDENTIFIER ${ARGS_IDENTIFIER} | ||||
184 | CATEGORY_NAME "kdevelop.plugins.${ARGS_CATEGORY_BASENAME}" | ||||
185 | DESCRIPTION "KDevelop plugin: ${ARGS_DESCRIPTION}" | ||||
186 | EXPORT ${_app_plugin_qt_logging_categories_export_name} | ||||
187 | ) | ||||
188 | elseif(ARGS_TYPE STREQUAL "APP") | ||||
189 | _declare_qt_logging_category(${sources} | ||||
190 | HEADER ${ARGS_HEADER} | ||||
191 | IDENTIFIER ${ARGS_IDENTIFIER} | ||||
192 | CATEGORY_NAME "kdevelop.app" | ||||
193 | DESCRIPTION "KDevelop app" | ||||
194 | EXPORT ${_app_plugin_qt_logging_categories_export_name} | ||||
195 | ) | ||||
196 | else() | ||||
197 | message(FATAL_ERROR "Unknown \"${ARGS_TYPE}\" with TYPE when calling declare_qt_logging_category().") | ||||
198 | endif() | ||||
199 | endmacro() | ||||
200 | | ||||
201 | | ||||
202 | # helper method | ||||
203 | # _install_qt_logging_categories(EXPORT <target> FILE <name> MACRONAME <macro>) | ||||
119 | # | 204 | # | ||
120 | # Needs to be called after the last declare_qt_logging_category call which uses the same EXPORT name. | 205 | # Needs to be called after the last _declare_qt_logging_category call which uses the same EXPORT name. | ||
121 | # | 206 | # | ||
122 | # Example: | 207 | # Example: | ||
123 | # install_qt_logging_categories( | 208 | # _install_qt_logging_categories( | ||
124 | # EXPORT KDevPlatformCategories | 209 | # EXPORT KDevPlatformCategories | ||
125 | # FILE kdevplatform.test.categories | 210 | # FILE kdevplatform.categories | ||
126 | # ) | 211 | # ) | ||
127 | function(install_qt_logging_categories) | 212 | function(_install_qt_logging_categories) | ||
128 | set(options ) | 213 | set(options ) | ||
129 | set(oneValueArgs FILE EXPORT) | 214 | set(oneValueArgs FILE EXPORT MACRONAME) | ||
130 | set(multiValueArgs) | 215 | set(multiValueArgs) | ||
131 | 216 | | |||
132 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | 217 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
133 | 218 | | |||
134 | if(NOT DEFINED ARGS_FILE) | 219 | if(NOT DEFINED ARGS_FILE) | ||
135 | message(FATAL_ERROR "FILE needs to be defined when calling install_qt_logging_categories().") | 220 | message(FATAL_ERROR "FILE needs to be defined when calling _install_qt_logging_categories().") | ||
136 | endif() | 221 | endif() | ||
137 | 222 | | |||
138 | if(NOT DEFINED ARGS_EXPORT) | 223 | if(NOT DEFINED ARGS_EXPORT) | ||
139 | message(FATAL_ERROR "EXPORT needs to be defined when calling install_qt_logging_categories().") | 224 | message(FATAL_ERROR "EXPORT needs to be defined when calling _install_qt_logging_categories().") | ||
225 | endif() | ||||
226 | | ||||
227 | if(NOT DEFINED ARGS_MACRONAME) | ||||
228 | message(FATAL_ERROR "MACRONAME needs to be defined when calling _install_qt_logging_categories().") | ||||
140 | endif() | 229 | endif() | ||
141 | 230 | | |||
142 | set(_targetname "qt_logging_category_${ARGS_EXPORT}") | 231 | set(_targetname "qt_logging_category_${ARGS_EXPORT}") | ||
143 | if (NOT TARGET ${_targetname}) | 232 | if (NOT TARGET ${_targetname}) | ||
144 | message(FATAL_ERROR "${ARGS_EXPORT} is an unknown qt logging category export name.") | 233 | message(FATAL_ERROR "${ARGS_EXPORT} is an unknown qt logging category export name.") | ||
145 | endif() | 234 | endif() | ||
146 | 235 | | |||
147 | get_target_property(_categories ${_targetname} CATEGORIES) | 236 | get_target_property(_categories ${_targetname} CATEGORIES) | ||
148 | list(SORT _categories) | 237 | list(SORT _categories) | ||
149 | 238 | | |||
150 | set(_content | 239 | set(_content | ||
151 | "# KDebugSettings data file | 240 | "# KDebugSettings data file | ||
152 | # This file was generated by install_qt_logging_categories(). DO NOT EDIT! | 241 | # This file was generated by ${ARGS_MACRONAME}(). DO NOT EDIT! | ||
153 | 242 | | |||
154 | ") | 243 | ") | ||
155 | 244 | | |||
156 | foreach(_category IN LISTS _categories) | 245 | foreach(_category IN LISTS _categories) | ||
157 | get_target_property(_description ${_targetname} "DESCRIPTION_${_category}") | 246 | get_target_property(_description ${_targetname} "DESCRIPTION_${_category}") | ||
158 | 247 | | |||
159 | # Format: | 248 | # Format: | ||
160 | # logname<space>description | 249 | # logname<space>description | ||
Show All 14 Lines | 262 | file(GENERATE | |||
175 | CONTENT "${_content}" | 264 | CONTENT "${_content}" | ||
176 | ) | 265 | ) | ||
177 | 266 | | |||
178 | install( | 267 | install( | ||
179 | FILES "${ARGS_FILE}" | 268 | FILES "${ARGS_FILE}" | ||
180 | DESTINATION ${KDE_INSTALL_CONFDIR} | 269 | DESTINATION ${KDE_INSTALL_CONFDIR} | ||
181 | ) | 270 | ) | ||
182 | endfunction() | 271 | endfunction() | ||
272 | | ||||
273 | # install_qt_logging_categories(TYPE LIBRARY|APP_PLUGIN) | ||||
274 | # | ||||
275 | # Needs to be called after the last declare_qt_logging_category call for the same TYPE(s). | ||||
276 | function(install_qt_logging_categories) | ||||
277 | set(options ) | ||||
278 | set(oneValueArgs TYPE) | ||||
279 | set(multiValueArgs) | ||||
280 | | ||||
281 | cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||||
282 | | ||||
283 | if(NOT DEFINED ARGS_TYPE) | ||||
284 | message(FATAL_ERROR "TYPE needs to be defined when calling install_qt_logging_categories().") | ||||
285 | endif() | ||||
286 | | ||||
287 | if(ARGS_TYPE STREQUAL "LIBRARY") | ||||
Wouldn't it be better to just add the install call in the declare_*_qt_logging_category calls? This way we wouldn't need a magical function call in the root CMakeLists.txt file. apol: Wouldn't it be better to just add the install call in the declare_*_qt_logging_category calls? | |||||
Sadly does not work. As I told myself earlier before here: So the generation of the file has to be explicitly triggered, as we do not know which declare call is the last one. Hm, unless we just append a new line every time to the file, and do the principal creation on the first call. Will give that a try tonight, kossebau: Sadly does not work. As I told myself earlier before here:
"Reason is that the macros are all… | |||||
288 | _install_qt_logging_categories( | ||||
289 | EXPORT ${_platformlib_qt_logging_categories_export_name} | ||||
290 | FILE kdevplatform.categories | ||||
291 | MACRONAME install_qt_logging_categories | ||||
292 | ) | ||||
293 | elseif(ARGS_TYPE STREQUAL "APP_PLUGIN") | ||||
294 | _install_qt_logging_categories( | ||||
295 | EXPORT ${_app_plugin_qt_logging_categories_export_name} | ||||
296 | FILE kdevelop.categories | ||||
297 | MACRONAME install_qt_logging_categories | ||||
298 | ) | ||||
299 | else() | ||||
300 | message(FATAL_ERROR "Unknown \"${ARGS_TYPE}\" with TYPE when calling declare_qt_logging_category().") | ||||
301 | endif() | ||||
302 | endfunction() |
Way too much code duplication in all those declare_*_qt_logging_category calls, IMO... But I realize that if you want to keep _declare_qt_logging_category KDevelop-agnostic (for possible future upstreaming to ECM...) there's no way around this.
If you don't want to keep _declare_qt_logging_category KDevelop-agnostic you could add a TYPE argument to it and set some defaults for the different ARGS_* based on TYPE instead. Thinking this out further, we wouldn't even need different declare_*_qt_logging_categoryfunctions, but just use a declare_qt_logging_category function with a TYPE parameter directly. Just specifiy TYPE ... at the call-site in the individual CMakeLists.txt files...