Skip to content

Commit

Permalink
build: add support for meson
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Morgner <frankmorgner@gmail.com>
Co-authored-by: Jussi Pakkanen <jpakkane@gmail.com>
  • Loading branch information
3 people committed Apr 26, 2024
1 parent fe2c1c8 commit e5b97bb
Show file tree
Hide file tree
Showing 21 changed files with 1,250 additions and 8 deletions.
66 changes: 66 additions & 0 deletions doc/tools/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
if progxsltproc.found()
sources = [
'cardos-tool.1.xml',
'cryptoflex-tool.1.xml',
'dnie-tool.1.xml',
'dtrust-tool.1.xml',
'egk-tool.1.xml',
'eidenv.1.xml',
'gids-tool.1.xml',
'goid-tool.1.xml',
'iasecc-tool.1.xml',
'netkey-tool.1.xml',
'npa-tool.1.xml',
'openpgp-tool.1.xml',
'opensc-asn1.1.xml',
'opensc-explorer.1.xml',
'opensc-notify.1.xml',
'opensc-tool.1.xml',
'piv-tool.1.xml',
'pkcs11-register.1.xml',
'pkcs11-tool.1.xml',
'pkcs15-crypt.1.xml',
'pkcs15-init.1.xml',
'pkcs15-tool.1.xml',
'sc-hsm-tool.1.xml',
'westcos-tool.1.xml'
]

if get_option('man')
foreach xml : sources
custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc:' + stylesheets_path / 'manpages',
'--xinclude',
'-o', '@OUTPUT@',
'man.xsl',
'@INPUT@'
],
input: xml,
output: modfs.replace_suffix(xml, ''),
build_by_default: true,
install: true,
install_dir: get_option('mandir') / 'man1'
)
endforeach
endif

if get_option('doc')
custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc:' + stylesheets_path / 'html',
'--xinclude',
'-o', '@OUTPUT@',
'html.xsl',
'@INPUT@'
],
input: sources,
output: 'tools.html',
build_by_default: true,
install: true,
install_dir: get_option('datadir') / 'doc' / 'opensc'
)
endif
endif
44 changes: 44 additions & 0 deletions etc/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
install_data(
'opensc.conf',
install_dir: get_option('sysconfdir')
)

conf_etc = configuration_data()
conf_etc.set_quoted('pkgdatadir', get_option('prefix') / get_option('datadir') / 'opensc')
conf_etc.set_quoted('DEFAULT_PCSC_PROVIDER', conf.get_unquoted('DEFAULT_PCSC_PROVIDER'))
conf_etc.set_quoted('DEFAULT_SM_MODULE', conf.get_unquoted('DEFAULT_SM_MODULE'))
conf_etc.set_quoted('DEFAULT_SM_MODULE_PATH', conf.get_unquoted('DEFAULT_SM_MODULE_PATH'))
conf_etc.set_quoted('DYN_LIB_EXT', '.' + extension_of_libraries)
conf_etc.set_quoted('LIB_PRE', prefix_of_libraries)
conf_etc.set_quoted('LIBDIR', get_option('prefix') / get_option('libdir'))

if host_machine.system() == 'windows' or host_machine.system() == 'cygwin'
conf_etc.set_quoted('DEBUG_FILE', '%TEMP%\\opensc-debug.log')
conf_etc.set_quoted('PROFILE_DIR_DEFAULT', 'obtained from windows registers')
conf_etc.set_quoted('PROFILE_DIR', '')
else
conf_etc.set_quoted('DEBUG_FILE', '/tmp/opensc-debug.log')
conf_etc.set_quoted('PROFILE_DIR_DEFAULT', get_option('prefix') / get_option('datadir') / 'opensc')
conf_etc.set_quoted('PROFILE_DIR', get_option('prefix') / get_option('datadir') / 'opensc')
endif

configure_file(
configuration: conf_etc,
input: 'opensc.conf.example.in',
output: 'opensc.conf',
install: true,
install_dir: get_option('datadir') / 'doc' / 'opensc'
)

if conf.get('ENABLE_OPENPACE')
path = get_option('datadir') / 'opensc' / 'cvc'
if cv_certificates_path.startswith(get_option('prefix'))
path = cv_certificates_path
endif
install_data(
'DESRCACC100001',
'DESCHSMCVCA00001',
install_dir: path
)
unset_variable('path')
endif
277 changes: 277 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
project('opensc', 'c',
version: '0.25.1',
license: 'LGPLv2.1+',
default_options: 'c_std=none',
meson_version: '>= 0.62'
)

modpkgconfig = import('pkgconfig')
modfs = import('fs')

all_languages = ['c']
if host_machine.system() == 'windows'
add_languages('cpp')
all_languages += 'cpp'
elif host_machine.system() == 'darwin'
add_languages('objc')
all_languages += 'objc'
endif

prefix_of_libraries = 'lib'
if host_machine.system() == 'cygwin'
prefix_of_libraries = 'cyg'
elif meson.get_compiler('c').get_id() == 'msvc'
prefix_of_libraries = ''
endif

extension_of_libraries = 'so'
if host_machine.system() == 'windows'
extension_of_libraries = 'dll'
elif host_machine.system() == 'darwin'
extension_of_libraries = 'dylib'
endif

#################################################
# Dependencies and configuration
#################################################
conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
conf.set_quoted('PACKAGE_NAME', 'OpenSC')
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set_quoted('OPENSC_VS_FF_COMPANY_NAME', 'OpenSC project')
conf.set_quoted('OPENSC_VS_FF_PRODUCT_NAME', 'OpenSC smartcard framework')
conf.set_quoted('VS_FF_LEGAL_COPYRIGHT', 'OpenSC Project')
conf.set_quoted('VS_FF_LEGAL_COMPANY_NAME', 'OpenSC Project')
conf.set_quoted('VS_FF_LEGAL_COMPANY_URL', 'https://github.com/OpenSC')
conf.set_quoted('VS_FF_COMMENTS', 'Provided under the terms of the GNU Lesser General Public License (LGPLv2.1+).')
conf.set_quoted('VS_FF_PRODUCT_NAME', 'OpenSC smartcard framework')
conf.set_quoted('VS_FF_PRODUCT_UPDATES', 'https://github.com/OpenSC/OpenSC/releases')
conf.set_quoted('VS_FF_PRODUCT_URL', 'https://github.com/OpenSC/OpenSC')
conf.set_quoted('SC_PKCS15_PROFILE_DIRECTORY', get_option('prefix') / get_option('datadir') / 'opensc')
conf.set_quoted('OPENSC_CONF_PATH', get_option('prefix') / get_option('sysconfdir') / 'opensc.conf')
conf.set_quoted('DEFAULT_SM_MODULE', prefix_of_libraries + 'smm-local.' + extension_of_libraries)

project_version = meson.project_version().split('.')
conf.set('OPENSC_VERSION_MAJOR', project_version[0])
conf.set('OPENSC_VERSION_MINOR', project_version[1])
conf.set('OPENSC_VERSION_FIX', project_version[2])

if host_machine.system() == 'windows' or host_machine.system() == 'cygwin'
conf.set_quoted('DEFAULT_PCSC_PROVIDER', 'winscard.dll')
conf.set_quoted('DEFAULT_SM_MODULE_PATH', '%PROGRAMFILES%\\OpenSC Project\\OpenSC\\tools')
conf.set_quoted('PKCS11_REGISTER_SKIP_FIREFOX', 'on')

elif host_machine.system() == 'darwin'
conf.set_quoted('DEFAULT_PCSC_PROVIDER', '/System/Library/Frameworks/PCSC.framework/PCSC')
conf.set_quoted('DEFAULT_SM_MODULE_PATH', get_option('prefix') / get_option('libdir'))
conf.set_quoted('PKCS11_REGISTER_SKIP_FIREFOX', 'on')

else
conf.set_quoted('DEFAULT_PCSC_PROVIDER', 'libpcsclite.so.1')
conf.set_quoted('DEFAULT_SM_MODULE_PATH', get_option('prefix') / get_option('libdir'))
conf.set_quoted('PKCS11_REGISTER_SKIP_FIREFOX', 'off')
endif

conf.set('ENABLE_MINIDRIVER', get_option('components').contains('minidriver'))
conf.set('ENABLE_SM', get_option('components').contains('sm'))

conf.set('ENABLE_PCSC', false)
conf.set('ENABLE_CRYPTOTOKENKIT', false)
conf.set('ENABLE_OPENCT', false)
conf.set('ENABLE_CTAPI', false)
conf.set('HAVE_WINSCARD_H', false)
conf.set('HAVE_PCSCLITE_H', false)

if get_option('driver') == 'pcsc'
conf.set('ENABLE_PCSC', true)
deppcsclite = dependency('libpcsclite', version: '>= 1.8.22')
conf.set('HAVE_WINSCARD_H', meson.get_compiler('c').has_header('winscard.h', dependencies: deppcsclite))
conf.set('HAVE_PCSCLITE_H', meson.get_compiler('c').has_header('pcsclite.h', dependencies: deppcsclite))

elif get_option('driver') == 'crypttokenkit'
conf.set('ENABLE_CRYPTOTOKENKIT', true)
depcryptotokenkit = dependency('appleframeworks', modules: 'CryptoTokenKit')

elif get_option('driver') == 'openct'
conf.set('ENABLE_OPENCT', true)
depopenct = dependency('openct')

elif get_option('driver') == 'ctapi'
conf.set('ENABLE_CTAPI', true)

else
error('The option "driver" has unknown value')
endif

depopenpace = dependency('libeac', version: '>= 0.9', required: get_option('openpace'))
conf.set('ENABLE_OPENPACE', depopenpace.found())
if depopenpace.found()
cv_certificates_path = depopenpace.get_variable('cvcdir')
conf.set_quoted('CVCDIR', cv_certificates_path)
x509_certificates_path = depopenpace.get_variable('x509dir')
conf.set_quoted('X509DIR', x509_certificates_path)
endif

depopenssl = dependency('openssl', version: '>= 1.1.1', required: get_option('openssl'))
conf.set('ENABLE_OPENSSL', depopenssl.found())

depreadline = dependency('readline', required: get_option('readline'))
conf.set('ENABLE_READLINE', depreadline.found())

depzlib = dependency('zlib', required: get_option('zlib'))
conf.set('ENABLE_ZLIB', depzlib.found())

depcorefoundation = dependency('appleframeworks', modules: 'CoreFoundation', required: get_option('dnie_ui'))
conf.set('ENABLE_DNIE_UI', depcorefoundation.found())

depthreads = dependency('threads', required: false)
conf.set('HAVE_PTHREAD', depthreads.found())

depgio2 = dependency('gio-2.0', required: false)
conf.set('ENABLE_GIO2', depgio2.found())

conf.set('ENABLE_NOTIFY', get_option('notify'))
conf.set('PKCS11_THREAD_LOCKING', get_option('thread_locking'))
conf.set('ENABLE_PIV_SM', get_option('piv_sm'))

depdl = dependency('dl')

conf.set_quoted('DEFAULT_PKCS11_PROVIDER', '')
conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', '')
if get_option('components').contains('pkcs11')
depp11kit = dependency('p11-kit-1', required: false)
if depp11kit.found()
p11kit_modules_path = depp11kit.get_variable('p11_module_path')
p11kit_configs_path = depp11kit.get_variable('p11_module_configs')

conf.set_quoted('DEFAULT_PKCS11_PROVIDER', p11kit_modules_path / 'opensc-pkcs11.' + extension_of_libraries)
conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', p11kit_modules_path / 'opensc-pkcs11.' + extension_of_libraries)
else
if get_option('default_library') != 'static'
conf.set_quoted('DEFAULT_PKCS11_PROVIDER', get_option('prefix') / get_option('libdir') / prefix_of_libraries + 'opensc-pkcs11.' + extension_of_libraries)
conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', get_option('prefix') / get_option('libdir') / prefix_of_libraries + 'opensc-pkcs11.' + extension_of_libraries)
endif
endif
endif

conf.set('HAVE_INTTYPES_H', meson.get_compiler('c').has_header('inttypes.h'))
conf.set('HAVE_STRING_H', meson.get_compiler('c').has_header('string.h'))
conf.set('HAVE_STRINGS_H', meson.get_compiler('c').has_header('strings.h'))
conf.set('HAVE_SYS_TIME_H', meson.get_compiler('c').has_header('sys' / 'time.h'))
conf.set('HAVE_SYS_MMAN_H', meson.get_compiler('c').has_header('sys' / 'mman.h'))
conf.set('HAVE_SYS_ENDIAN_H', meson.get_compiler('c').has_header('sys' / 'endian.h'))
conf.set('HAVE_UNISTD_H', meson.get_compiler('c').has_header('unistd.h'))
conf.set('HAVE_ENDIAN_H', meson.get_compiler('c').has_header('endian.h'))

conf.set('HAVE_GETPASS', meson.get_compiler('c').has_function('getpass'))
conf.set('HAVE_GETTIMEOFDAY', meson.get_compiler('c').has_function('gettimeofday'))
conf.set('HAVE_GETLINE', meson.get_compiler('c').has_function('getline'))
conf.set('HAVE_MEMSET_S', meson.get_compiler('c').has_function('memset_s'))
conf.set('HAVE_EXPLICIT_BZERO', meson.get_compiler('c').has_function('explicit_bzero'))
conf.set('HAVE_STRNLEN', meson.get_compiler('c').has_function('strnlen'))
conf.set('HAVE_SIGACTION', meson.get_compiler('c').has_function('sigaction'))
conf.set('HAVE_BUILTIN_OVERFLOW', meson.get_compiler('c').has_function('__builtin_uadd_overflow'))

opensc_features = ''
opensc_features += conf.get('PKCS11_THREAD_LOCKING')? ' locking' : ''
opensc_features += conf.get('ENABLE_OPENPACE')? ' openpace' : ''
opensc_features += conf.get('ENABLE_OPENSSL')? ' openssl' : ''
opensc_features += conf.get('ENABLE_READLINE')? ' readline' : ''
opensc_features += conf.get('ENABLE_ZLIB')? ' zlib' : ''
opensc_features += conf.get('ENABLE_PCSC')? ' pcsc(@0@)'.format(conf.get_unquoted('DEFAULT_PCSC_PROVIDER')) : ''
opensc_features += conf.get('ENABLE_CRYPTOTOKENKIT')? ' cryptotokenkit' : ''
opensc_features += conf.get('ENABLE_OPENCT')? ' openct' : ''
opensc_features += conf.get('ENABLE_CTAPI')? ' ctapi' : ''
conf.set_quoted('OPENSC_FEATURES', opensc_features.strip())
unset_variable('opensc_features')

proggit = find_program('git', required: false)
if proggit.found()
description = run_command(proggit, 'describe', check: true).stdout().strip()
if description == ''
description = run_command(proggit, 'describe', '--tags', check: true).stdout().strip()
endif
hash_commit_date = run_command(proggit, 'log', '-1', '--pretty=format:rev: %h, commit-time: %ci', check: true).stdout().strip()
tag_commit = run_command(proggit, 'rev-list', '--tags', '--no-walk', '--max-count=1', check: true).stdout().strip()
revision = run_command(proggit, 'rev-list', tag_commit + '..HEAD', '--count', check: true).stdout().strip()

conf.set_quoted('OPENSC_SCM_REVISION', 'OpenSC-@0@, @1@'.format(description, hash_commit_date))
conf.set_quoted('OPENSC_VERSION_REVISION', revision)

unset_variable('description')
unset_variable('hash_commit_date')
unset_variable('tag_commit')
unset_variable('revision')
else
conf.set_quoted('OPENSC_SCM_REVISION', '<revision is unavailable>')
conf.set_quoted('OPENSC_VERSION_REVISION', '0')
endif

progxsltproc = find_program('xsltproc', required: false)
if progxsltproc.found()
stylesheets_path = get_option('xsl_stylesheets_path')
if stylesheets_path == ''
foreach path : [
'/usr/share/xml/docbook/stylesheet/nwalsh',
'/usr/share/xml/docbook/stylesheet/nwalsh/current',
'/opt/local/share/xsl/docbook-xsl',
'/sw/share/xml/xsl/docbook-xsl' ]

if modfs.exists(path / 'html' / 'docbook.xsl')
stylesheets_path = path
break
endif
endforeach
else
if not modfs.exists(stylesheets_path / 'html' / 'docbook.xsl')
error('The file @0@ does not exist'.format(stylesheets_path / 'html' / 'docbook.xsl'))
endif
endif
endif

configure_file(
output: 'config.h',
configuration: conf
)
add_project_arguments('-DHAVE_CONFIG_H', language: all_languages)

#################################################
# Build targets
#################################################
core_inc = include_directories('.', 'src')

subdir('src' / 'common')
subdir('src' / 'scconf')
subdir('src' / 'ui')
subdir('src' / 'pkcs15init')
subdir('src' / 'sm')
subdir('src' / 'libopensc')

if get_option('components').contains('pkcs11')
subdir('src' / 'pkcs11')
endif

if get_option('components').contains('tools')
subdir('src' / 'tools')
endif

if get_option('components').contains('minidriver')
subdir('src' / 'minidriver')
endif

if get_option('components').contains('sm')
subdir('src' / 'smm')
endif

subdir('etc')
subdir('doc' / 'tools')

if get_option('tests')
subdir('src' / 'tests')
#subdir('tests')
endif

#################################################
# Summary
#################################################

0 comments on commit e5b97bb

Please sign in to comment.