Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Enable meson build #955

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ sudo: false
dist: trusty

env:
matrix:
- MESON=false
- MESON=true
global:
# COVERITY_SCAN_TOKEN
- secure: "ZD0KxBhO/CaSE/TOkW+H5nsBbaMolbIPv5DgctcjA1BlTckgc5lK4m+7BIR1Fft6gaeeLOoCY3qUm4kW++Bqk2bTsrx/HvrmVmrzMO572jA74x4E+5lynUnRVaAgBg7cVBcB0hZcUurx8FifNBbgnWlxT/nDWttVnglkz400GCE9/zy+VTJWqt4QAB+6qeKPiG3vRthQdWcHstBI8IIAbvp4rhSUajBBQeZ5ro5RPGNy+iHen+t6tyJmbjiP0Y4qjkKGbfwXHnsseEcuSJQuxSkQ9MWK6t93BFXFSPw5MjHIApMn+4CjRp2JMoVTVfe5fFeZEHxVUmAzy+e5eIeftrUtUlCI293UuxZnw/vpJczn3BWunlhhjqjsCwVeknzGHxlaT+ck8Et1Mdl/3nY/E9dt47/NOzXY2xrAz59GYsdKvvsPoCGgNlAub03Vl0W24I1kjppsmN/zFwazHGqoxIBTwrDOQUmZvPfXA3jAUozrfAdT3YjnRcCG7bbQmacFApqfUm/bqMgapAgozjjxpuBrO1wQSUjjH6NANZsP2Gpk0eAl7FOlBzbVgKPxCQozWCjpKOj3HMnXX458ZQWsboG5J00wwjw9DRNRCkeexLdi832L/BPhUY5JgRlTqqyKr9cr69DvogBF/pLytpSCciF6t9NqqGZYbBomXJLaG84="
# COVERALLS_REPO_TOKEN
- secure: "BJUO7GJjP+WgMgSwTTteuc2KKum7Na++92pCLDa3hAzwZZ2OA+MbR9Zd25Yp0kT1K7bIPGDVdg0RksMI9P+Lbun3pajqLWfJpXrAF5IywllQx7bT4x1KeJridJeDnHZVSobTn4oAaGl5JrtpGgXAOjzpgLl1ljP0STyZUF+kC4RSK4Wt2DdT2acj5B8PT6cqR3btfStWgWKlm8t2nOFDGxTCbI4YIwcfgFhOG/ATx7Uc/z08MBI3z7lezy0nBt1/o2gDPZVb4Pa5A390P6Gv0g6mFu1te+P2IFmrWR6mF2Jh5GiJFWR7935rX5d2HxCkCNO7uEmncM4WeDk5PE9+TIcg7T2d9G1JR762aLMvNtUcmlfa6JX/EvveZK47ThwAictwvlD3tgfDy1E7Wdb1O6PtLsUIXRx50UocqBMeSQvOfR1330FuF/td9VGNFqxKW0wDWVIyl8QMK+p7t0aE+2py2Hb3IYVQEk98aWnffvEFeYfNPBywOiVD7trsTFEXKusVypAWDF3kvOmNuetL6ADfPnIfzvPw6DxQzwsxPUo0ahM2C2pzY/MavSlDM8+Q/EZiLkw9g39IgxjDsExD2EEu8U9jyz8iSmbKsrK6Z4L3BWO6a0gFakBAfWR1Rsb15UfVPYlJgPwtAdbgQ65ElgVeyTdkDCuE64iby2nZeP4="
# run coverity scan on gcc build to keep from DOSing coverity
- coverity_scan_run_condition='"$CC" = gcc'
- PKG_CONFIG_PATH="$(pwd)/cmocka/lib/pkgconfig:/usr/lib/pkgconfig"
- LD_LIBRARY_PATH="$(pwd)/cmocka/lib:/usr/lib"
- CMOCKA_CFLAGS="-I$(pwd)/cmocka/include -I/usr/include"
- CMOCKA_LIBS="-L$(pwd)/cmocka/lib -lcmocka"
# COVERITY_SCAN_TOKEN
- secure: "ZD0KxBhO/CaSE/TOkW+H5nsBbaMolbIPv5DgctcjA1BlTckgc5lK4m+7BIR1Fft6gaeeLOoCY3qUm4kW++Bqk2bTsrx/HvrmVmrzMO572jA74x4E+5lynUnRVaAgBg7cVB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ypAWDF3kvOmNuetL6ADfPnIfzvPw6DxQzwsxPUo0ahM2C2pzY/MavSlDM8+Q/EZiLkw9g39IgxjDsExD2EEu8U9jyz8iSmbKsrK6Z4L3BWO6a0gFakBAfWR1Rsb15UfVPYlJgPwtAdbgQ65ElgVeyTdkDCuE64iby2nZeP4="
# run coverity scan on gcc build to keep from DOSing coverity
- coverity_scan_run_condition='"$CC" = gcc'
- PKG_CONFIG_PATH="$(pwd)/cmocka/lib/pkgconfig:/usr/lib/pkgconfig"
- LD_LIBRARY_PATH="$(pwd)/cmocka/lib:/usr/lib"
- CMOCKA_CFLAGS="-I$(pwd)/cmocka/include -I/usr/include"
- CMOCKA_LIBS="-L$(pwd)/cmocka/lib -lcmocka"
- PATH="$(pwd):$PATH"

addons:
apt:
Expand All @@ -30,6 +34,7 @@ addons:
- lcov
- libssl-dev
- uthash-dev
- python3-pip
coverity_scan:
project:
name: "01org/TPM2.0-TSS"
Expand Down Expand Up @@ -61,11 +66,28 @@ install:
- tar xJf autoconf-archive-2017.09.28.tar.xz
- cp autoconf-archive-2017.09.28/m4/ax_code_coverage.m4 m4/
- pip install --user cpp-coveralls
# Trusty's python version is 3.4.x. Meson 0.45++ require python 3.5++
- pip3 install --user meson==0.44.1
# Trusty's ninja is too old
- wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
- sha256sum ninja-linux.zip | grep -q d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07
- unzip ninja-linux.zip

before_script:
- ./bootstrap

script:
# if we are building with meson, only the next 5 lines are executed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not seem to be accurate--it is more than 5 lines that are executed for Meson builds.

- test "$MESON" != "true" || meson builddir -Dtests=true -Dsimulatorbin=$(pwd)/ibmtpm/src/tpm_server
- test "$MESON" != "true" || pushd builddir
- test "$MESON" != "true" || cat meson-logs/meson-log.txt
- test "$MESON" != "true" || meson configure
- test "$MESON" != "true" || ninja
- test "$MESON" != "true" || meson test --setup=sim
- test "$MESON" != "true" || cat meson-logs/testlog-int-log-compiler.sh.txt
- test "$MESON" != "true" || ninja dist || exit 1
- test "$MESON" != "true" || popd
- test "$MESON" != "true" || exit 0
# short-circuit normal build if we've already done a coverity scan
- |
if [ "${COVERITY_SCAN_BRANCH}" == 1 ]; then
Expand Down
16 changes: 16 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ $ docker rm temp

tpm2-tss is now in your working directory and contains all the built files.

## Building with meson

The project now contains initial meson.build files. These are currently
experimental but shall be actively supported in the future.
To build using meson, please run
```
mkdir builddir installdir
meson builddir -Dtests=true -Dsimulatorbin=$PWD/../tpm_server
cd builddir
meson configure
ninja
meson test --setup=sim
ninja dist
ninja install
```

## Doxygen Documentation

To build Doxygen documentation files, first install package Doxygen.
Expand Down
259 changes: 259 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
project('tpm2-tss', 'c',
version : '2.0.0-dev',
license : 'BSD 2-clause',
meson_version : '>= 0.41',
default_options : [
'c_std=c99',
'werror=true',
'b_lundef=true'
] )

################################################################################

subdir('src')
subdir('test')

################################################################################

tctidefault_c_args = []
if get_option('tctidefaultmodule') != ''
tctidefault_c_args += [ '-DESYS_TCTI_DEFAULT_MODULE='+get_option('tctidefaultmodule') ]
endif
if get_option('tctidefaultconfig') != ''
tctidefault_c_args += [ '-DESYS_TCTI_DEFAULT_CONFIG='+get_option('tctidefaultconfig') ]
endif

maxloglevel = get_option('maxloglevel').to_lower()
if maxloglevel == 'trace'
add_project_arguments('-DMAXLOGLEVEL=6', language : 'c')
elif maxloglevel == 'debug'
add_project_arguments('-DMAXLOGLEVEL=5', language : 'c')
elif maxloglevel == 'info'
add_project_arguments('-DMAXLOGLEVEL=4', language : 'c')
elif maxloglevel == 'warning'
add_project_arguments('-DMAXLOGLEVEL=3', language : 'c')
elif maxloglevel == 'error'
add_project_arguments('-DMAXLOGLEVEL=2', language : 'c')
elif maxloglevel == 'none'
add_project_arguments('-DMAXLOGLEVEL=0', language : 'c')
else
error('No maxloglevel set.')
endif

################################################################################

cc = meson.get_compiler('c')
foreach arg : ['-Wall',
'-Wextra',
'-fstack-protector',
'-fstack-protector-strong',
'-fstack-protector-all',
'-fPIE' ]
if cc.has_argument(arg)
add_project_arguments(arg, language : 'c')
endif
endforeach

add_project_arguments('-D_DEFAULT_SOURCE',
'-D_BSD_SOURCE',
'-D_POSIX_SOURCE',
language : 'c')

################################################################################

libdl = cc.find_library('dl')
libgcrypt = cc.find_library('gcrypt')
liburiparser = dependency('liburiparser')
libcrypto = dependency('libcrypto')

################################################################################

tss2_headers = files('''
include/tss2/tss2_common.h
include/tss2/tss2_esys.h
include/tss2/tss2_mu.h
include/tss2/tss2_sys.h
include/tss2/tss2_tcti.h
include/tss2/tss2_tcti_device.h
include/tss2/tss2_tcti_mssim.h
include/tss2/tss2_tpm2_types.h'''.split())

install_headers(tss2_headers, subdir: 'tss2')

################################################################################

incdirs = include_directories('include/tss2', 'src', 'src/util')

libutil = static_library('util', util_sources,
include_directories : incdirs, install : false)

libmu = shared_library('tss2-mu', mu_sources,
include_directories : incdirs,
link_whole : libutil,
install : true)

libdevice = shared_library('tss2-tcti-device', device_sources,
include_directories : incdirs,
link_with : libmu,
install : true)

libmssim = shared_library('tss2-tcti-mssim', mssim_sources,
include_directories : incdirs,
link_with : libmu,
dependencies : liburiparser,
install : true)

libsys = shared_library('tss2-sys', sys_sources,
include_directories : [ incdirs,
include_directories('src/tss2-sys') ],
link_with : libmu,
install : true)

libesys = shared_library('tss2-esys', esys_sources,
include_directories : [ incdirs,
include_directories('src/tss2-sys',
'src/tss2-esys') ],
c_args: tctidefault_c_args,
link_with : [ libdevice, libmssim, libmu, libsys ],
dependencies : [ libgcrypt, libdl ],
install : true)

################################################################################

docdir = join_paths(get_option('datadir'), 'doc', meson.project_name())

install_data('CHANGELOG.md',
'CONTRIBUTING.md',
'INSTALL.md',
'README.md',
'RELEASE.md',
'LICENSE',
'MAINTAINERS',
'doc/archandlayout.md',
'doc/arch.md',
'doc/coding_standard_c.md',
'doc/logging.md',
'doc/TSS block diagram.png',
install_dir : docdir)

cdata = configuration_data()
cdata.set('VERSION', meson.project_version())
cdata.set('PACKAGE_NAME', meson.project_name())
cdata.set('TOP_SRCDIR', meson.source_root())
cdata.set('TOP_BUILDDIR', meson.build_root())

man_pages = []
foreach m: ['tss2-tcti-device.7',
'Tss2_Tcti_Device_Init.3',
'tss2-tcti-mssim.7',
'Tss2_Tcti_Mssim_Init.3']
man_pages += configure_file(input: 'man/'+m+'.in',
output: m,
configuration: cdata)
endforeach

man = custom_target('man',
output : 'man',
input : man_pages,
command : ['echo'])

if get_option('doxygen-docs')
doxygen = find_program('doxygen', required : false)

doxyfile = configure_file(input: 'doc/Doxyfile.in',
output: 'Doxyfile',
configuration: cdata,
install: false)

html_target = custom_target('doxygen-docs',
build_always: true,
input: doxyfile,
output: 'html',
command: [doxygen, doxyfile],
install: true,
install_dir: docdir)
endif

################################################################################

if get_option('tests')

cmocka = dependency('cmocka')
#libuthash = cc.find_library('ut', libtype: 'static')

test_c_args = [ '-Wno-unused-parameter',
'-Wno-missing-field-initializers',
'-Wno-missing-braces' ]

libtestutil = static_library('testutil', testutil_sources,
include_directories : [ incdirs,
include_directories('src/tss2-sys',
'src/tss2-esys') ],
c_args : test_c_args,
link_with : [ libdevice, libmssim, libmu, libsys ],
dependencies: [ libcrypto ])

foreach t: tests_unit
test(t[0], executable(t[0].underscorify(),
[ t[0]+'.c' ] + t[1],
include_directories : [ incdirs,
include_directories('src/tss2-sys'),
include_directories('src/tss2-esys') ],
c_args : t[2] + test_c_args,
link_with : [ libmu, libsys, libesys, libdevice, libmssim ],
link_whole : [ libutil, libtestutil ],
link_args : t[3],
dependencies: [ cmocka, liburiparser ] ))
endforeach

testhelperstartup = executable('test/helper/tpm_startup',
'test/helper/tpm_startup.c',
include_directories : [ incdirs,
include_directories('src/tss2-sys'),
include_directories('test/integration') ],
c_args: test_c_args,
link_with : [ libmu, libsys, libmssim ],
link_whole : [ libutil, libtestutil ],
dependencies: [ cmocka, liburiparser ] )

testhelperstartup = executable('test/helper/tpm_transientempty',
'test/helper/tpm_transientempty.c',
include_directories : [ incdirs,
include_directories('src/tss2-sys'),
include_directories('test/integration') ],
c_args: test_c_args,
link_with : [ libmu, libsys, libmssim ],
link_whole : [ libutil, libtestutil ],
dependencies: [ cmocka, liburiparser ] )

testharness = find_program('script/int-log-compiler.sh')

simulatorbin = get_option('simulatorbin')
if simulatorbin != ''
tpmsim = find_program(simulatorbin)
add_test_setup('sim',
exe_wrapper: [ testharness, '--simulator-bin='+tpmsim.path() ])
endif

foreach t: tests_integration
tsrc = t[1]
if (t[1] == [])
tsrc += [ t[0]+'.c' ]
if (t[0].startswith('test/integration/esys-'))
tsrc += ['test/integration/main-esapi.c']
elif (t[0].startswith('test/integration/'))
tsrc += ['test/integration/main.c']
endif
endif
test(t[0], executable(t[0].underscorify(), tsrc,
include_directories : [ incdirs,
include_directories('src/tss2-sys'),
include_directories('src/tss2-esys') ],
c_args : t[2] + test_c_args,
link_with : [ libmu, libsys, libesys, libdevice, libmssim ],
link_whole : [ libutil, libtestutil ],
link_args : t[3],
dependencies: [ libcrypto ] ) )
endforeach

endif #tests
12 changes: 12 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
option('tctidefaultmodule', type : 'string', value : '',
description : 'The default TCTI module for ESAPI.')
option('tctidefaultconfig', type : 'string', value : '',
description : 'The default tcti modules configuration.')
option('maxloglevel', type : 'string', value : 'trace',
description : 'sets the maximum log level (trace, debug, info, warning, error or none).')
option('tests', type : 'boolean', value : false,
description : 'Enable compilation of tests.')
option('simulatorbin', type : 'string', value : '',
description : 'Set the simulator executable for tests (use meson test --setup=sim).')
option('doxygen-docs', type : 'boolean', value : false,
description : 'Enable doxygen documentation.')
Loading