Skip to content
Open
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
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ jobs:
exit 0
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

meson-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y meson ninja-build pkg-config openssl libssl-dev

- name: meson build
run: |
meson setup build --prefix=/usr
meson compile -C build
meson test -C build
meson dist -C build
tar -tf build/meson-dist/*.tar.xz
25 changes: 25 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ For patch submissions, please use a Signed-off-by: <your email> to indicate
agreement to the DCO1.1.txt.


Building
--------

There are two build systems available for libtpms: autotools and meson.
The GitHub CI runs builds using both build systems.

### Autotools

To build with autotools, run the following commands:

$ ./autogen.sh --with-openssl --prefix=/usr --with-tpm2
$ make
$ make check
$ sudo make install

### Meson

To build with meson, run the following commands:

$ meson setup build --prefix=/usr
Copy link
Owner

Choose a reason for hiding this comment

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

Add pip install meson here maybe? Do we need ninja to build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or maybe we add link to https://mesonbuild.com/Quick-guide.html

$ meson compile -C build
$ meson test -C build
$ sudo meson install -C build


Fuzzing
-------
Initial fuzzing is possible with clang & libfuzzer.
Expand Down
15 changes: 15 additions & 0 deletions include/libtpms/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tpm_library_h = configure_file(
input: 'tpm_library.h.in',
output: 'tpm_library.h',
configuration: conf_data,
)

install_headers(
'tpm_error.h',
'tpm_memory.h',
'tpm_nvfilename.h',
'tpm_tis.h',
'tpm_types.h',
tpm_library_h,
subdir: 'libtpms'
)
1 change: 1 addition & 0 deletions include/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subdir('libtpms')
37 changes: 37 additions & 0 deletions man/man3/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pod_files = [
'TPM_IO_Hash_Start.pod',
'TPM_IO_TpmEstablished_Get.pod',
'TPM_Malloc.pod',
'TPMLIB_CancelCommand.pod',
'TPMLIB_ChooseTPMVersion.pod',
'TPMLIB_DecodeBlob.pod',
'TPMLIB_GetInfo.pod',
'TPMLIB_GetTPMProperty.pod',
'TPMLIB_GetVersion.pod',
'TPMLIB_MainInit.pod',
'TPMLIB_Process.pod',
'TPMLIB_RegisterCallbacks.pod',
'TPMLIB_SetBufferSize.pod',
'TPMLIB_SetDebugFD.pod',
'TPMLIB_SetProfile.pod',
'TPMLIB_SetState.pod',
'TPMLIB_ValidateState.pod',
'TPMLIB_VolatileAll_Store.pod',
'TPMLIB_WasManufactured.pod',
]

pod2man = find_program('pod2man', required: true)

foreach pod : pod_files
base_name = pod.split('.')[0]
target_name = base_name + '.3'

custom_target(target_name,
input: pod,
output: target_name,
command: [pod2man, '-r', 'libtpms', '-c', '""', '-n', base_name, '--section=3', '@INPUT@', '@OUTPUT@'],
capture: false,
install: true,
install_dir: get_option('mandir') / 'man3'
)
endforeach
1 change: 1 addition & 0 deletions man/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subdir('man3')
97 changes: 97 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
project(
'libtpms', ['c', 'cpp'],
version: '0.11.0',
license: 'BSD-3-Clause AND LicenseRef-TCGL',
default_options: ['c_std=c99', 'warning_level=1', 'werror=true'],
meson_version: '>=1.1',
)

c_compiler = meson.get_compiler('c')

# Add an include directory that points to the build directory.
add_project_arguments('-I' + meson.current_build_dir(), language: 'c')

# Add common warning flags
warning_flags = [
'-Wshadow',
'-Wreturn-type',
'-Wsign-compare',
'-Wno-self-assign',
'-Wmissing-prototypes'
]
supported_warning_flags = c_compiler.get_supported_arguments(warning_flags)
add_project_arguments(supported_warning_flags, language: 'c')

# Get build options
with_tpm1 = get_option('tpm1')
with_tpm2 = get_option('tpm2')
crypto_backend = get_option('crypto_backend')

if crypto_backend == 'openssl'
add_project_arguments(['-DUSE_OPENSSL_CRYPTO_LIBRARY=1'], language: 'c')
else
add_project_arguments(['-DUSE_FREEBL_CRYPTO_LIBRARY=1'], language: 'c')
endif

# Add hardening flags for non-plain build types
if get_option('buildtype') != 'plain'
hardening_c_flags = []
# Stack protector
if c_compiler.has_argument('-fstack-protector-strong')
hardening_c_flags += '-fstack-protector-strong'
elif c_compiler.has_argument('-fstack-protector')
hardening_c_flags += '-fstack-protector'
endif
# Fortify source only works with optimization
if get_option('optimization') != '0'
if c_compiler.has_argument('-D_FORTIFY_SOURCE=2')
hardening_c_flags += '-D_FORTIFY_SOURCE=2'
endif
endif
add_project_arguments(hardening_c_flags, language: 'c')

hardening_ld_flags = []
# Linker hardening
if c_compiler.has_link_argument('-Wl,-z,relro')
hardening_ld_flags += '-Wl,-z,relro'
endif
if c_compiler.has_link_argument('-Wl,-z,now')
hardening_ld_flags += '-Wl,-z,now'
endif
add_project_link_arguments(hardening_ld_flags, language: 'c')
endif

# Versioning
libtpms_version = meson.project_version()
libtpms_version_arr = libtpms_version.split('.')
libtpms_ver_major = libtpms_version_arr[0].to_int()
libtpms_ver_minor = libtpms_version_arr[1].to_int()
libtpms_ver_micro = libtpms_version_arr[2].to_int()

# Create a configuration header file
conf_data = configuration_data()
conf_data.set('PACKAGE_VERSION', '"' + meson.project_version() + '"')
conf_data.set('LIBTPMS_VER_MAJOR', libtpms_ver_major)
conf_data.set('LIBTPMS_VER_MINOR', libtpms_ver_minor)
conf_data.set('LIBTPMS_VER_MICRO', libtpms_ver_micro)

# config.h could be dropped if when autotools is removed
configure_file(
output: 'config.h',
configuration: conf_data
)

# Add subdirectories to the build
subdir('include')
subdir('src')
subdir('man')
subdir('tests')

summary_info = {}
summary_info += {'Build directory': meson.current_build_dir()}
summary_info += {'Source path': meson.current_source_dir()}
summary_info += {'TPM1': with_tpm1}
summary_info += {'TPM2': with_tpm2}
summary_info += {'Crypto backend': crypto_backend}

summary(summary_info, bool_yn: true, section: 'Build configuration')
6 changes: 6 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

option('tpm1', type: 'boolean', value: true, description: 'Build with TPM 1.2 support.')
option('tpm2', type: 'boolean', value: true, description: 'Build with TPM 2.0 support.')
option('crypto_backend', type: 'combo', choices: ['openssl', 'freebl'], value: 'openssl', description: 'Choose the cryptographic backend.')
option('use_openssl_functions', type: 'boolean', value: true, description: 'Use OpenSSL functions for crypto instead of internal code.')
option('fuzzing_engine', type: 'boolean', value: false, description: 'Build with fuzzing engine')
Loading