summaryrefslogtreecommitdiff
path: root/src/mongo/embedded/mongoc_embedded/SConscript
blob: fa25dd0a1c99405345e1eca4cd9f4fab73900b5f (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- mode: python; -*-

import libdeps

Import("env")
Import("get_option")

env = env.Clone()

if not env['MONGO_HAVE_LIBMONGOC']:
    Return()

def create_mongoc_env(env):
    mongocEnv = env.Clone()
    if mongocEnv['MONGO_HAVE_LIBMONGOC'] == "framework":
        mongocEnv.AppendUnique(FRAMEWORKS=['bson', 'mongoc'])
    else:
        mongocEnv.AppendUnique(LIBS=['bson-1.0', 'mongoc-1.0'])
    return mongocEnv

mongocEmbeddedEnv = create_mongoc_env(env)

mongocEmbeddedEnv.AppendUnique(
    CPPDEFINES=[
        'MONGOC_EMBEDDED_COMPILING',
     ],
)

if get_option('link-model') == 'static':
    mongocEmbeddedEnv.AppendUnique(
        CPPDEFINES=[
            'MONGOC_EMBEDDED_STATIC',
        ],
    )

# Please see the note in ../mongo_embedded/SConscript about how to
# interpret and adjust the current and compatibility versinos.
mongocEmbeddedEnv.AppendUnique(
    SHLINKFLAGS=[
        '$MONGO_EXPORT_FILE_SHLINKFLAGS',
    ],
)

if mongocEmbeddedEnv.TargetOSIs('darwin'):
    # Please see the note in ../mongo_embedded/SConscript about how to
    # interpret and adjust the current and compatibility versinos.
    mongocEmbeddedEnv.AppendUnique(
        SHLINKFLAGS=[
            '-Wl,-current_version,1',
            '-Wl,-compatibility_version,1',
        ],
    )

mongocEmbeddedEnv.Library(
    target='mongoc_embedded',
    source=[
        'mongoc_embedded.cpp',
    ],
    LIBDEPS=[
        # No LIBDEPS or LIBDEPS_PRIVATE to mongo libraries are allowed in this library. They would get duplicated in mongo_embedded_capi.
        '$BUILD_DIR/mongo/embedded/mongo_embedded/mongo_embedded',
    ],
    INSTALL_ALIAS=[
        'embedded-dev',
    ],
)

if get_option('install-mode') == 'hygienic':
    env.AutoInstall(
        'include/mongoc_embedded/v1/mongoc_embedded',
        source=['mongoc_embedded.h'],
        INSTALL_ALIAS=[
            'embedded-dev',
        ],
    )

yamlEnv = env.Clone()
yamlEnv.InjectThirdPartyIncludePaths(libraries=['yaml'])

if get_option('link-model') != 'dynamic-sdk':
    mongocEmbeddedTestEnv = create_mongoc_env(yamlEnv)
    clientTest = mongocEmbeddedTestEnv.Program(
        target='mongoc_embedded_test',
        source=[
            'mongoc_embedded_test.cpp',
        ],
        LIBDEPS=[
            '$BUILD_DIR/mongo/base',
            '$BUILD_DIR/mongo/db/server_options_core',
            '$BUILD_DIR/mongo/unittest/unittest',
            '$BUILD_DIR/mongo/util/options_parser/options_parser',
            'mongoc_embedded',
        ],
        INSTALL_ALIAS=[
            'embedded-test',
        ],
    )

    env.RegisterUnitTest(clientTest[0]);

# Frameworkization craziness begins here. Honestly, we should do this
# better in the future in some re-usable way, but we need to get this
# thing out the door, so here goes.

# First, we only do this in hygienic mode for the mobile targets,
# which are darwin but not macOS. For all others, we abort here. Maybe
# this should be a build flag? Since we aren't doing this for macOS,
# we can also ignore all the framework version nonsense.
if get_option('link-model') != 'dynamic-sdk' or get_option('install-mode') != 'hygienic' or not env.TargetOSIs('darwin') or env.TargetOSIs('macOS'):
    Return()

installHeaderRoot = env.Dir('$INSTALL_DIR/include/mongoc_embedded/v1/mongoc_embedded')

frameworkDir = env.Dir('$INSTALL_DIR/Frameworks/mongoc_embedded.framework')
env.Alias('install-embedded-dev', frameworkDir)

env.Install(
    target=frameworkDir.Dir('Headers'),
    source=installHeaderRoot.File('mongoc_embedded.h'),
)

env.InstallAs(
    target=frameworkDir.File('Modules/module.modulemap'),
    source="mongoc_embedded.modulemap"
)

mongocEmbeddedPlist = env.Substfile(
    target="Info.plist",
    source='../Info.plist.in',
    SUBST_DICT=[
        ('@CFBundleExecutable@', 'mongoc_embedded'),
        ('@CFBundleIdentifier@', 'org.mongodb.mongoc_embedded'),
        ('@CFBundleVersion@', '$MONGO_VERSION'),
        ('@CFBundleShortVersionString@', '$MONGO_VERSION')
    ]
)

env.Install(
    target=frameworkDir,
    source=mongocEmbeddedPlist,
)

mongocEmbeddedFwLib = env.InstallAs(
    target=frameworkDir.File('mongoc_embedded'),
    source='$INSTALL_DIR/lib/libmongoc_embedded.dylib',
)

env.AddPostAction(
    files=mongocEmbeddedFwLib,
    action=[
        "install_name_tool -id @rpath/mongoc_embedded.framework/mongoc_embedded $TARGET",
        "install_name_tool -change @rpath/libmongo_embedded.dylib @rpath/mongo_embedded.framework/mongo_embedded $TARGET",
    ],
)