• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1############################################################################
2# Copyright 2016-2018 Intel Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15############################################################################
16
17import os
18
19Import('*')
20env.PartName('member')
21
22api_headers = Pattern(src_dir='.', includes=['*.h'], recursive=False).files()
23src_files = Pattern(src_dir='src', includes=['*.c'], recursive=False).files()
24internal_headers = Pattern(
25    src_dir='src', includes=['*.h'], recursive=False).files()
26
27tpm_utest_wrapper_files = Pattern(
28    src_dir='tpm2/unittests',
29    includes=['tpm2_wrapper-testhelper.cc'],
30    recursive=False).files()
31
32utest_files = Pattern(
33    src_dir='unittests',
34    includes=[
35        '*-test.cc',
36        '*-testhelper.cc',
37    ],
38    recursive=False).files()
39utest_headers = Pattern(
40    src_dir='unittests', includes=[
41        '*-testhelper.h',
42    ], recursive=False).files()
43
44build_files = Pattern(
45    src_dir='.', includes=['*.parts', 'Makefile'], recursive=False).files()
46
47tpm2_install_files = Pattern(src_dir='tpm2',
48                             includes=[
49                                 '*.h',
50                                 '*.c',
51                                 '*-test.cc',
52                                 '*-testhelper.cc',
53                                 '*.parts'],
54                             recursive=True)
55tpm2_include_files = Pattern(src_dir='.',
56                             includes=['*.h'],
57                             recursive=False).files()
58
59
60if 'install_package' in env['MODE']:
61    env.InstallTopLevel(api_headers, sub_dir='epid/${PART_SHORT_NAME}')
62    env.InstallTopLevel(
63        src_files + internal_headers, sub_dir='epid/${PART_SHORT_NAME}/src')
64    env.InstallTopLevel(
65        utest_files + utest_headers,
66        sub_dir='epid/${PART_SHORT_NAME}/unittests')
67    env.InstallTopLevel(build_files, sub_dir='epid/${PART_SHORT_NAME}')
68    env.InstallTopLevel(tpm2_install_files,
69                        sub_dir='epid/${PART_SHORT_NAME}/tpm2')
70
71else:
72    env.DependsOn([
73        Component('common'),
74    ])
75
76    if 'use_tss' in env['MODE']:
77        env.Append(CPPDEFINES=['TPM_TSS'])
78
79        tpm2_src_files = Pattern(src_dir='tpm2/ibm_tss',
80                                 includes=['*.c'],
81                                 recursive=False).files()
82        tpm2_utest_files = Pattern(src_dir='tpm2/unittests',
83                                   includes=['*-test.cc',
84                                             '*-testhelper.cc'],
85                                   excludes=['*-simulator-test.cc'],
86                                   recursive=False).files()
87        if (env['TARGET_ARCH'] == 'x86_64' and
88                env['TARGET_PLATFORM']['OS'] == 'win32'):
89            PrintError("--use-tss is not compatiable with x86_64 target. "
90                       "Try an x86 build.")
91        try:
92            TSSROOT = os.environ['TSSROOT']
93        except KeyError, e:
94            env.PrintError("Necessary environment variable not set: ",
95                           e, show_stack=False)
96        env.Append(CPPPATH=TSSROOT)
97        env.Append(LIBPATH=TSSROOT)
98        if 'cl' in env['CC']:
99            env.Append(CCFLAGS=['/wd4201',   # allow nameless struct
100                                '/wd4200',   # allow zero-sized array in struct
101                               ])
102        env.Append(CPPDEFINES=['TPM_TSS'])
103
104    else:
105        tpm2_src_files = Pattern(src_dir='tpm2/src',
106                                 includes=['*.c'],
107                                 recursive=False).files()
108
109        tpm2_utest_files = Pattern(src_dir='tpm2/unittests',
110                                   includes=['*-test.cc',
111                                             '*-testhelper.cc'],
112                                   excludes=['*-tss-test.cc'],
113                                   recursive=False).files()
114
115    env.Append(CPPPATH='#')
116
117
118    testenv = env.Clone()
119
120    outputs = env.Library('${PART_NAME}', src_files + tpm2_src_files)
121    env.Sdk(outputs)
122    env.SdkInclude(api_headers, sub_dir='epid/${PART_SHORT_NAME}')
123
124    if 'install_lib' in env['MODE']:
125        env.InstallLib(outputs)
126        env.InstallInclude(api_headers, sub_dir='${PART_SHORT_NAME}')
127
128    #unit tests
129    testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}"
130    testenv.UnitTest(
131        "utest",
132        utest_files + tpm_utest_wrapper_files,
133        command_args=[
134            '--gtest_color=yes',
135            '--gtest_print_time=1',
136            '--gtest_output=xml',
137            '--gtest_filter=**',
138        ],
139        make_pdb=(env.isConfigBasedOn('debug') or
140                  env.isConfigBasedOn('static_crt_debug')),
141        depends=[
142            Component('gtest'), Component('common-testhelper'),
143            Component('member'), Component('verifier')
144        ],
145        INSTALL_BIN='${INSTALL_TEST_BIN}')
146
147    testenv['UNIT_TEST_TARGET_NAME'] = "${UNIT_TEST_TARGET}"
148
149    utest = testenv.UnitTest("member.tpm2-utest",
150                             tpm2_utest_files,
151                             command_args=[
152                                 '--gtest_color=yes',
153                                 '--gtest_print_time=1',
154                                 '--gtest_output=xml',
155                                 '--gtest_filter=**',
156                             ],
157                             make_pdb=(env.isConfigBasedOn('debug') or
158                                       env.isConfigBasedOn('static_crt_debug')),
159                             depends=[Component('gtest'),
160                                      Component('common-testhelper'),
161                                      Component('member')],
162                             INSTALL_BIN='${INSTALL_TEST_BIN}')
163
164    if 'use_tss' in env['MODE']:
165        if env['TARGET_PLATFORM']['OS'] == 'win32':
166            libpost = env['LIBSUFFIX']
167            shlibpost = env['SHLIBSUFFIX']
168        else:
169            libpost = env['SHLIBSUFFIX']
170            shlibpost = libpost
171
172        tss_libname = env['LIBPREFIX'] + 'tss' + libpost
173        env.SdkLib(os.path.join(TSSROOT, tss_libname))
174
175        if env['TARGET_PLATFORM']['OS'] != 'win32':
176            env.ExportLIBS(['crypto'])
177
178        tss_shlibname = env['SHLIBPREFIX'] + 'tss' + shlibpost
179        runtime_lib = testenv.CCopy("${INSTALL_TEST_BIN}",
180                                    os.path.join(TSSROOT, tss_shlibname))
181        Depends(utest, runtime_lib)
182