1ECM-MODULES(7) Extra CMake Modules ECM-MODULES(7)
2
3
4
6 ecm-modules - ECM Modules Reference
7
9 Extra CMake Modules (ECM) provides various modules that provide useful
10 functions for CMake scripts. ECM actually provides three types of mod‐
11 ules that can be used from CMake scripts: those that extend the func‐
12 tionality of the find_package command are documented in ecm-find-mod‐
13 ules(7); those that provide standard settings for software produced by
14 the KDE community are documented in ecm-kde-modules(7). The rest pro‐
15 vide macros and functions for general use by CMake scripts and are doc‐
16 umented here.
17
18 To use these modules, you need to tell CMake to find the ECM package,
19 and then add either ${ECM_MODULE_PATH} or ${ECM_MODULE_DIR} to the
20 CMAKE_MODULE_PATH variable:
21
22 find_package(ECM REQUIRED NO_MODULE)
23 set(CMAKE_MODULE_PATH ${ECM_MODULE_DIR})
24
25 Using ${ECM_MODULE_PATH} will also make the find modules and KDE mod‐
26 ules available.
27
28 Note that there are also toolchain modules, documented in
29 ecm-toolchains(7), but these are used by users building the software
30 rather than developers writing CMake scripts.
31
33 ECMAddAppIcon
34 Add icons to executable files and packages.
35
36 ecm_add_app_icon(<sources_var>
37 ICONS <icon> [<icon> [...]]
38 [SIDEBAR_ICONS <icon> [<icon> [...]] # Since 5.49
39 [OUTFILE_BASENAME <name>]) # Since 5.49
40 )
41
42 The given icons, whose names must match the pattern:
43
44 <size>-<other_text>.png
45
46 will be added to the executable target whose sources are specified by
47 <sources_var> on platforms that support it (Windows and Mac OS X).
48 Other icon files are ignored but on Mac SVG files can be supported and
49 it is thus possible to mix those with png files in a single macro call.
50
51 <size> is a numeric pixel size (typically 16, 32, 48, 64, 128 or 256).
52 <other_text> can be any other text. See the platform notes below for
53 any recommendations about icon sizes.
54
55 SIDEBAR_ICONS can be used to add Mac OS X sidebar icons to the gener‐
56 ated iconset. They are used when a folder monitored by the application
57 is dragged into Finder’s sidebar. Since 5.49.
58
59 OUTFILE_BASENAME will be used as the basename for the icon file. If you
60 specify it, the icon file will be called <OUTFILE_BASENAME>.icns on Mac
61 OS X and <OUTFILE_BASENAME>.ico on Windows. If you don’t specify it, it
62 defaults to <sources_var>.<ext>. Since 5.49.
63
64 Windows notes
65
66 · Icons are compiled into the executable using a resource file.
67
68 · Icons may not show up in Windows Explorer if the executable
69 target does not have the WIN32_EXECUTABLE property set.
70
71 · Icotool (see FindIcoTool) is required.
72
73 · Supported sizes: 16, 24, 32, 48, 64, 128, 256, 512 and 1024.
74
75 Mac OS X notes
76
77 · The executable target must have the MACOSX_BUNDLE property
78 set.
79
80 · Icons are added to the bundle.
81
82 · If the ksvg2icns tool from KIconThemes is available, .svg and
83 .svgz files are accepted; the first that is converted success‐
84 fully to .icns will provide the application icon. SVG files
85 are ignored otherwise.
86
87 · The tool iconutil (provided by Apple) is required for bitmap
88 icons.
89
90 · Supported sizes: 16, 32, 64, 128, 256 (and 512, 1024 after OS
91 X 10.9).
92
93 · At least a 128x128px (or an SVG) icon is required.
94
95 · Larger sizes are automatically used to substitute for smaller
96 sizes on “Retina” (high-resolution) displays. For example, a
97 32px icon, if provided, will be used as a 32px icon on stan‐
98 dard-resolution displays, and as a 16px-equivalent icon (with
99 an “@2x” tag) on high-resolution displays. That is why you
100 should provide 64px and 1024px icons although they are not
101 supported anymore directly. Instead they will be used as
102 32px@2x and 512px@2x. ksvg2icns handles this internally.
103
104 · This function sets the MACOSX_BUNDLE_ICON_FILE variable to the
105 name of the generated icns file, so that it will be used as
106 the MACOSX_BUNDLE_ICON_FILE target property when you call
107 add_executable.
108
109 · Sidebar icons should typically provided in 16, 32, 64, 128 and
110 256px.
111
112 Since 1.7.0.
113
114 ECMAddQch
115 This module provides the ecm_add_qch function for generating API docu‐
116 mentation files in the QCH format, and the ecm_install_qch_export func‐
117 tion for generating and installing exported CMake targets for such gen‐
118 erated QCH files to enable builds of other software with generation of
119 QCH files to create links into the given QCH files.
120
121 ecm_add_qch(<target_name>
122 NAME <name>
123 VERSION <version>
124 QCH_INSTALL_DESTINATION <qchfile_install_path>
125 TAGFILE_INSTALL_DESTINATION <tagsfile_install_path>
126 [COMPONENT <component>]
127 [BASE_NAME <basename>]
128 [SOURCE_DIRS <dir> [<dir2> [...]]]
129 [SOURCES <file> [<file2> [...]]]
130 |MD_MAINPAGE <md_file>]
131 [INCLUDE_DIRS <incdir> [<incdir2> [...]]]
132 [IMAGE_DIRS <idir> [<idir2> [...]]]
133 [EXAMPLE_DIRS <edir> [<edir2> [...]]]
134 [ORG_DOMAIN <domain>]
135 [NAMESPACE <namespace>]
136 [LINK_QCHS <qch> [<qch2> [...]]]
137 [PREDEFINED_MACROS <macro[=content]> [<macro2[=content]> [...]]]
138 [BLANK_MACROS <macro> [<macro2> [...]]]
139 [CONFIG_TEMPLATE <configtemplate_file>]
140 [VERBOSE]
141 )
142
143 This macro adds a target called <target_name> for the creation of an
144 API documentation manual in the QCH format from the given sources. It
145 currently uses doxygen, future versions might optionally also allow
146 other tools. Next to the QCH file the target will generate a corre‐
147 sponding doxygen tag file, which enables creating links from other doc‐
148 umentation into the generated QCH file.
149
150 It is recommended to make the use of this macro optional, by depending
151 the call to ecm_add_qch on a CMake option being set, with a name like
152 BUILD_QCH and being TRUE by default. This will allow the developers to
153 saves resources on normal source development build cycles by setting
154 this option to FALSE.
155
156 The macro will set the target properties DOXYGEN_TAGFILE, QHP_NAMES‐
157 PACE, QHP_NAMESPACE_VERSIONED, QHP_VIRTUALFOLDER and LINK_QCHS to the
158 respective values, to allow other code access to them, e.g. the macro
159 ecm_install_qch_export. To enable the use of the target <target_name>
160 as item for LINK_QCHS in further ecm_add_qch calls in the current
161 build, additionally a target property DOXYGEN_TAGFILE_BUILD is set,
162 with the path of the created doxygen tag file in the build dir. If
163 existing, ecm_add_qch will use this property instead of DOXYGEN_TAGFILE
164 for access to the tags file.
165
166 NAME specifies the name for the generated documentation.
167
168 VERSION specifies the version of the library for which the documenta‐
169 tion is created.
170
171 BASE_NAME specifies the base name for the generated files. The default
172 basename is <name>.
173
174 SOURCE_DIRS specifies the dirs (incl. subdirs) with the source files
175 for which the API documentation should be generated. Dirs can be rela‐
176 tive to the current source dir. Dependencies to the files in the dirs
177 are not tracked currently, other than with the SOURCES argument. So do
178 not use for sources generated during the build. Needs to be used when
179 SOURCES or CONFIG_TEMPLATE are not used.
180
181 SOURCES specifies the source files for which the API documentation
182 should be generated. Needs to be used when SOURCE_DIRS or CONFIG_TEM‐
183 PLATE are not used.
184
185 MD_MAINPAGE specifies a file in Markdown format that should be used as
186 main page. This page will overrule any \mainpage command in the
187 included sources.
188
189 INCLUDE_DIRS specifies the dirs which should be searched for included
190 headers. Dirs can be relative to the current source dir. Since 5.63.
191
192 IMAGE_DIRS specifies the dirs which contain images that are included in
193 the documentation. Dirs can be relative to the current source dir.
194
195 EXAMPLE_DIRS specifies the dirs which contain examples that are
196 included in the documentation. Dirs can be relative to the current
197 source dir.
198
199 QCH_INSTALL_DESTINATION specifies where the generated QCH file will be
200 installed.
201
202 TAGFILE_INSTALL_DESTINATION specifies where the generated tag file will
203 be installed.
204
205 COMPONENT specifies the installation component name with which the
206 install rules for the generated QCH file and tag file are associated.
207
208 NAMESPACE can be used to set a custom namespace <namespace> of the gen‐
209 erated QCH file. The namepspace is used as the unique id by QHelpEngine
210 (cmp. https://doc.qt.io/qt-5/qthelpproject.html#namespace). The
211 default namespace is <domain>.<name>. Needs to be used when ORG_DOMAIN
212 is not used.
213
214 ORG_DOMAIN can be used to define the organization domain prefix for the
215 default namespace of the generated QCH file. Needs to be used when
216 NAMESPACE is not used.
217
218 LINK_QCHS specifies a list of other QCH targets which should be used
219 for creating references to API documentation of code in external
220 libraries. For each target <qch> in the list these target properties
221 are expected to be defined: DOXYGEN_TAGFILE, QHP_NAMESPACE and QHP_VIR‐
222 TUALFOLDER. If any of these is not existing, <qch> will be ignored.
223 Use the macro ecm_install_qch_export for exporting a target with these
224 properties with the CMake config of a library. Any target <qch> can
225 also be one created before in the same buildsystem by another call of
226 ecm_add_qch.
227
228 PREDEFINED_MACROS specifies a list of C/C++ macros which should be han‐
229 dled as given by the API dox generation tool. Examples are macros only
230 defined in generated files, so whose definition might be not available
231 to the tool.
232
233 BLANK_MACROS specifies a list of C/C++ macro names which should be
234 ignored by the API dox generation tool and handled as if they resolve
235 to empty strings. Examples are export macros only defined in generated
236 files, so whose definition might be not available to the tool.
237
238 CONFIG_TEMPLATE specifies a custom cmake template file for the config
239 file that is created to control the execution of the API dox generation
240 tool. The following CMake variables need to be used: ECM_QCH_DOXY‐
241 GEN_QHELPGENERATOR_EXECUTABLE, ECM_QCH_DOXYGEN_FILEPATH, ECM_QCH_DOXY‐
242 GEN_TAGFILE. The following CMake variables can be used: ECM_QCH_DOXY‐
243 GEN_PROJECTNAME, ECM_QCH_DOXYGEN_PROJECTVERSION, ECM_QCH_DOXYGEN_VIRTU‐
244 ALFOLDER, ECM_QCH_DOXYGEN_FULLNAMESPACE, ECM_QCH_DOXYGEN_TAGFILES,
245 ECM_QCH_DOXYGEN_WARN_LOGFILE, ECM_QCH_DOXYGEN_QUIET. There is no guar‐
246 antue that the other CMake variables currently used in the default con‐
247 fig file template will also be present with the same semantics in
248 future versions of this macro.
249
250 VERBOSE tells the API dox generation tool to be more verbose about its
251 activity.
252
253 The default config file for the API dox generation tool, so the one
254 when not using CONFIG_TEMPLATE, allows code to handle the case of being
255 processed by the tool by defining the C/C++ preprocessor macro K_DOXY‐
256 GEN when run (since v5.67.0). For backward-compatibility also the defi‐
257 nition DOXYGEN_SHOULD_SKIP_THIS is set, but its usage is deprecated.
258
259 Example usage:
260
261 ecm_add_qch(
262 MyLib_QCH
263 NAME MyLib
264 VERSION "0.42.0"
265 ORG_DOMAIN org.myorg
266 SOURCE_DIRS
267 src
268 LINK_QCHS
269 Qt5Core_QCH
270 Qt5Xml_QCH
271 Qt5Gui_QCH
272 Qt5Widgets_QCH
273 BLANK_MACROS
274 MyLib_EXPORT
275 MyLib_DEPRECATED
276 TAGFILE_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/tags
277 QCH_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/qch
278 COMPONENT Devel
279 )
280
281 Example usage (with two QCH files, second linking first):
282
283 ecm_add_qch(
284 MyLib_QCH
285 NAME MyLib
286 VERSION ${MyLib_VERSION}
287 ORG_DOMAIN org.myorg
288 SOURCES ${MyLib_PUBLIC_HEADERS}
289 MD_MAINPAGE src/mylib/README.md
290 LINK_QCHS Qt5Core_QCH
291 TAGFILE_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/tags
292 QCH_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/qch
293 COMPONENT Devel
294 )
295 ecm_add_qch(
296 MyOtherLib_QCH
297 NAME MyOtherLib
298 VERSION ${MyOtherLib_VERSION}
299 ORG_DOMAIN org.myorg
300 SOURCES ${MyOtherLib_PUBLIC_HEADERS}
301 MD_MAINPAGE src/myotherlib/README.md
302 LINK_QCHS Qt5Core_QCH MyLib_QCH
303 TAGFILE_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/tags
304 QCH_INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/docs/qch
305 COMPONENT Devel
306 )
307
308 ecm_install_qch_export(
309 TARGETS [<name> [<name2> [...]]]
310 FILE <file>
311 DESTINATION <dest>
312 [COMPONENT <component>]
313 )
314
315 This macro creates and installs a CMake file <file> which exports the
316 given QCH targets <name> etc., so they can be picked up by CMake-based
317 builds of other software that also generate QCH files (using
318 ecm_add_qch) and which should include links to the QCH files created by
319 the given targets. The installed CMake file <file> is expected to be
320 included by the CMake config file created for the software the related
321 QCH files are documenting.
322
323 TARGETS specifies the QCH targets which should be exported. If a target
324 does not exist or does not have all needed properties, a warning will
325 be generated and the target skipped. This behaviour might change in
326 future versions to result in a fail instead.
327
328 FILE specifies the name of the created CMake file, typically with a
329 .cmake extension.
330
331 DESTINATION specifies the directory on disk to which the file will be
332 installed. It usually is the same as the one where the CMake config
333 files for this software are installed.
334
335 COMPONENT specifies the installation component name with which the
336 install rule is associated.
337
338 Example usage:
339
340 ecm_install_qch_export(
341 TARGETS MyLib_QCH
342 FILE MyLibQCHTargets.cmake
343 DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/MyLib"
344 COMPONENT Devel
345 )
346
347 Since 5.36.0.
348
349 ECMAddQtDesignerPlugin
350 This module provides the ecm_add_qtdesignerplugin function for generat‐
351 ing Qt Designer plugins for custom widgets. Each of those widgets is
352 described using a second function ecm_qtdesignerplugin_widget.
353
354 ecm_add_qtdesignerplugin(<target_name>
355 NAME <name>
356 WIDGETS <widgetid> [<widgetid2> [...]]
357 LINK_LIBRARIES <lib> [<lib2> [...]]
358 INSTALL_DESTINATION <install_path>
359 [OUTPUT_NAME <output_name>]
360 [DEFAULT_GROUP <group>]
361 [DEFAULT_HEADER_CASE <SAME_CASE|LOWER_CASE|UPPER_CASE>]
362 [DEFAULT_HEADER_EXTENSION <header_extension>]
363 [DEFAULT_ICON_DIR <icon_dir>]
364 [INCLUDE_FILES <include_file> [<include_file2> [...]]]
365 [SOURCES <src> [<src2> [...]]]
366 [COMPONENT <component>]
367 )
368
369 NAME specifies the base name to use in the generated sources. The
370 default is <target_name>.
371
372 WIDGETS specifies the widgets the plugin should support. Each widget
373 has to be defined before by a call of ecm_qtdesignerplugin_widget with
374 the respective <widgetid>, in a scope including the current call.
375
376 LINK_LIBRARIES specifies the libraries to link against. This will be at
377 least the library providing the widget class(es).
378
379 INSTALL_DESTINATION specifies where the generated plugin binary will be
380 installed.
381
382 OUTPUT_NAME specifies the name of the plugin binary. The default is
383 “<target_name>”.
384
385 DEFAULT_GROUP specifies the default group in Qt Designer where the wid‐
386 gets will be placed. The default is “Custom”.
387
388 DEFAULT_HEADER_CASE specifies how the name of the header is derived
389 from the widget class name. The default is “LOWER_CASE”.
390
391 DEFAULT_HEADER_EXTENSION specifies what file name extension is used for
392 the header file derived from the class name. The default is “h”.
393
394 DEFAULT_ICON_DIR specifies what file name extension is used for the
395 header file derived from the class name. The default is “pics”.
396
397 INCLUDE_FILES specifies additional include files to include with the
398 generated source file. This can be needed for custom code used in ini‐
399 tializing or creating widgets.
400
401 SOURCES specifies additional source files to build the plugin from.
402 This can be needed to support custom code used in initializing or cre‐
403 ating widgets.
404
405 COMPONENT specifies the installation component name with which the
406 install rules for the generated plugin are associated.
407
408 ecm_qtdesignerplugin_widget(<widgetid>
409 [CLASS_NAME <class_name>]
410 [INCLUDE_FILE <include_file>]
411 [CONTAINER]
412 [ICON <iconfile>]
413 [TOOLTIP <tooltip>]
414 [WHATSTHIS <whatsthis>]
415 [GROUP <group>]
416 [CREATE_WIDGET_CODE_FROM_VARIABLE <create_widget_code_variable>]
417 [INITIALIZE_CODE_FROM_VARIABLE <initialize_code_variable]
418 [DOM_XML_FROM_VARIABLE <dom_xml_variable>]
419 [IMPL_CLASS_NAME <impl_class_name>]
420 [CONSTRUCTOR_ARGS_CODE <constructor_args_code>]
421 [CONSTRUCTOR_ARGS_CODE_FROM_VARIABLE <constructor_args_code_variable>]
422 )
423
424 CLASS_NAME specifies the name of the widget class, including names‐
425 paces. The default is “<widgetid>”.
426
427 INCLUDE_FILE specifies the include file to use for the class of this
428 widget. The default is derived from <class_name> as configured by the
429 DEFAULT_HEADER_* options of ecm_add_qtdesignerplugin, also replacing
430 any namespace separators with “/”.
431
432 CONTAINER specifies, if set, that this widget is a container for other
433 widgets.
434
435 ICON specifies the icon file to use as symbol for this widget. The
436 default is “{lowercased <class_name>}.png” in the default icons dir as
437 configured by the DEFAULT_ICON_DIR option of ecm_add_qtdesignerplugin,
438 if such a file exists.
439
440 TOOLTIP specifies the tooltip text to use for this widget. Default is
441 “<class_name> Widget”.
442
443 WHATSTHIS specifies the What’s-This text to use for this widget.
444 Defaults to the tooltip.
445
446 GROUP specifies the group in Qt Designer where the widget will be
447 placed. The default is set as configured by the DEFAULT_GROUP option
448 of ecm_add_qtdesignerplugin.
449
450 CREATE_WIDGET_CODE_FROM_VARIABLE specifies the variable to get from the
451 C++ code to use as factory code to create an instance of the widget,
452 for the override of QDesignerCustomWidgetInterface::createWidget(QWid‐
453 get* parent). The default is “return new <impl_class_name><construc‐
454 tor_args_code>;”.
455
456 INITIALIZE_CODE_FROM_VARIABLE specifies the variable to get from the
457 C++ code to use with the override of QDesignerCustomWidgetInter‐
458 face::initialize(QDesignerFormEditorInterface* core). The code has to
459 use the present class member m_initialized to track and update the
460 state. The default code simply sets m_initialized to true, if it was
461 not before.
462
463 DOM_XML_FROM_VARIABLE specifies the variable to get from the string to
464 use with the optional override of QDesignerCustomWidgetInter‐
465 face::domXml(). Default does not override.
466
467 IMPL_CLASS_NAME specifies the name of the widget class to use for the
468 widget instance with Qt Designer. The default is “<class_name>”.
469
470 CONSTRUCTOR_ARGS_CODE specifies the C++ code to use for the constructor
471 arguments with the default of CREATE_WIDGET_CODE_FROM_VARIABLE. Note
472 that the parentheses are required. The default is “(parent)”.
473
474 CONSTRUCTOR_ARGS_CODE_FROM_VARIABLE specifies the variable to get from
475 the C++ code instead of passing it directly via CONSTRUCTOR_ARGS_CODE.
476 This can be needed if the code is more complex and e.g. includes “;”
477 chars.
478
479 Example usage:
480
481 ecm_qtdesignerplugin_widget(FooWidget
482 TOOLTIP "Enables to browse foo."
483 GROUP "Views (Foo)"
484 )
485
486 set(BarWidget_CREATE_WIDGET_CODE
487 "
488 auto* widget = new BarWidget(parent);
489 widget->setBar("Example bar");
490 return widget;
491 ")
492
493 ecm_qtdesignerplugin_widget(BarWidget
494 TOOLTIP "Displays bars."
495 GROUP "Display (Foo)"
496 CREATE_WIDGET_CODE_FROM_VARIABLE BarWidget_CREATE_WIDGET_CODE
497 )
498
499 ecm_add_qtdesignerplugin(foowidgets
500 NAME FooWidgets
501 OUTPUT_NAME foo2widgets
502 WIDGETS
503 FooWidget
504 BarWidget
505 LINK_LIBRARIES
506 Foo::Widgets
507 INSTALL_DESTINATION "${KDE_INSTALL_QTPLUGINDIR}/designer"
508 COMPONENT Devel
509 )
510
511 Since 5.62.0.
512
513 ECMAddTests
514 Convenience functions for adding tests.
515
516 ecm_add_tests(<sources> LINK_LIBRARIES <library> [<library> [...]]
517 [NAME_PREFIX <prefix>]
518 [GUI]
519 [TARGET_NAMES_VAR <target_names_var>]
520 [TEST_NAMES_VAR <test_names_var>])
521
522 A convenience function for adding multiple tests, each consisting of a
523 single source file. For each file in <sources>, an executable target
524 will be created (the name of which will be the basename of the source
525 file). This will be linked against the libraries given with
526 LINK_LIBRARIES. Each executable will be added as a test with the same
527 name.
528
529 If NAME_PREFIX is given, this prefix will be prepended to the test
530 names, but not the target names. As a result, it will not prevent
531 clashes between tests with the same name in different parts of the
532 project, but it can be used to give an indication of where to look for
533 a failing test.
534
535 If the flag GUI is passed the test binaries will be GUI executables,
536 otherwise the resulting binaries will be console applications (regard‐
537 less of the value of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). Be
538 aware that this changes the executable entry point on Windows (although
539 some frameworks, such as Qt, abstract this difference away).
540
541 The TARGET_NAMES_VAR and TEST_NAMES_VAR arguments, if given, should
542 specify a variable name to receive the list of generated target and
543 test names, respectively. This makes it convenient to apply properties
544 to them as a whole, for example, using set_target_properties() or
545 set_tests_properties().
546
547 The generated target executables will have the effects of
548 ecm_mark_as_test() (from the ECMMarkAsTest module) applied to it.
549
550 ecm_add_test(<sources> LINK_LIBRARIES <library> [<library> [...]]
551 [TEST_NAME <name>]
552 [NAME_PREFIX <prefix>]
553 [GUI])
554
555 This is a single-test form of ecm_add_tests that allows multiple source
556 files to be used for a single test. If using multiple source files,
557 TEST_NAME must be given; this will be used for both the target and test
558 names (and, as with ecm_add_tests(), the NAME_PREFIX argument will be
559 prepended to the test name).
560
561 Since pre-1.0.0.
562
563 ECMCheckOutboundLicense
564 Assert that source file licenses are compatible with a desired outbound
565 license of a compiled binary artifact (e.g., library, plugin or appli‐
566 cation).
567
568 This module provides the ecm_check_outbound_license function that gen‐
569 erates unit tests for checking the compatibility of license statements.
570 The license statements in all tested files are required to be added by
571 using the SPDX marker SPDX-License-Identifier.
572
573 During the CMake configuration of the project, a temporary license bill
574 of materials (BOM) in SPDX format is generated by calling the REUSE
575 tool (see <https://reuse.software>). That BOM is parsed and license
576 computations based on an internal compatibility matrix are performed.
577
578 Preconditions for using this module:
579
580 · All tested input source files must contain the
581 SPDX-License-Identifier tag.
582
583 · Python3 must be available.
584
585 · The REUSE tool must be available, which generates the
586 bill-of-materials by running reuse spdx on the tested direc‐
587 tory.
588
589 When this module is included, a SKIP_LICENSE_TESTS option is added
590 (default OFF). Turning this option on skips the generation of license
591 tests, which might be convenient if licenses shall not be tested in all
592 build configurations.
593
594 ecm_check_outbound_license(LICENSES <outbound-licenses>
595 FILES <source-files>
596 [TEST_NAME <name>]
597 [WILL_FAIL])
598
599 This method adds a custom unit test to ensure the specified outbound
600 license to be compatible with the specified license headers. Note that
601 a convenient way is to use the CMake GLOB command of the FILE function.
602
603 LICENSES
604 List of one or multiple outbound license regarding which the
605 compatibility.INDENT 7.0
606 of the source code files shall be tested. Currently, the following
607 values
608
609 are supported (values are SPDX registry identifiers):
610
611 · MIT
612
613 · BSD-2-Clause
614
615 · BSD-3-Clause
616
617 · LGPL-2.0-only
618
619 · LGPL-2.1-only
620
621 · LGPL-3.0-only
622
623 · GPL-2.0-only
624
625 · GPL-3.0-only
626
627 FILES: List of source files that contain valid SPDX-License-Identifier
628 markers. The paths can be relative to the CMake file that gen‐
629 erates the test case or be absolute paths.
630
631 TEST_NAME
632 Optional parameter that defines the name of the generated test
633 case. If no name is defined, the relative path to the test
634 directory with appended license name is used. Every test has
635 licensecheck_ as prefix.
636
637 WILL_FAIL
638 Optional parameter that inverts the test result. This parameter
639 is usually only used for tests of the module.
640
641Since 5.75.0
642
643 ECMConfiguredInstall
644 Takes a list of files, runs configure_file on each and installs the
645 resultant configured files in the given location.
646
647 Any suffix of “.in” in the passed file names wil be stripped from the
648 file name at the installed location.
649
650 ecm_install_configured_files(
651 INPUT <file> [<file2> [...]]
652 DESTINATION <INSTALL_DIRECTORY>
653 [COPYONLY]
654 [ESCAPE_QUOTES]
655 [@ONLY]
656 [COMPONENT <component>])
657
658 Example usage:
659
660 ecm_install_configured_files(INPUT foo.txt.in DESTINATION ${KDE_INSTALL_DATADIR} @ONLY)
661
662 This wil install the file as foo.txt with any cmake variable replace‐
663 ments made into the data directory.
664
665 Since 5.73.0.
666
667 ECMCoverageOption
668 Allow users to easily enable GCov code coverage support.
669
670 Code coverage allows you to check how much of your codebase is covered
671 by your tests. This module makes it easy to build with support for
672 GCov.
673
674 When this module is included, a BUILD_COVERAGE option is added (default
675 OFF). Turning this option on enables GCC’s coverage instrumentation,
676 and links against libgcov.
677
678 Note that this will probably break the build if you are not using GCC.
679
680 Since 1.3.0.
681
682 ECMCreateQmFromPoFiles
683 WARNING:
684 This module is deprecated and will be removed by ECM 1.0. Use ECMPo‐
685 QmTools instead.
686
687 Generate QTranslator (.qm) catalogs from Gettext (.po) catalogs.
688
689 ecm_create_qm_from_po_files(PO_FILES <file1>... <fileN>
690 [CATALOG_NAME <catalog_name>]
691 [INSTALL_DESTINATION <install_destination>])
692
693 Creates the necessary rules to compile .po files into .qm files, and
694 install them.
695
696 The .qm files are installed in <install_destination>/<lang>/LC_MES‐
697 SAGES, where <install_destination> is the INSTALL_DESTINATION argument
698 and <lang> is extracted from the “Language” field inside the .po file.
699
700 INSTALL_DESTINATION defaults to ${LOCALE_INSTALL_DIR} if defined, oth‐
701 erwise it uses ${CMAKE_INSTALL_LOCALEDIR} if that is defined, otherwise
702 it uses share/locale.
703
704 CATALOG_NAME defines the name of the installed .qm files. If set, .qm
705 files will be installed as <catalog_name>.qm. If not set .qm files will
706 be named after the name of their source .po file.
707
708 Setting the catalog name is useful when all .po files for a target are
709 kept in a single source directory. For example, the “mylib” probject
710 might keep all its translations in a “po” directory, like this:
711
712 po/
713 es.po
714 fr.po
715
716 Without setting CATALOG_NAME, those .po will be turned into .qm and
717 installed as:
718
719 share/locale/fr/LC_MESSAGES/fr.qm
720 share/locale/es/LC_MESSAGES/es.qm
721
722 If CATALOG_NAME is set to “mylib”, they will be installed as:
723
724 share/locale/fr/LC_MESSAGES/mylib.qm
725 share/locale/es/LC_MESSAGES/mylib.qm
726
727 Which is what the loader created by ecm_create_qm_loader() expects.
728
729 ecm_create_qm_from_po_files() creates a “translation” target. This tar‐
730 get builds all .po files into .qm files.
731
732 ecm_create_qm_loader(<source_files_var> <catalog_name>)
733
734 ecm_create_qm_loader() generates a C++ file which ensures translations
735 are automatically loaded at startup. The path of the .cpp file is
736 appended to <source_files_var>. Typical usage is like:
737
738 set(mylib_SRCS foo.cpp bar.cpp)
739 ecm_create_qm_loader(mylib_SRCS mylib)
740 add_library(mylib ${mylib_SRCS})
741
742 This generates a C++ file which loads “mylib.qm” at startup, assuming
743 it has been installed by ecm_create_qm_from_po_files(), and compiles it
744 into mylib.
745
746 Since pre-1.0.0.
747
748 ECMEnableSanitizers
749 Enable compiler sanitizer flags.
750
751 The following sanitizers are supported:
752
753 · Address Sanitizer
754
755 · Memory Sanitizer
756
757 · Thread Sanitizer
758
759 · Leak Sanitizer
760
761 · Undefined Behaviour Sanitizer
762
763 All of them are implemented in Clang, depending on your version, and
764 there is an work in progress in GCC, where some of them are currently
765 implemented.
766
767 This module will check your current compiler version to see if it sup‐
768 ports the sanitizers that you want to enable
769
770 Usage
771 Simply add:
772
773 include(ECMEnableSanitizers)
774
775 to your CMakeLists.txt. Note that this module is included in KDECompil‐
776 erSettings, so projects using that module do not need to also include
777 this one.
778
779 The sanitizers are not enabled by default. Instead, you must set
780 ECM_ENABLE_SANITIZERS (either in your CMakeLists.txt or on the command
781 line) to a semicolon-separated list of sanitizers you wish to enable.
782 The options are:
783
784 · address
785
786 · memory
787
788 · thread
789
790 · leak
791
792 · undefined
793
794 · fuzzer
795
796 The sanitizers “address”, “memory” and “thread” are mutually exclusive.
797 You cannot enable two of them in the same build.
798
799 “leak” requires the “address” sanitizer.
800
801 NOTE:
802 To reduce the overhead induced by the instrumentation of the sani‐
803 tizers, it is advised to enable compiler optimizations (-O1 or
804 higher).
805
806 Example
807 This is an example of usage:
808
809 mkdir build
810 cd build
811 cmake -DECM_ENABLE_SANITIZERS='address;leak;undefined' ..
812
813 NOTE:
814 Most of the sanitizers will require Clang. To enable it, use:
815
816 -DCMAKE_CXX_COMPILER=clang++
817
818 Since 1.3.0.
819
820 ECMFindModuleHelpers
821 Helper macros for find modules: ecm_find_package_version_check(),
822 ecm_find_package_parse_components() and ecm_find_package_han‐
823 dle_library_components().
824
825 ecm_find_package_version_check(<name>)
826
827 Prints warnings if the CMake version or the project’s required CMake
828 version is older than that required by extra-cmake-modules.
829
830 ecm_find_package_parse_components(<name>
831 RESULT_VAR <variable>
832 KNOWN_COMPONENTS <component1> [<component2> [...]]
833 [SKIP_DEPENDENCY_HANDLING])
834
835 This macro will populate <variable> with a list of components found in
836 <name>_FIND_COMPONENTS, after checking that all those components are in
837 the list of KNOWN_COMPONENTS; if there are any unknown components, it
838 will print an error or warning (depending on the value of
839 <name>_FIND_REQUIRED) and call return().
840
841 The order of components in <variable> is guaranteed to match the order
842 they are listed in the KNOWN_COMPONENTS argument.
843
844 If SKIP_DEPENDENCY_HANDLING is not set, for each component the variable
845 <name>_<component>_component_deps will be checked for dependent compo‐
846 nents. If <component> is listed in <name>_FIND_COMPONENTS, then all
847 its (transitive) dependencies will also be added to <variable>.
848
849 ecm_find_package_handle_library_components(<name>
850 COMPONENTS <component> [<component> [...]]
851 [SKIP_DEPENDENCY_HANDLING])
852 [SKIP_PKG_CONFIG])
853
854 Creates an imported library target for each component. The operation
855 of this macro depends on the presence of a number of CMake variables.
856
857 The <name>_<component>_lib variable should contain the name of this
858 library, and <name>_<component>_header variable should contain the name
859 of a header file associated with it (whatever relative path is normally
860 passed to ‘#include’). <name>_<component>_header_subdir variable can be
861 used to specify which subdirectory of the include path the headers will
862 be found in. ecm_find_package_components() will then search for the
863 library and include directory (creating appropriate cache variables)
864 and create an imported library target named <name>::<component>.
865
866 Additional variables can be used to provide additional information:
867
868 If SKIP_PKG_CONFIG, the <name>_<component>_pkg_config variable is set,
869 and pkg-config is found, the pkg-config module given by <name>_<compo‐
870 nent>_pkg_config will be searched for and used to help locate the
871 library and header file. It will also be used to set <name>_<compo‐
872 nent>_VERSION.
873
874 Note that if version information is found via pkg-config, <name>_<com‐
875 ponent>_FIND_VERSION can be set to require a particular version for
876 each component.
877
878 If SKIP_DEPENDENCY_HANDLING is not set, the INTERFACE_LINK_LIBRARIES
879 property of the imported target for <component> will be set to contain
880 the imported targets for the components listed in <name>_<compo‐
881 nent>_component_deps. <component>_FOUND will also be set to false if
882 any of the compoments in <name>_<component>_component_deps are not
883 found. This requires the components in <name>_<component>_compo‐
884 nent_deps to be listed before <component> in the COMPONENTS argument.
885
886 The following variables will be set:
887
888 <name>_TARGETS
889 the imported targets
890
891 <name>_LIBRARIES
892 the found libraries
893
894 <name>_INCLUDE_DIRS
895 the combined required include directories for the components
896
897 <name>_DEFINITIONS
898 the “other” CFLAGS provided by pkg-config, if any
899
900 <name>_VERSION
901 the value of <name>_<component>_VERSION for the first component
902 that has this variable set (note that components are searched
903 for in the order they are passed to the macro), although if it
904 is already set, it will not be altered
905
906 Note that these variables are never cleared, so if ecm_find_pack‐
907 age_handle_library_components() is called multiple times with different
908 components (typically because of multiple find_package() calls) then
909 <name>_TARGETS, for example, will contain all the targets found in any
910 call (although no duplicates).
911
912 Since pre-1.0.0.
913
914 ECMGenerateDBusServiceFile
915 This module provides the ecm_generate_dbus_service_file function for
916 generating and installing a D-Bus service file.
917
918 ecm_generate_dbus_service_file(
919 NAME <service name>
920 EXECUTABLE <executable>
921 [SYSTEMD_SERVICE <systemd service>]
922 DESTINATION <install_path>
923 [RENAME <dbus service filename>] # Since 5.75
924 )
925
926 A D-Bus service file <service name>.service will be generated and
927 installed in the relevant D-Bus config location. This filename can be
928 customized with RENAME.
929
930 <executable> must be an absolute path to the installed service exe‐
931 cutable. When using it with KDEInstallDirs it needs to be the _FULL_
932 variant of the path variable.
933
934 Note: On Windows, the macro will only use the file name part of <exe‐
935 cutable> since D-Bus service executables are to be installed in the
936 same directory as the D-Bus daemon.
937
938 Optionally, a <systemd service> can be specified to launch the corre‐
939 sponding systemd service instead of the <executable> if the D-Bus dae‐
940 mon is started by systemd.
941
942 Example usage:
943
944 ecm_generate_dbus_service_file(
945 NAME org.kde.kded5
946 EXECUTABLE ${KDE_INSTALL_FULL_BINDIR}/kded5
947 DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR}
948 )
949
950 ecm_generate_dbus_service_file(
951 NAME org.kde.kded5
952 EXECUTABLE ${KDE_INSTALL_FULL_BINDIR}/kded5
953 SYSTEMD_SERVICE plasma-kded.service
954 DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR}
955 RENAME org.kde.daemon.service
956 )
957
958 Since 5.73.0.
959
960 ECMGenerateExportHeader
961 This module provides the ecm_generate_export_header function for gener‐
962 ating export macros for libraries with version-based control over visi‐
963 bility of and compiler warnings for deprecated API for the library
964 user, as well as over excluding deprecated API and their implementation
965 when building the library itself.
966
967 For preparing some values useful in the context it also provides a
968 function ecm_export_header_format_version.
969
970 ecm_generate_export_header(<library_target_name>
971 VERSION <version>
972 [BASE_NAME <base_name>]
973 [GROUP_BASE_NAME <group_base_name>]
974 [EXPORT_MACRO_NAME <export_macro_name>]
975 [EXPORT_FILE_NAME <export_file_name>]
976 [DEPRECATED_MACRO_NAME <deprecated_macro_name>]
977 [NO_EXPORT_MACRO_NAME <no_export_macro_name>]
978 [INCLUDE_GUARD_NAME <include_guard_name>]
979 [STATIC_DEFINE <static_define>]
980 [PREFIX_NAME <prefix_name>]
981 [DEPRECATED_BASE_VERSION <deprecated_base_version>]
982 [DEPRECATION_VERSIONS <deprecation_version> [<deprecation_version2> [...]]]
983 [EXCLUDE_DEPRECATED_BEFORE_AND_AT <exclude_deprecated_before_and_at_version>]
984 [NO_BUILD_SET_DEPRECATED_WARNINGS_SINCE]
985 [NO_DEFINITION_EXPORT_TO_BUILD_INTERFACE]
986 [CUSTOM_CONTENT_FROM_VARIABLE <variable>]
987 )
988
989 VERSION specifies the version of the library, given in the format
990 “<major>.<minor>.<patchlevel>”.
991
992 GROUP_BASE_NAME specifies the name to use for the macros defining
993 library group default values. If set, this will generate code support‐
994 ing <group_base_name>_NO_DEPRECATED_WARNINGS, <group_base_name>_DIS‐
995 ABLE_DEPRECATED_BEFORE_AND_AT, <group_base_name>_DEPRECATED_WARN‐
996 INGS_SINCE and <group_base_name>_NO_DEPRECATED (see below). If not
997 set, the generated code will ignore any such macros.
998
999 DEPRECATED_BASE_VERSION specifies the default version before and at
1000 which deprecated API is disabled. The default is the value of
1001 “<exclude_deprecated_before_and_at_version>” if set, or “<major>.0.0”,
1002 with <major> taken from <version>.
1003
1004 DEPRECATION_VERSIONS specifies versions in “<major>.<minor>” format in
1005 which API was declared deprecated. Any version used with the generated
1006 macro <prefix_name><base_name>_DEPRECATED_VERSION(major, minor, text)
1007 or <prefix_name><base_name>_DEPRECATED_VERSION_BELATED(major, minor,
1008 textmajor, textminor, text) needs to be listed here, otherwise the
1009 macro will fail to work.
1010
1011 EXCLUDE_DEPRECATED_BEFORE_AND_AT specifies the version for which all
1012 API deprecated before and at should be excluded from the build com‐
1013 pletely. Possible values are “0” (default), “CURRENT” (which resolves
1014 to <version>) and a version string in the format
1015 “<major>.<minor>.<patchlevel>”.
1016
1017 NO_BUILD_SET_DEPRECATED_WARNINGS_SINCE specifies that the definition
1018 <prefix_name><uppercase_base_name>_DEPRECATED_WARNINGS_SINCE will not
1019 be set for the library inside its own build, and thus will be defined
1020 by either explicit definition in the build system configuration or by
1021 the default value mechanism (see below). The default is that it is set
1022 for the build, to the version specified by EXCLUDE_DEPRE‐
1023 CATED_BEFORE_AND_AT, so no deprecation warnings are done for any own
1024 deprecated API used in the library implementation itself.
1025
1026 NO_DEFINITION_EXPORT_TO_BUILD_INTERFACE specifies that the definition
1027 <prefix_name><uppercase_base_name>_DISABLE_DEPRECATED_BEFORE_AND_AT
1028 will not be set in the public interface of the library inside its own
1029 build, and the same for the definition <prefix_name><upper‐
1030 case_base_name>_DEPRECATED_WARNINGS_SINCE (if not disabled by
1031 NO_BUILD_SET_DEPRECATED_WARNINGS_SINCE already). The default is that
1032 they are set, to the version specified by EXCLUDE_DEPRE‐
1033 CATED_BEFORE_AND_AT, so e.g. test and examples part of the project
1034 automatically build against the full API included in the build and
1035 without any deprecation warnings for it.
1036
1037 The function ecm_generate_export_header defines C++ preprocessor macros
1038 in the generated export header, some for use in the sources of the
1039 library the header is generated for, other for use by projects linking
1040 agsinst the library.
1041
1042 The macros for use in the library C++ sources are these, next to those
1043 also defined by GenerateExportHeader:
1044
1045 <prefix_name><uppercase_base_name>_DEPRECATED_VERSION(major, minor,
1046 text)
1047 to use to conditionally set a <prefix_name><upper‐
1048 case_base_name>_DEPRECATED macro for a class, struct or function
1049 (other elements to be supported in future versions), depending
1050 on the visibility macro flags set (see below)
1051
1052 <prefix_name><uppercase_base_name>_DEPRECATED_VERSION_BELATED(major,
1053 minor, textmajor, textminor, text)
1054 to use to conditionally set a <prefix_name><upper‐
1055 case_base_name>_DEPRECATED macro for a class, struct or function
1056 (other elements to be supported in future versions), depending
1057 on the visibility macro flags set (see below), with major &
1058 minor applied for the logic and textmajor & textminor for the
1059 warnings message. Useful for retroactive tagging of API for the
1060 compiler without injecting the API into the compiler warning
1061 conditions of already released versions. Since 5.71.
1062
1063 <prefix_name><uppercase_base_name>_ENABLE_DEPRECATED_SINCE(major,
1064 minor)
1065 evaluates to TRUE or FALSE depending on the visibility macro
1066 flags set (see below). To be used mainly with #if/#endif to mark
1067 sections of code which should be included depending on the visi‐
1068 bility requested.
1069
1070 <prefix_name><uppercase_base_name>_BUILD_DEPRECATED_SINCE(major, minor)
1071 evaluates to TRUE or FALSE depending on the value of
1072 EXCLUDE_DEPRECATED_BEFORE_AND_AT. To be used mainly with
1073 #if/#endif to mark sections of two types of code: implementation
1074 code for deprecated API and declaration code of deprecated API
1075 which only may be disabled at build time of the library for BC
1076 reasons (e.g. virtual methods, see notes below).
1077
1078 <prefix_name><uppercase_base_name>_EXCLUDE_DEPRECATED_BEFORE_AND_AT
1079 holds the version used to exclude deprecated API at build time
1080 of the library.
1081
1082 The macros used to control visibility when building against the library
1083 are:
1084
1085 <prefix_name><uppercase_base_name>_DISABLE_DEPRECATED_BEFORE_AND_AT
1086 definition to set to a value in single hex number version nota‐
1087 tion (0x<major><minor><patchlevel>).
1088
1089 <prefix_name><uppercase_base_name>_NO_DEPRECATED
1090 flag to define to disable all deprecated API, being a shortcut
1091 for settings <prefix_name><uppercase_base_name>_DISABLE_DEPRE‐
1092 CATED_BEFORE_AND_AT to the current version. If both are set,
1093 this flag overrules.
1094
1095 <prefix_name><uppercase_base_name>_DEPRECATED_WARNINGS_SINCE
1096 definition to set to a value in single hex number version nota‐
1097 tion (0x<major><minor><patchlevel>). Warnings will be only acti‐
1098 vated for API deprecated up to and including the version. If
1099 <prefix_name><uppercase_base_name>_DISABLE_DEPRE‐
1100 CATED_BEFORE_AND_AT is set (directly or via the group default),
1101 it will default to that version, resulting in no warnings. Oth‐
1102 erwise the default is the current version, resulting in warnings
1103 for all deprecated API.
1104
1105 <prefix_name><uppercase_base_name>_NO_DEPRECATED_WARNINGS
1106 flag to define to disable all deprecation warnings, being a
1107 shortcut for setting <prefix_name><uppercase_base_name>_DEPRE‐
1108 CATED_WARNINGS_SINCE to “0”. If both are set, this flag over‐
1109 rules.
1110
1111 When the GROUP_BASE_NAME has been used, the same macros but with the
1112 given <group_base_name> prefix are available to define the defaults of
1113 these macros, if not explicitly set.
1114
1115 Note: The tricks applied here for hiding deprecated API to the compiler
1116 when building against a library do not work for all deprecated API:
1117
1118 · virtual methods need to stay visible to the compiler to build proper
1119 virtual method tables for subclasses
1120
1121 · enumerators from enums cannot be simply removed, as this changes auto
1122 values of following enumerators, also can poke holes in enumerator
1123 series used as index into tables
1124
1125 In such cases the API can be only “hidden” at build time of the
1126 library, itself, by generated hard coded macro settings, using <pre‐
1127 fix_name><uppercase_base_name>_BUILD_DEPRECATED_SINCE(major, minor).
1128
1129 Examples:
1130
1131 Preparing a library “Foo” created by target “foo”, which is part of a
1132 group of libraries “Bar”, where some API of “Foo” got deprecated at
1133 versions 5.0 & 5.12:
1134
1135 ecm_generate_export_header(foo
1136 GROUP_BASE_NAME BAR
1137 VERSION ${FOO_VERSION}
1138 DEPRECATION_VERSIONS 5.0 5.12
1139 )
1140
1141 In the library “Foo” sources in the headers the API would be prepared
1142 like this, using the generated macros FOO_ENABLE_DEPRECATED_SINCE and
1143 FOO_DEPRECATED_VERSION:
1144
1145 #include <foo_export.h>
1146
1147 #if FOO_ENABLE_DEPRECATED_SINCE(5, 0)
1148 /**
1149 * @deprecated Since 5.0
1150 */
1151 FOO_DEPRECATED_VERSION(5, 0, "Use doFoo2()")
1152 FOO_EXPORT void doFoo();
1153 #endif
1154
1155 #if FOO_ENABLE_DEPRECATED_SINCE(5, 12)
1156 /**
1157 * @deprecated Since 5.12
1158 */
1159 FOO_DEPRECATED_VERSION(5, 12, "Use doBar2()")
1160 FOO_EXPORT void doBar();
1161 #endif
1162
1163 Projects linking against the “Foo” library can control which part of
1164 its deprecated API should be hidden to the compiler by adding a defini‐
1165 tion using the FOO_DISABLE_DEPRECATED_BEFORE_AND_AT macro variable set
1166 to the desired value (in version hex number notation):
1167
1168 add_definitions(-DFOO_DISABLE_DEPRECATED_BEFORE_AND_AT=0x050000)
1169
1170 Or using the macro variable of the group:
1171
1172 add_definitions(-DBAR_DISABLE_DEPRECATED_BEFORE_AND_AT=0x050000)
1173
1174 If both are specified, FOO_DISABLE_DEPRECATED_BEFORE_AND_AT will take
1175 precedence.
1176
1177 To build a variant of a library with some deprecated API completely
1178 left out from the build, not only optionally invisible to consumers,
1179 one uses the EXCLUDE_DEPRECATED_BEFORE_AND_AT parameter. This is best
1180 combined with a cached CMake variable.
1181
1182 set(EXCLUDE_DEPRECATED_BEFORE_AND_AT 0 CACHE STRING "Control the range of deprecated API excluded from the build [default=0].")
1183
1184 ecm_generate_export_header(foo
1185 VERSION ${FOO_VERSION}
1186 EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
1187 DEPRECATION_VERSIONS 5.0 5.12
1188 )
1189
1190 The macros used in the headers for library consumers are reused for
1191 disabling the API excluded in the build of the library. For disabling
1192 the implementation of that API as well as for disabling deprecated API
1193 which only can be disabled at build time of the library for BC reasons,
1194 one uses the generated macro FOO_BUILD_DEPRECATED_SINCE, like this:
1195
1196 #include <foo_export.h>
1197
1198 enum Bars {
1199 One,
1200 #if FOO_BUILD_DEPRECATED_SINCE(5, 0)
1201 Two,
1202 #endif
1203 Three,
1204 };
1205
1206 #if FOO_ENABLE_DEPRECATED_SINCE(5, 0)
1207 /**
1208 * @deprecated Since 5.0
1209 */
1210 FOO_DEPRECATED_VERSION(5, 0, "Use doFoo2()")
1211 FOO_EXPORT void doFoo();
1212 #endif
1213
1214 #if FOO_ENABLE_DEPRECATED_SINCE(5, 12)
1215 /**
1216 * @deprecated Since 5.12
1217 */
1218 FOO_DEPRECATED_VERSION(5, 12, "Use doBar2()")
1219 FOO_EXPORT void doBar();
1220 #endif
1221
1222 class FOO_EXPORT Foo {
1223 public:
1224 #if FOO_BUILD_DEPRECATED_SINCE(5, 0)
1225 /**
1226 * @deprecated Since 5.0
1227 */
1228 FOO_DEPRECATED_VERSION(5, 0, "Feature removed")
1229 virtual void doWhat();
1230 #endif
1231 };
1232
1233 #if FOO_BUILD_DEPRECATED_SINCE(5, 0)
1234 void doFoo()
1235 {
1236 // [...]
1237 }
1238 #endif
1239
1240 #if FOO_BUILD_DEPRECATED_SINCE(5, 12)
1241 void doBar()
1242 {
1243 // [...]
1244 }
1245 #endif
1246
1247 #if FOO_BUILD_DEPRECATED_SINCE(5, 0)
1248 void Foo::doWhat()
1249 {
1250 // [...]
1251 }
1252 #endif
1253
1254 So e.g. if EXCLUDE_DEPRECATED_BEFORE_AND_AT is set to “5.0.0”, the enu‐
1255 merator Two as well as the methods ::doFoo() and Foo::doWhat() will be
1256 not available to library consumers. The methods will not have been com‐
1257 piled into the library binary, and the declarations will be hidden to
1258 the compiler, FOO_DISABLE_DEPRECATED_BEFORE_AND_AT also cannot be used
1259 to reactivate them.
1260
1261 When using the NO_DEFINITION_EXPORT_TO_BUILD_INTERFACE and the project
1262 for the “Foo” library includes also tests and examples linking against
1263 the library and using deprecated API (like tests covering it), one bet‐
1264 ter explicitly sets FOO_DISABLE_DEPRECATED_BEFORE_AND_AT for those tar‐
1265 gets to the version before and at which all deprecated API has been
1266 excluded from the build. Even more when building against other
1267 libraries from the same group “Bar” and disabling some deprecated API
1268 of those libraries using the group macro BAR_DISABLE_DEPRE‐
1269 CATED_BEFORE_AND_AT, which also works as default for FOO_DISABLE_DEPRE‐
1270 CATED_BEFORE_AND_AT.
1271
1272 To get the hex number style value the helper macro
1273 ecm_export_header_format_version() will be used:
1274
1275 set(EXCLUDE_DEPRECATED_BEFORE_AND_AT 0 CACHE STRING "Control what part of deprecated API is excluded from build [default=0].")
1276
1277 ecm_generate_export_header(foo
1278 VERSION ${FOO_VERSION}
1279 GROUP_BASE_NAME BAR
1280 EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
1281 NO_DEFINITION_EXPORT_TO_BUILD_INTERFACE
1282 DEPRECATION_VERSIONS 5.0 5.12
1283 )
1284
1285 ecm_export_header_format_version(${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
1286 CURRENT_VERSION ${FOO_VERSION}
1287 HEXNUMBER_VAR foo_no_deprecated_before_and_at
1288 )
1289
1290 # disable all deprecated API up to 5.9.0 from all other libs of group "BAR" that we use ourselves
1291 add_definitions(-DBAR_DISABLE_DEPRECATED_BEFORE_AND_AT=0x050900)
1292
1293 add_executable(app app.cpp)
1294 target_link_libraries(app foo)
1295 target_compile_definitions(app
1296 PRIVATE "FOO_DISABLE_DEPRECATED_BEFORE_AND_AT=${foo_no_deprecated_before_and_at}")
1297
1298 Since 5.64.0.
1299
1300 ECMGenerateHeaders
1301 Generate C/C++ CamelCase forwarding headers.
1302
1303 ecm_generate_headers(<camelcase_forwarding_headers_var>
1304 HEADER_NAMES <CamelCaseName> [<CamelCaseName> [...]]
1305 [ORIGINAL <CAMELCASE|LOWERCASE>]
1306 [HEADER_EXTENSION <header_extension>]
1307 [OUTPUT_DIR <output_dir>]
1308 [PREFIX <prefix>]
1309 [REQUIRED_HEADERS <variable>]
1310 [COMMON_HEADER <HeaderName>]
1311 [RELATIVE <relative_path>])
1312
1313 For each CamelCase header name passed to HEADER_NAMES, a file of that
1314 name will be generated that will include a version with .h or, if set,
1315 .<header_extension> appended. For example, the generated header ClassA
1316 will include classa.h (or ClassA.h, see ORIGINAL). If a CamelCaseName
1317 consists of multiple comma-separated files, e.g. ClassA,ClassB,ClassC,
1318 then multiple camelcase header files will be generated which are redi‐
1319 rects to the first header file. The file locations of these generated
1320 headers will be stored in <camelcase_forwarding_headers_var>.
1321
1322 ORIGINAL specifies how the name of the original header is written: low‐
1323 ercased or also camelcased. The default is LOWERCASE. Since 1.8.0.
1324
1325 HEADER_EXTENSION specifies what file name extension is used for the
1326 header files. The default is “h”. Since 5.48.0.
1327
1328 PREFIX places the generated headers in subdirectories. This should be
1329 a CamelCase name like KParts, which will cause the CamelCase forwarding
1330 headers to be placed in the KParts directory (e.g. KParts/Part). It
1331 will also, for the convenience of code in the source distribution, gen‐
1332 erate forwarding headers based on the original names (e.g.
1333 kparts/part.h). This allows includes like "#include <kparts/part.h>"
1334 to be used before installation, as long as the include_directories are
1335 set appropriately.
1336
1337 OUTPUT_DIR specifies where the files will be generated; this should be
1338 within the build directory. By default, ${CMAKE_CURRENT_BINARY_DIR}
1339 will be used. This option can be used to avoid file conflicts.
1340
1341 REQUIRED_HEADERS specifies an output variable name where all the
1342 required headers will be appended so that they can be installed
1343 together with the generated ones. This is mostly intended as a conve‐
1344 nience so that adding a new header to a project only requires specify‐
1345 ing the CamelCase variant in the CMakeLists.txt file; the original
1346 variant will then be added to this variable.
1347
1348 COMMON_HEADER generates an additional convenience header which includes
1349 all other header files.
1350
1351 The RELATIVE argument indicates where the original headers can be found
1352 relative to CMAKE_CURRENT_SOURCE_DIR. It does not affect the generated
1353 CamelCase forwarding files, but ecm_generate_headers() uses it when
1354 checking that the original header exists, and to generate originally
1355 named forwarding headers when PREFIX is set.
1356
1357 To allow other parts of the source distribution (eg: tests) to use the
1358 generated headers before installation, it may be desirable to set the
1359 INCLUDE_DIRECTORIES property for the library target to output_dir. For
1360 example, if OUTPUT_DIR is CMAKE_CURRENT_BINARY_DIR (the default), you
1361 could do
1362
1363 target_include_directories(MyLib PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
1364
1365 Example usage (without PREFIX):
1366
1367 ecm_generate_headers(
1368 MyLib_FORWARDING_HEADERS
1369 HEADERS
1370 MLFoo
1371 MLBar
1372 # etc
1373 REQUIRED_HEADERS MyLib_HEADERS
1374 COMMON_HEADER MLGeneral
1375 )
1376 install(FILES ${MyLib_FORWARDING_HEADERS} ${MyLib_HEADERS}
1377 DESTINATION ${CMAKE_INSTALL_PREFIX}/include
1378 COMPONENT Devel)
1379
1380 Example usage (with PREFIX):
1381
1382 ecm_generate_headers(
1383 MyLib_FORWARDING_HEADERS
1384 HEADERS
1385 Foo
1386 # several classes are contained in bar.h, so generate
1387 # additional files
1388 Bar,BarList
1389 # etc
1390 PREFIX MyLib
1391 REQUIRED_HEADERS MyLib_HEADERS
1392 )
1393 install(FILES ${MyLib_FORWARDING_HEADERS}
1394 DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MyLib
1395 COMPONENT Devel)
1396 install(FILES ${MyLib_HEADERS}
1397 DESTINATION ${CMAKE_INSTALL_PREFIX}/include/mylib
1398 COMPONENT Devel)
1399
1400 Since pre-1.0.0.
1401
1402 ECMGeneratePkgConfigFile
1403 Generate a pkg-config file for the benefit of autotools-based projects.
1404
1405 ecm_generate_pkgconfig_file(BASE_NAME <baseName>
1406 [LIB_NAME <libName>]
1407 [DEPS "<dep> [<dep> [...]]"]
1408 [FILENAME_VAR <filename_variable>]
1409 [INCLUDE_INSTALL_DIR <dir>]
1410 [LIB_INSTALL_DIR <dir>]
1411 [DEFINES -D<variable=value>...]
1412 [DESCRIPTION <library description>] # since 5.41.0
1413 [INSTALL])
1414
1415 BASE_NAME is the name of the module. It’s the name projects will use to
1416 find the module.
1417
1418 LIB_NAME is the name of the library that is being exported. If unde‐
1419 fined, it will default to the BASE_NAME. That means the LIB_NAME will
1420 be set as the name field as well as the library to link to.
1421
1422 FILENAME_VAR is specified with a variable name. This variable will
1423 receive the location of the generated file will be set, within the
1424 build directory. This way it can be used in case some processing is
1425 required. See also INSTALL.
1426
1427 INCLUDE_INSTALL_DIR specifies where the includes will be installed. If
1428 it’s not specified, it will default to INSTALL_INCLUDEDIR,
1429 CMAKE_INSTALL_INCLUDEDIR or just “include/” in case they are specified,
1430 with the BASE_NAME postfixed.
1431
1432 LIB_INSTALL_DIR specifies where the library is being installed. If it’s
1433 not specified, it will default to LIB_INSTALL_DIR, CMAKE_INSTALL_LIBDIR
1434 or just “lib/” in case they are specified.
1435
1436 DEFINES is a list of preprocessor defines that it is recommended users
1437 of the library pass to the compiler when using it.
1438
1439 DESCRIPTION describes what this library is. If it’s not specified,
1440 CMake will first try to get the description from the metainfo.yaml file
1441 or will create one based on LIB_NAME. Since 5.41.0.
1442
1443 INSTALL will cause the module to be installed to the pkgconfig subdi‐
1444 rectory of LIB_INSTALL_DIR, unless the ECM_PKGCONFIG_INSTALL_DIR cache
1445 variable is set to something different. Note that the first call to
1446 ecm_generate_pkgconfig_file with the INSTALL argument will cause
1447 ECM_PKGCONFIG_INSTALL_DIR to be set to the cache, and will be used in
1448 any subsequent calls.
1449
1450 To properly use this macro a version needs to be set. To retrieve it,
1451 ECM_PKGCONFIG_INSTALL_DIR uses PROJECT_VERSION. To set it, use the
1452 project() command (only available since CMake 3.0) or the ecm_set‐
1453 up_version() macro.
1454
1455 Example usage:
1456
1457 ecm_generate_pkgconfig_file(
1458 BASE_NAME KF5Archive
1459 DEPS Qt5Core
1460 FILENAME_VAR pkgconfig_filename
1461 INSTALL
1462 )
1463
1464 Since 1.3.0.
1465
1466 ECMGeneratePriFile
1467 Generate a .pri file for the benefit of qmake-based projects.
1468
1469 As well as the function below, this module creates the cache variable
1470 ECM_MKSPECS_INSTALL_DIR and sets the default value to mkspecs/modules.
1471 This assumes Qt and the current project are both installed to the same
1472 non-system prefix. Packagers who use -DCMAKE_INSTALL_PREFIX=/usr will
1473 certainly want to set ECM_MKSPECS_INSTALL_DIR to something like
1474 share/qt5/mkspecs/modules.
1475
1476 The main thing is that this should be the modules subdirectory of
1477 either the default qmake mkspecs directory or of a directory that will
1478 be in the $QMAKEPATH environment variable when qmake is run.
1479
1480 ecm_generate_pri_file(BASE_NAME <baseName>
1481 LIB_NAME <libName>
1482 [DEPS "<dep> [<dep> [...]]"]
1483 [FILENAME_VAR <filename_variable>]
1484 [INCLUDE_INSTALL_DIR <dir>]
1485 [LIB_INSTALL_DIR <dir>])
1486
1487 If your CMake project produces a Qt-based library, you may expect there
1488 to be applications that wish to use it that use a qmake-based build
1489 system, rather than a CMake-based one. Creating a .pri file will make
1490 use of your library convenient for them, in much the same way that
1491 CMake config files make things convenient for CMake-based applications.
1492
1493 ecm_generate_pri_file() generates just such a file. It requires the
1494 PROJECT_VERSION_STRING variable to be set. This is typically set by
1495 ECMSetupVersion, although the project() command in CMake 3.0.0 and
1496 later can also set this.
1497
1498 BASE_NAME specifies the name qmake project (.pro) files should use to
1499 refer to the library (eg: KArchive). LIB_NAME is the name of the
1500 actual library to link to (ie: the first argument to add_library()).
1501 DEPS is a space-separated list of the base names of other libraries
1502 (for Qt libraries, use the same names you use with the QT variable in a
1503 qmake project file, such as “core” for QtCore). FILENAME_VAR specifies
1504 the name of a variable to store the path to the generated file in.
1505
1506 INCLUDE_INSTALL_DIR is the path (relative to CMAKE_INSTALL_PREFIX) that
1507 include files will be installed to. It defaults to
1508 ${INCLUDE_INSTALL_DIR}/<baseName> if the INCLUDE_INSTALL_DIR variable
1509 is set. If that variable is not set, the CMAKE_INSTALL_INCLUDEDIR vari‐
1510 able is used instead, and if neither are set include is used.
1511 LIB_INSTALL_DIR operates similarly for the installation location for
1512 libraries; it defaults to ${LIB_INSTALL_DIR}, ${CMAKE_INSTALL_LIBDIR}
1513 or lib, in that order.
1514
1515 Example usage:
1516
1517 ecm_generate_pri_file(
1518 BASE_NAME KArchive
1519 LIB_NAME KF5KArchive
1520 DEPS "core"
1521 FILENAME_VAR pri_filename
1522 )
1523 install(FILES ${pri_filename} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
1524
1525 A qmake-based project that wished to use this would then do:
1526
1527 QT += KArchive
1528
1529 in their .pro file.
1530
1531 Since pre-1.0.0.
1532
1533 ECMGenerateQmlTypes
1534 Generates plugins.qmltypes files for QML plugins.
1535
1536 ecm_generate_qmltypes(<org.kde.pluginname> 1.3
1537 DESTINATION <${KDE_INSTALL_QMLDIR}/org/kde/pluginname>)
1538
1539 Makes it possible to generate plugins.qmltypes files for the QML plug‐
1540 ins that our project offers. These files offer introspection upon our
1541 plugin and are useful for integrating with IDE language support of our
1542 plugin. It offers information about the objects its methods and their
1543 argument types.
1544
1545 The developer will be in charge of making sure that these files are up
1546 to date. The plugin.qmltypes file will sit in the source directory.
1547 This function will include the code that installs the file in the right
1548 place and a small unit test named qmltypes-pluginname-version that
1549 makes sure that it doesn’t need updating.
1550
1551 Since 5.33.0
1552
1553 ECMInstallIcons
1554 Installs icons, sorting them into the correct directories according to
1555 the FreeDesktop.org icon naming specification.
1556
1557 ecm_install_icons(ICONS <icon> [<icon> [...]]
1558 DESTINATION <icon_install_dir>
1559 [LANG <l10n_code>]
1560 [THEME <theme>])
1561
1562 The given icons, whose names must match the pattern:
1563
1564 <size>-<group>-<name>.<ext>
1565
1566 will be installed to the appropriate subdirectory of DESTINATION
1567 according to the FreeDesktop.org icon naming scheme. By default, they
1568 are installed to the “hicolor” theme, but this can be changed using the
1569 THEME argument. If the icons are localized, the LANG argument can be
1570 used to install them in a locale-specific directory.
1571
1572 <size> is a numeric pixel size (typically 16, 22, 32, 48, 64, 128 or
1573 256) or sc for scalable (SVG) files, <group> is one of the standard
1574 FreeDesktop.org icon groups (actions, animations, apps, categories,
1575 devices, emblems, emotes, intl, mimetypes, places, status) and <ext> is
1576 one of .png, .mng or .svgz.
1577
1578 The typical installation directory is share/icons.
1579
1580 ecm_install_icons(ICONS 22-actions-menu_new.png
1581 DESTINATION share/icons)
1582
1583 The above code will install the file 22-actions-menu_new.png as
1584 ${CMAKE_INSTALL_PREFIX}/share/icons/<theme>/22x22/actions/menu_new.png
1585
1586 Users of the KDEInstallDirs module would normally use
1587 ${KDE_INSTALL_ICONDIR} as the DESTINATION, while users of the GNUIn‐
1588 stallDirs module should use ${CMAKE_INSTALL_DATAROOTDIR}/icons.
1589
1590 An old form of arguments will also be accepted:
1591
1592 ecm_install_icons(<icon_install_dir> [<l10n_code>])
1593
1594 This matches files named like:
1595
1596 <theme><size>-<group>-<name>.<ext>
1597
1598 where <theme> is one of
1599
1600 · hi for hicolor
1601
1602 · lo for locolor
1603
1604 · cr for the Crystal icon theme
1605
1606 · ox for the Oxygen icon theme
1607
1608 · br for the Breeze icon theme
1609
1610 With this syntax, the file hi22-actions-menu_new.png would be installed
1611 into <icon_install_dir>/hicolor/22x22/actions/menu_new.png
1612
1613 Since pre-1.0.0.
1614
1615 ECMMarkAsTest
1616 Marks a target as only being required for tests.
1617
1618 ecm_mark_as_test(<target1> [<target2> [...]])
1619
1620 This will cause the specified targets to not be built unless either
1621 BUILD_TESTING is set to ON or the user invokes the buildtests target.
1622
1623 BUILD_TESTING is created as a cache variable by the CTest module and by
1624 the KDECMakeSettings module.
1625
1626 Since pre-1.0.0.
1627
1628 ECMMarkNonGuiExecutable
1629 Marks an executable target as not being a GUI application.
1630
1631 ecm_mark_nongui_executable(<target1> [<target2> [...]])
1632
1633 This will indicate to CMake that the specified targets should not be
1634 included in a MACOSX_BUNDLE and should not be WIN32_EXECUTABLEs. On
1635 platforms other than MacOS X or Windows, this will have no effect.
1636
1637 Since pre-1.0.0.
1638
1639 ECMOptionalAddSubdirectory
1640 Make subdirectories optional.
1641
1642 ecm_optional_add_subdirectory(<dir>)
1643
1644 This behaves like add_subdirectory(), except that it does not complain
1645 if the directory does not exist. Additionally, if the directory does
1646 exist, it creates an option to allow the user to skip it. The option
1647 will be named BUILD_<dir>.
1648
1649 This is useful for “meta-projects” that combine several mostly-indepen‐
1650 dent sub-projects.
1651
1652 If the CMake variable DISABLE_ALL_OPTIONAL_SUBDIRECTORIES is set to
1653 TRUE for the first CMake run on the project, all optional subdirecto‐
1654 ries will be disabled by default (but can of course be enabled via the
1655 respective options). For example, the following will disable all
1656 optional subdirectories except the one named “foo”:
1657
1658 cmake -DDISABLE_ALL_OPTIONAL_SUBDIRECTORIES=TRUE -DBUILD_foo=TRUE myproject
1659
1660 Since pre-1.0.0.
1661
1662 ECMPackageConfigHelpers
1663 Helper macros for generating CMake package config files.
1664
1665 write_basic_package_version_file() is the same as the one provided by
1666 the CMakePackageConfigHelpers module in CMake; see that module’s docu‐
1667 mentation for more information.
1668
1669 ecm_configure_package_config_file(<input> <output>
1670 INSTALL_DESTINATION <path>
1671 [PATH_VARS <var1> [<var2> [...]]
1672 [NO_SET_AND_CHECK_MACRO]
1673 [NO_CHECK_REQUIRED_COMPONENTS_MACRO])
1674
1675 This behaves in the same way as configure_package_config_file() from
1676 CMake 2.8.12, except that it adds an extra helper macro: find_depen‐
1677 dency(). It is highly recommended that you read the documentation for
1678 CMakePackageConfigHelpers for more information, particularly with
1679 regard to the PATH_VARS argument.
1680
1681 Note that there is no argument that will disable the find_dependency()
1682 macro; if you do not require this macro, you should use configure_pack‐
1683 age_config_file from the CMakePackageConfigHelpers module.
1684
1685 CMake 3.0 includes a CMakeFindDependencyMacro module that provides the
1686 find_dependency() macro (which you can include() in your package config
1687 file), so this file is only useful for projects wishing to provide con‐
1688 fig files that will work with CMake 2.8.12.
1689
1690 Additional Config File Macros
1691 find_dependency(<dep> [<version> [EXACT]])
1692
1693 find_dependency() should be used instead of find_package() to find
1694 package dependencies. It forwards the correct parameters for EXACT,
1695 QUIET and REQUIRED which were passed to the original find_package()
1696 call. It also sets an informative diagnostic message if the dependency
1697 could not be found.
1698
1699 Since pre-1.0.0.
1700
1701 ECMPoQmTools
1702 This module provides the ecm_process_po_files_as_qm and
1703 ecm_install_po_files_as_qm functions for generating QTranslator (.qm)
1704 catalogs from Gettext (.po) catalogs, and the ecm_create_qm_loader
1705 function for generating the necessary code to load them in a Qt appli‐
1706 cation or library.
1707
1708 ecm_process_po_files_as_qm(<lang> [ALL]
1709 [INSTALL_DESTINATION <install_destination>]
1710 PO_FILES <pofile> [<pofile> [...]])
1711
1712 Compile .po files into .qm files for the given language.
1713
1714 If INSTALL_DESTINATION is given, the .qm files are installed in
1715 <install_destination>/<lang>/LC_MESSAGES. Typically, <install_destina‐
1716 tion> is set to share/locale.
1717
1718 ecm_process_po_files_as_qm creates a “translations” target. This target
1719 builds all .po files into .qm files. If ALL is specified, these rules
1720 are added to the “all” target (and so the .qm files will be built by
1721 default).
1722
1723 ecm_create_qm_loader(<source_files_var> <catalog_name>)
1724
1725 Generates C++ code which ensures translations are automatically loaded
1726 at startup. The generated files are appended to <source_files_var>.
1727
1728 It assumes that the .qm file for the language code <lang> is installed
1729 as <sharedir>/locale/<lang>/LC_MESSAGES/<catalog_name>.qm, where
1730 <sharedir> is one of the directories given by the GenericDataLocation
1731 of QStandardPaths.
1732
1733 Typical usage is like:
1734
1735 set(mylib_SRCS foo.cpp bar.cpp)
1736 ecm_create_qm_loader(mylib_SRCS mylib)
1737 add_library(mylib ${mylib_SRCS})
1738
1739 ecm_install_po_files_as_qm(<podir>)
1740
1741 Searches for .po files and installs them to the standard location.
1742
1743 This is a convenience function which relies on all .po files being kept
1744 in <podir>/<lang>/, where <lang> is the language the .po files are
1745 written in.
1746
1747 For example, given the following directory structure:
1748
1749 po/
1750 fr/
1751 mylib.po
1752
1753 ecm_install_po_files_as_qm(po) compiles mylib.po into mylib.qm and
1754 installs it in <install_destination>/fr/LC_MESSAGES. <install_destina‐
1755 tion> defaults to ${LOCALE_INSTALL_DIR} if defined, otherwise it uses
1756 ${CMAKE_INSTALL_LOCALEDIR} if that is defined, otherwise it uses
1757 share/locale.
1758
1759 Since pre-1.0.0.
1760
1761 ECMQMLModules
1762 Find QML import modules through a find_qmlmodule() call. It uses the
1763 qmlplugindump application to find the plugins and sets them up as run‐
1764 time dependencies.
1765
1766 This is useful so that when we configure a project we are noified when
1767 some QML imports are not present in the system, thus having the appli‐
1768 cation compilable but fail at runtime.
1769
1770 ecm_find_qmlmodule(<module_name> <version>...)
1771
1772 Any further arguments passed will be forwarded into a find_package()
1773 call. See find_package() documentation for more information.
1774
1775 Usage example:
1776
1777 ecm_find_qmlmodule(org.kde.kirigami 2.1)
1778
1779 Since 5.38.0.
1780
1781 ECMQtDeclareLoggingCategory
1782 This module provides the ecm_qt_declare_logging_category function for
1783 generating declarations for logging categories in Qt5, and the
1784 ecm_qt_install_logging_categories function for generating and
1785 installing a file in KDebugSettings format with the info about all
1786 those categories, as well as a file with info about any renamed cate‐
1787 gories if defined. To include in that file any logging categories that
1788 are manually defined also a function ecm_qt_export_logging_category is
1789 provided.
1790
1791 ecm_qt_declare_logging_category(<sources_var>
1792 HEADER <filename>
1793 IDENTIFIER <identifier>
1794 CATEGORY_NAME <category_name>
1795 [OLD_CATEGORY_NAMES <oldest_cat_name> [<second_oldest_cat_name> [...]]]
1796 [DEFAULT_SEVERITY <Debug|Info|Warning|Critical|Fatal>]
1797 [EXPORT <exportid>]
1798 [DESCRIPTION <description>]
1799 )
1800
1801 A header file, <filename>, will be generated along with a corresponding
1802 source file, which will be added to <sources_var>. These will provide a
1803 QLoggingCategory category that can be referred to from C++ code using
1804 <identifier>, and from the logging configuration using <category_name>.
1805
1806 If <filename> is not absolute, it will be taken relative to the current
1807 binary directory.
1808
1809 If the code is compiled against Qt 5.4 or later, by default it will
1810 only log output that is at least the severity specified by
1811 DEFAULT_SEVERITY, or “Info” level if DEFAULT_SEVERITY is not given.
1812 Note that, due to a bug in Qt 5.5, “Info” may be treated as more severe
1813 than “Fatal”.
1814
1815 <identifier> may include namespaces (eg: foo::bar::IDENT).
1816
1817 If EXPORT is passed, the category will be registered for the group id
1818 <exportid>. Info about the categories of that group can then be gener‐
1819 ated in a file and installed by that group id with the
1820 ecm_qt_install_logging_categories function. In that case also DESCRIP‐
1821 TION will need to be passed, with <description> being a short single
1822 line text. And OLD_CATEGORY_NAMES can be used to inform about any
1823 renamings of the category, so user settings can be migrated. Since
1824 5.68.0.
1825
1826 Since 5.14.0.
1827
1828 ecm_qt_export_logging_category(
1829 IDENTIFIER <identifier>
1830 CATEGORY_NAME <category_name>
1831 [OLD_CATEGORY_NAMES <oldest_category_name> [<second_oldest_category_name> [...]]]
1832 EXPORT <exportid>
1833 DESCRIPTION <description>
1834 [DEFAULT_SEVERITY <Debug|Info|Warning|Critical|Fatal>]
1835 )
1836
1837 Registers a logging category for being included in the generated and
1838 installed KDebugSettings files. To be used for categories who are
1839 declared by manual code or other ways instead of code generated with
1840 ecm_qt_declare_logging_category.
1841
1842 <identifier> may include namespaces (eg: foo::bar::IDENT).
1843
1844 EXPORT specifies the group id with which the category will be regis‐
1845 tered. Info about the categories of that group can then be generated
1846 in a file and installed by that group id with the ecm_qt_install_log‐
1847 ging_categories function.
1848
1849 DESCRIPTION specifies a short single line text describing the category.
1850
1851 OLD_CATEGORY_NAMES can be used to inform about any renamings of the
1852 category, so user settings can be migrated.
1853
1854 Since 5.68.0.
1855
1856 ecm_qt_install_logging_categories(
1857 EXPORT <exportid>
1858 [FILE <filename>]
1859 DESTINATION <install_path>
1860 [SORT]
1861 [COMPONENT <component>]
1862 )
1863
1864 Generates and installs a file in KDebugSettings format with the info
1865 about all the categories registered for the group <exportid>, as well
1866 as a file with info about any renamed categories, if there are.
1867
1868 The method call needs to be after the last ecm_qt_declare_logging_cate‐
1869 gory call which uses the same <exportid>. This can be in the same
1870 directory, or any subdirectory or parent directory.
1871
1872 EXPORT specifies the group id of categories whose information should be
1873 stored in the file generated and installed.
1874
1875 FILE specifies the name of the file generated and installed. It will
1876 default to lower-cased <exportid>.categories.
1877
1878 DESTINATION specifies where the generated file will be installed.
1879
1880 IF SORT is set, entries will be sorted by identifiers.
1881
1882 COMPONENT specifies the installation component name with which the
1883 install rules for the generated file are associated.
1884
1885 Example usage:
1886
1887 ecm_qt_declare_logging_category(
1888 MYPROJECT_SRCS
1889 HEADER "myproject_debug.h"
1890 IDENTIFIER "MYPROJECT_DEBUG"
1891 CATEGORY_NAME "myproject"
1892 OLD_CATEGORY_NAMES "myprojectlog"
1893 DESCRIPTION "My project"
1894 EXPORT MyProject
1895 )
1896
1897 ecm_qt_export_logging_category(
1898 IDENTIFIER "MYPROJECT_SUBMODULE_DEBUG"
1899 CATEGORY_NAME "myproject.submodule"
1900 DESCRIPTION "My project - submodule"
1901 EXPORT MyProject
1902 )
1903
1904 ecm_qt_install_logging_categories(
1905 EXPORT MyProject
1906 FILE myproject.categories
1907 DESTINATION "${KDE_INSTALL_LOGGINGCATEGORIESDIR}"
1908 )
1909
1910 Since 5.68.0.
1911
1912 ECMSetupQtPluginMacroNames
1913 Instruct CMake’s automoc about C++ preprocessor macros used to define
1914 Qt-style plugins.
1915
1916 ecm_setup_qtplugin_macro_names(
1917 [JSON_NONE <macro_name> [<macro_name> [...]]]
1918 [JSON_ARG1 <macro_name> [<macro_name> [...]]]
1919 [JSON_ARG2 <macro_name> [<macro_name> [...]]]
1920 [JSON_ARG3 <macro_name> [<macro_name> [...]]]
1921 [CONFIG_CODE_VARIABLE <variable_name>] )
1922
1923 CMake’s automoc needs some support when parsing C++ source files to
1924 detect whether moc should be run on those files and if there are also
1925 dependencies on other files, like those with Qt plugin metadata in JSON
1926 format. Because automoc just greps overs the raw plain text of the
1927 sources without any C++ preprocessor-like processing. CMake in newer
1928 versions provides the variables CMAKE_AUTOMOC_DEPEND_FILTERS (CMake >=
1929 3.9.0) and CMAKE_AUTOMOC_MACRO_NAMES (CMake >= 3.10) to allow the
1930 developer to assist automoc.
1931
1932 This macro cares for the explicit setup needed for those variables for
1933 common cases of C++ preprocessor macros used for Qt-style plugins.
1934
1935 JSON_NONE lists the names of C++ preprocessor macros for Qt-style plug‐
1936 ins which do not refer to external files with the plugin metadata.
1937
1938 JSON_ARG1 lists the names of C++ preprocessor macros for Qt-style plug‐
1939 ins where the first argument to the macro is the name of the external
1940 file with the plugin metadata.
1941
1942 JSON_ARG2 is the same as JSON_ARG1 but with the file name being the
1943 second argument.
1944
1945 JSON_ARG3 is the same as JSON_ARG1 but with the file name being the
1946 third argument.
1947
1948 CONFIG_CODE_VARIABLE specifies the name of the variable which will get
1949 set as value some generated CMake code for instructing automoc for the
1950 given macro names, as useful in an installed CMake config file. The
1951 variable can then be used as usual in the template file for such a
1952 CMake config file, by @<variable_name>@.
1953
1954 Example usage:
1955
1956 Given some plugin-oriented Qt-based software which defines a custom C++
1957 preprocessor macro EXPORT_MYPLUGIN for declaring the central plugin
1958 object:
1959
1960 #define EXPORT_MYPLUGIN_WITH_JSON(classname, jsonFile) \
1961 class classname : public QObject \
1962 { \
1963 Q_OBJECT \
1964 Q_PLUGIN_METADATA(IID "myplugin" FILE jsonFile) \
1965 explicit classname() {} \
1966 };
1967
1968 In the CMake buildsystem of the library one calls
1969
1970 ecm_setup_qtplugin_macro_names(
1971 JSON_ARG2
1972 EXPORT_MYPLUGIN_WITH_JSON
1973 )
1974
1975 to instruct automoc about the usage of that macro in the sources of the
1976 library itself.
1977
1978 Given the software installs a library including the header with the
1979 macro definition and a CMake config file, so 3rd-party can create addi‐
1980 tional plugins by linking against the library, one passes additionally
1981 the name of a variable which shall be set as value the CMake code
1982 needed to instruct automoc about the usage of that macro.
1983
1984 ecm_setup_qtplugin_macro_names(
1985 JSON_ARG2
1986 EXPORT_MYPLUGIN_WITH_JSON
1987 CONFIG_CODE_VARIABLE
1988 PACKAGE_SETUP_AUTOMOC_VARIABLES
1989 )
1990
1991 This variable then is used in the template file (e.g. MyProjectCon‐
1992 fig.cmake.in) for the libary’s installed CMake config file and that way
1993 will ensure that in the 3rd-party plugin’s buildsystem automoc is
1994 instructed as well as needed:
1995
1996 @PACKAGE_SETUP_AUTOMOC_VARIABLES@
1997
1998 Since 5.45.0.
1999
2000 ECMSetupVersion
2001 Handle library version information.
2002
2003 ecm_setup_version(<version>
2004 VARIABLE_PREFIX <prefix>
2005 [SOVERSION <soversion>]
2006 [VERSION_HEADER <filename>]
2007 [PACKAGE_VERSION_FILE <filename> [COMPATIBILITY <compat>]] )
2008
2009 This parses a version string and sets up a standard set of version
2010 variables. It can optionally also create a C version header file and a
2011 CMake package version file to install along with the library.
2012
2013 If the <version> argument is of the form <major>.<minor>.<patch> (or
2014 <major>.<minor>.<patch>.<tweak>), The following CMake variables are
2015 set:
2016
2017 <prefix>_VERSION_MAJOR - <major>
2018 <prefix>_VERSION_MINOR - <minor>
2019 <prefix>_VERSION_PATCH - <patch>
2020 <prefix>_VERSION - <version>
2021 <prefix>_VERSION_STRING - <version> (for compatibility: use <prefix>_VERSION instead)
2022 <prefix>_SOVERSION - <soversion>, or <major> if SOVERSION was not given
2023
2024 If CMake policy CMP0048 is not NEW, the following CMake variables will
2025 also be set:
2026
2027 PROJECT_VERSION_MAJOR - <major>
2028 PROJECT_VERSION_MINOR - <minor>
2029 PROJECT_VERSION_PATCH - <patch>
2030 PROJECT_VERSION - <version>
2031 PROJECT_VERSION_STRING - <version> (for compatibility: use PROJECT_VERSION instead)
2032
2033 If the VERSION_HEADER option is used, a simple C header is generated
2034 with the given filename. If filename is a relative path, it is inter‐
2035 preted as relative to CMAKE_CURRENT_BINARY_DIR. The generated header
2036 contains the following macros:
2037
2038 <prefix>_VERSION_MAJOR - <major> as an integer
2039 <prefix>_VERSION_MINOR - <minor> as an integer
2040 <prefix>_VERSION_PATCH - <patch> as an integer
2041 <prefix>_VERSION_STRING - <version> as a C string
2042 <prefix>_VERSION - the version as an integer
2043
2044 <prefix>_VERSION has <patch> in the bottom 8 bits, <minor> in the next
2045 8 bits and <major> in the remaining bits. Note that <patch> and
2046 <minor> must be less than 256.
2047
2048 If the PACKAGE_VERSION_FILE option is used, a simple CMake package ver‐
2049 sion file is created using the write_basic_package_version_file() macro
2050 provided by CMake. It should be installed in the same location as the
2051 Config.cmake file of the library so that it can be found by find_pack‐
2052 age(). If the filename is a relative path, it is interpreted as rela‐
2053 tive to CMAKE_CURRENT_BINARY_DIR. The optional COMPATIBILITY option is
2054 forwarded to write_basic_package_version_file(), and defaults to
2055 AnyNewerVersion.
2056
2057 If CMake policy CMP0048 is NEW, an alternative form of the command is
2058 available:
2059
2060 ecm_setup_version(PROJECT
2061 [VARIABLE_PREFIX <prefix>]
2062 [SOVERSION <soversion>]
2063 [VERSION_HEADER <filename>]
2064 [PACKAGE_VERSION_FILE <filename>] )
2065
2066 This will use the version information set by the project() command.
2067 VARIABLE_PREFIX defaults to the project name. Note that PROJECT must
2068 be the first argument. In all other respects, it behaves like the
2069 other form of the command.
2070
2071 Since pre-1.0.0.
2072
2073 COMPATIBILITY option available since 1.6.0.
2074
2075 ECMSourceVersionControl
2076 Tries to determine whether the source is under version control (git
2077 clone, svn checkout, etc).
2078
2079 ECM_SOURCE_UNDER_VERSION_CONTROL is set when indication is found that
2080 CMAKE_SOURCE_DIR is under version control.
2081
2082 Since 5.63
2083
2084 ECMUninstallTarget
2085 Add an uninstall target.
2086
2087 By including this module, an uninstall target will be added to your
2088 CMake project. This will remove all files installed (or updated) by a
2089 previous invocation of the install target. It will not remove files
2090 created or modified by an install(SCRIPT) or install(CODE) command; you
2091 should create a custom uninstallation target for these and use
2092 add_dependency to make the uninstall target depend on it:
2093
2094 include(ECMUninstallTarget)
2095 install(SCRIPT install-foo.cmake)
2096 add_custom_target(uninstall_foo COMMAND ${CMAKE_COMMAND} -P uninstall-foo.cmake)
2097 add_dependency(uninstall uninstall_foo)
2098
2099 The target will fail if the install target has not yet been run (so it
2100 is not possible to run CMake on the project and then immediately run
2101 the uninstall target).
2102
2103 WARNING:
2104 CMake deliberately does not provide an uninstall target by default
2105 on the basis that such a target has the potential to remove impor‐
2106 tant files from a user’s computer. Use with caution.
2107
2108 Since 1.7.0.
2109
2110 ECMUseFindModules
2111 Selectively use some of the find modules provided by extra-cmake-mod‐
2112 ules.
2113
2114 This module is automatically available once extra-cmake-modules has
2115 been found, so it is not necessary to include(ECMUseFindModules)
2116 explicitly.
2117
2118 ecm_use_find_modules(DIR <dir>
2119 MODULES module1.cmake [module2.cmake [...]]
2120 [NO_OVERRIDE])
2121
2122 This allows selective use of the find modules provided by ECM, includ‐
2123 ing deferring to CMake’s versions of those modules if it has them.
2124 Rather than adding ${ECM_FIND_MODULE_DIR} to CMAKE_MODULE_PATH, you use
2125 ecm_use_find_modules() to copy the modules you want to a local (build)
2126 directory, and add that to CMAKE_MODULE_PATH.
2127
2128 The find modules given to MODULES will be copied to the directory given
2129 by DIR (which should be located in ${CMAKE_BINARY_DIR} and added to
2130 CMAKE_MODULE_PATH). If NO_OVERRIDE is given, only modules not also
2131 provided by CMake will be copied.
2132
2133 Example:
2134
2135 find_package(ECM REQUIRED)
2136 ecm_use_find_modules(
2137 DIR ${CMAKE_BINARY_DIR}/cmake
2138 MODULES FindEGL.cmake
2139 NO_OVERRIDE
2140 )
2141 set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/cmake)
2142
2143 This example will make FindEGL.cmake available in your project, but
2144 only as long as it is not yet part of CMake. Calls to find_package(EGL)
2145 will then make use of this copied module (or the CMake module if it
2146 exists).
2147
2148 Another possible use for this macro is to take copies of find modules
2149 that can be installed along with config files if they are required as a
2150 dependency (for example, if targets provided by the find module are in
2151 the link interface of a library).
2152
2153 Since pre-1.0.0.
2154
2155 ECMWinResolveSymlinks
2156 Resolve pseudo-symlinks created by git when cloning on Windows.
2157
2158 ecm_win_resolve_symlinks(<dir>)
2159
2160 When git checks out a repository with UNIX symlinks on Windows machine,
2161 it creates a text file for each symlink, containing a relative path to
2162 the real file. This function would recursively walk over specified
2163 directory and replace pseudo-symlinks with corresponding real file’s
2164 contents. It would then run git update-index –assume-unchanged on them
2165 to trick git.
2166
2167 This is useful for projects like “breeze-icons” that contain many iden‐
2168 tical icons implemented as symlinks.
2169
2170 Since 5.28
2171
2173 ecm(7), ecm-find-modules(7), ecm-kde-modules(7)
2174
2176 KDE Developers
2177
2178
2179
2180
21815.79 Feb 06, 2021 ECM-MODULES(7)