Changeset View
Changeset View
Standalone View
Standalone View
cmake/SolidBackendsMacros.cmake
- This file was added.
1 | # Helper macros for dealing with device backends. | ||||
---|---|---|---|---|---|
2 | | ||||
3 | # Copyright (c) 2019, Pino Toscano <pino@kde.org> | ||||
4 | # | ||||
5 | # Redistribution and use in source and binary forms, with or without | ||||
6 | # modification, are permitted provided that the following conditions | ||||
7 | # are met: | ||||
8 | # 1. Redistributions of source code must retain the above copyright | ||||
9 | # notice, this list of conditions and the following disclaimer. | ||||
10 | # 2. Redistributions in binary form must reproduce the above copyright | ||||
11 | # notice, this list of conditions and the following disclaimer in the | ||||
12 | # documentation and/or other materials provided with the distribution. | ||||
13 | # 3. Neither the name of the University nor the names of its contributors | ||||
14 | # may be used to endorse or promote products derived from this software | ||||
15 | # without specific prior written permission. | ||||
16 | # | ||||
17 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||||
18 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||||
21 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
22 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
23 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
24 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
25 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
26 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
27 | # SUCH DAMAGE. | ||||
28 | | ||||
29 | # "Begin" the device backends addition, to be called *before* all the order | ||||
30 | # add_device_backend* macros | ||||
31 | macro(add_device_backends_begin) | ||||
32 | set(ENABLED_DEVICE_BACKENDS) | ||||
33 | endmacro() | ||||
34 | | ||||
35 | # Macro to add a new device backend; a new cmake option is automatically added | ||||
36 | # to disable the build of that backend, available as | ||||
37 | # BUILD_DEVICE_BACKEND_$name. | ||||
38 | macro(add_device_backend backend) | ||||
39 | _add_device_backend(${backend} "${CMAKE_CURRENT_SOURCE_DIR}") | ||||
40 | endmacro() | ||||
41 | | ||||
42 | # Internal implementation of add_device_backend, mostly to pass the right | ||||
43 | # source directory (in case of a function is the file containing that | ||||
44 | # function). | ||||
45 | function(_add_device_backend backend source_dir) | ||||
46 | set(cmakelists_path "${source_dir}/src/solid/devices/backends/${backend}/CMakeLists.txt") | ||||
47 | if(NOT (EXISTS "${cmakelists_path}")) | ||||
48 | message(FATAL_ERROR "Missing CMakeLists.txt for backend ${backend}") | ||||
49 | endif() | ||||
50 | | ||||
51 | option(BUILD_DEVICE_BACKEND_${backend} "Build the backend ${backend}" ON) | ||||
52 | if(NOT BUILD_DEVICE_BACKEND_${backend}) | ||||
53 | return() | ||||
54 | endif() | ||||
55 | | ||||
56 | set(backends ${ENABLED_DEVICE_BACKENDS}) | ||||
57 | list(APPEND backends ${backend}) | ||||
58 | set(ENABLED_DEVICE_BACKENDS ${backends} PARENT_SCOPE) | ||||
59 | endfunction() | ||||
60 | | ||||
61 | # After all the add_device_backend()s are called, create all the cmake | ||||
62 | # material: | ||||
63 | # - the BUILD_DEVICE_BACKEND_$name cmake variables, used to conditionally | ||||
64 | # add stuff depending whether a backend is built | ||||
65 | # - a feature info, to show that that backend was enabled | ||||
66 | macro(add_device_backends_cmake) | ||||
67 | foreach(backend ${ENABLED_DEVICE_BACKENDS}) | ||||
68 | set(BUILD_DEVICE_BACKEND_${backend} TRUE) | ||||
69 | add_feature_info(${backend} TRUE "Solid device '${backend}' backend.") | ||||
70 | endforeach() | ||||
71 | endmacro() | ||||
72 | | ||||
73 | # After all the add_device_backend()s are called, create/collect all the | ||||
74 | # material used for the build: | ||||
75 | # - create a config-backends.h file in the current binary directory, with | ||||
76 | # BUILD_DEVICE_BACKEND_$name defines for all the built backends | ||||
77 | # - fill the sources_var, and libs_var variables resp. with the sources, | ||||
78 | # and the libraries needed for all the built backends | ||||
79 | macro(add_device_backends_build base_backends_dir sources_var libs_var) | ||||
80 | foreach(backend ${ENABLED_DEVICE_BACKENDS}) | ||||
81 | string(APPEND config_backends_output "#define BUILD_DEVICE_BACKEND_${backend} 1\n") | ||||
82 | unset(backend_sources) | ||||
83 | unset(backend_libs) | ||||
84 | include("${base_backends_dir}/${backend}/CMakeLists.txt") | ||||
85 | foreach(source ${backend_sources}) | ||||
86 | if(NOT (IS_ABSOLUTE ${source})) | ||||
87 | set(source "${base_backends_dir}/${backend}/${source}") | ||||
88 | endif() | ||||
89 | list(APPEND ${sources_var} "${source}") | ||||
90 | endforeach() | ||||
91 | list(APPEND ${libs_var} ${backend_libs}) | ||||
92 | endforeach() | ||||
93 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config-backends.h" "${config_backends_output}") | ||||
94 | endmacro() |