File: MongoPlatform.cmake

package info (click to toggle)
mongo-c-driver 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 47,088 kB
  • sloc: ansic: 193,670; python: 7,780; cpp: 1,493; sh: 659; makefile: 78
file content (87 lines) | stat: -rw-r--r-- 3,576 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#[[

Defines a target mongo::detail::c_platform (alias of _mongo-platform), which
exposes system-level supporting compile and link usage requirements. All targets
should link to this target with level PUBLIC.

Use mongo_platform_compile_options and mongo_platform_link_options to add usage
requirements to this library.

The mongo::detail::c_platform library is installed and exported with the
mongo-platform-targets export set as an implementation detail. It is installed with this
export set so that it is available to both libbson and libmongoc (attempting to
install this target in both mongo-platform-targets and mongoc-targets export sets would
lead to duplicate definitions of mongo::detail::c_platform for downstream
users).

]]

add_library(_mongo-platform INTERFACE)
if (NOT USE_SYSTEM_LIBBSON)
    add_library(mongo::detail::c_platform ALIAS _mongo-platform)
else ()
   # The system libbson exports the `mongo::detail::c_platform` target.
   # Do not define the `mongo::detail::c_platform` target, to prevent an "already defined" error.
endif ()
set_property(TARGET _mongo-platform PROPERTY EXPORT_NAME mongo::detail::c_platform)
# This export set is installed as part of libbson. Search: PLATFORM-EXPORT-TARGET-INSTALL
install(TARGETS _mongo-platform EXPORT mongo-platform-targets)

#[[
Define additional platform-support compile options

These options are added to the mongo::detail::c_platform INTERFACE library.
]]
function (mongo_platform_compile_options)
    list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION})
    message(DEBUG "Add platform-support compilation options: ${ARGN}")
    target_compile_options(_mongo-platform INTERFACE ${ARGN})
endfunction ()

#[[
Define additional platform-support link options.

These options are added to the mongo::detail::c_platform INTERFACE library.
]]
function(mongo_platform_link_options)
    list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION})
    message(DEBUG "Add platform-support runtime linking options: ${ARGN}")
    target_link_options(_mongo-platform INTERFACE ${ARGN})
endfunction()

#[[
Add targets to the usage requirements for the current platform.

All of the named items must be the names of existing targets. Note that these
targets will also need to be available at import-time for consumers (unless
wrapped in $<BUILD_INTERFACE:>).
]]
function(mongo_platform_use_target)
    list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION})
    message(DEBUG "Add platform-support usage of targets: ${ARGN}")
    foreach(item IN LISTS ARGN)
        if(item MATCHES "::")
            # CMake will enforce that this link names an existing target
            target_link_libraries(_mongo-platform INTERFACE "${item}")
        else()
            # Generate a configure-time-error if the named item is not the name of a target
            target_link_libraries(_mongo-platform INTERFACE
                $<IF:$<TARGET_EXISTS:${item}>,${item},NO_SUCH_TARGET::${item}>)
        endif()
    endforeach()
endfunction()

#[[
Add non-target link library as usage requirements for the current platform.

This is intended for adding libraries that need to be linked. To add targets
as usage requirements, use mongo_platform_use_target. For adding link options,
use mongo_platform_link_options.
]]
function(mongo_platform_link_libraries)
    list(APPEND CMAKE_MESSAGE_CONTEXT ${CMAKE_CURRENT_FUNCTION})
    foreach(item IN LISTS ARGN)
        message(DEBUG "Add platform-support link library: ${item}")
        target_link_libraries(_mongo-platform INTERFACE "${item}")
    endforeach()
endfunction()