tpm2.parts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ############################################################################
  2. # Copyright 2017 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. import os
  17. Import('*')
  18. env.PartName('tpm2')
  19. include_files = Pattern(src_dir='.',
  20. includes=['*.h'],
  21. recursive=False).files()
  22. install_files = Pattern(src_dir='.',
  23. includes=[
  24. '*.h',
  25. '*.c',
  26. '*-test.cc',
  27. '*-testhelper.cc',
  28. '*.parts'],
  29. recursive=True)
  30. if 'install_package' in env['MODE']:
  31. env.InstallTopLevel(install_files,
  32. sub_dir='epid/member/${PART_SHORT_NAME}')
  33. else:
  34. env.DependsOn([
  35. Component('common'),
  36. ])
  37. env.Append(CPPPATH='#')
  38. if 'use_tss' in env['MODE']:
  39. src_files = Pattern(src_dir='ibm_tss',
  40. includes=['*.c'],
  41. recursive=False).files()
  42. utest_files = Pattern(src_dir='unittests',
  43. includes=['*-test.cc',
  44. '*-testhelper.cc'],
  45. excludes=['*-simulator-test.cc'],
  46. recursive=False).files()
  47. if env['TARGET_ARCH'] == 'x86_64' and env['TARGET_PLATFORM']['OS'] == 'win32':
  48. PrintError("--use-tss is not compatiable with x86_64 target. "
  49. "Try an x86 build.")
  50. try:
  51. TSSROOT = os.environ['TSSROOT']
  52. except KeyError, e:
  53. env.PrintError("Necessary environment variable not set: ",
  54. e, show_stack=False)
  55. env.Append(CPPPATH=TSSROOT)
  56. env.Append(LIBPATH=TSSROOT)
  57. if 'cl' in env['CC']:
  58. env.Append(CCFLAGS=['/wd4201', # allow nameless struct
  59. '/wd4200', # allow zero-sized array in struct
  60. ])
  61. env.Append(CPPDEFINES=['TPM_TSS'])
  62. else:
  63. src_files = Pattern(src_dir='src',
  64. includes=['*.c'],
  65. recursive=False).files()
  66. utest_files = Pattern(src_dir='unittests',
  67. includes=['*-test.cc',
  68. '*-testhelper.cc'],
  69. excludes=['*-tss-test.cc'],
  70. recursive=False).files()
  71. testenv = env.Clone()
  72. outputs = env.Library('${PART_NAME}', src_files)
  73. env.Sdk(outputs)
  74. env.SdkInclude(include_files,
  75. sub_dir='epid/member/${PART_SHORT_NAME}')
  76. #unit tests
  77. testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}"
  78. utest = testenv.UnitTest("utest",
  79. utest_files,
  80. command_args=[
  81. '--gtest_color=yes',
  82. '--gtest_print_time=1',
  83. '--gtest_output=xml',
  84. '--gtest_filter=**',
  85. ],
  86. make_pdb=(env.isConfigBasedOn('debug') or
  87. env.isConfigBasedOn('static_crt_debug')),
  88. depends=[Component('gtest'),
  89. Component('common-testhelper'),
  90. Component('member.tpm2')],
  91. INSTALL_BIN='${INSTALL_TEST_BIN}')
  92. if 'use_tss' in env['MODE']:
  93. if env['TARGET_PLATFORM']['OS'] == 'win32':
  94. libpost = env['LIBSUFFIX']
  95. shlibpost = env['SHLIBSUFFIX']
  96. else:
  97. libpost = env['SHLIBSUFFIX']
  98. shlibpost = libpost
  99. tss_libname = env['LIBPREFIX'] + 'tss' + libpost
  100. env.SdkLib(os.path.join(TSSROOT, tss_libname))
  101. if env['TARGET_PLATFORM']['OS'] != 'win32':
  102. env.ExportLIBS(['crypto'])
  103. tss_shlibname = env['SHLIBPREFIX'] + 'tss' + shlibpost
  104. runtime_lib = testenv.CCopy("${INSTALL_TEST_BIN}",
  105. os.path.join(TSSROOT, tss_shlibname))
  106. Depends(utest, runtime_lib)