File: SolidBackendsMacros.cmake

package info (click to toggle)
solid 5.78.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 5,100 kB
  • sloc: cpp: 21,549; xml: 464; lex: 111; yacc: 83; sh: 14; makefile: 5
file content (72 lines) | stat: -rw-r--r-- 2,985 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Helper macros for dealing with device backends.

# SPDX-FileCopyrightText: 2019 Pino Toscano <pino@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause

# "Begin" the device backends addition, to be called *before* all the order
# add_device_backend* macros
macro(add_device_backends_begin)
    set(ENABLED_DEVICE_BACKENDS)
endmacro()

# Macro to add a new device backend; a new cmake option is automatically added
# to disable the build of that backend, available as
# BUILD_DEVICE_BACKEND_$name.
macro(add_device_backend backend)
    _add_device_backend(${backend} "${CMAKE_CURRENT_SOURCE_DIR}")
endmacro()

# Internal implementation of add_device_backend, mostly to pass the right
# source directory (in case of a function is the file containing that
# function).
function(_add_device_backend backend source_dir)
    set(cmakelists_path "${source_dir}/src/solid/devices/backends/${backend}/CMakeLists.txt")
    if(NOT (EXISTS "${cmakelists_path}"))
        message(FATAL_ERROR "Missing CMakeLists.txt for backend ${backend}")
    endif()

    option(BUILD_DEVICE_BACKEND_${backend} "Build the backend ${backend}" ON)
    if(NOT BUILD_DEVICE_BACKEND_${backend})
        return()
    endif()

    set(backends ${ENABLED_DEVICE_BACKENDS})
    list(APPEND backends ${backend})
    set(ENABLED_DEVICE_BACKENDS ${backends} PARENT_SCOPE)
endfunction()

# After all the add_device_backend()s are called, create all the cmake
# material:
# - the BUILD_DEVICE_BACKEND_$name cmake variables, used to conditionally
#   add stuff depending whether a backend is built
# - a feature info, to show that that backend was enabled
macro(add_device_backends_cmake)
    foreach(backend ${ENABLED_DEVICE_BACKENDS})
        set(BUILD_DEVICE_BACKEND_${backend} TRUE)
        add_feature_info(${backend} TRUE "Solid device '${backend}' backend.")
    endforeach()
endmacro()

# After all the add_device_backend()s are called, create/collect all the
# material used for the build:
# - create a config-backends.h file in the current binary directory, with
#   BUILD_DEVICE_BACKEND_$name defines for all the built backends
# - fill the sources_var, and libs_var variables resp. with the sources,
#   and the libraries needed for all the built backends
macro(add_device_backends_build base_backends_dir sources_var libs_var)
    foreach(backend ${ENABLED_DEVICE_BACKENDS})
        string(APPEND config_backends_output "#define BUILD_DEVICE_BACKEND_${backend} 1\n")
        unset(backend_sources)
        unset(backend_libs)
        include("${base_backends_dir}/${backend}/CMakeLists.txt")
        foreach(source ${backend_sources})
            if(NOT (IS_ABSOLUTE ${source}))
                set(source "${base_backends_dir}/${backend}/${source}")
            endif()
            list(APPEND ${sources_var} "${source}")
        endforeach()
        list(APPEND ${libs_var} ${backend_libs})
    endforeach()
    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config-backends.h" "${config_backends_output}")
endmacro()