Skip to content

Commit

Permalink
Add meson build system
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Feb 21, 2025
1 parent bf9daf2 commit be0eafb
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 1 deletion.
30 changes: 30 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project('libomemo-c', 'c', license: 'GPL-3.0', version: '0.5.1', meson_version: '>=1.1.0')

cc = meson.get_compiler('c')


c_args = []
if cc.has_function('SecureZeroMemory', prefix: '#include <Windows.h>')
c_args += ['-DSECUREZEROMEMORY']
endif
if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
c_args += ['-fmessage-length=0', '-Wall', '-Wmissing-field-initializers', '-Wno-missing-braces', '-Wparentheses']
endif
if cc.get_id() == 'gcc'
c_args += ['-Wsign-compare']
if cc.has_argument('-Wsign-conversion')
c_args += ['-Wsign-conversion']
endif
endif
if cc.get_id() == 'clang'
c_args += ['-Wswitch', '-Wunused-variable', '-Wunused-value', '-Wshadow', '-Wint-conversion', '-Wpointer-sign', '-Wprotocol', '-Wshorten-64-to-32']
endif
if cc.has_function('memset_s', prefix: '#include <string.h>')
c_args += ['-DHAVE_MEMSET_S']
endif

subdir('protobuf')
subdir('src')
if get_option('tests')
subdir('tests')
endif
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('tests', type: 'boolean', value: true, description: 'Whether to compile unit tests')
30 changes: 30 additions & 0 deletions protobuf/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
protobuf_c = dependency('libprotobuf-c')

protoc = find_program('protoc')
if not protoc.found()
protoc = find_program('protoc-c')
endif

protobuf_proto_names = [
'LocalStorageProtocol',
'WhisperTextProtocol',
'OMEMO',
]

protobuf_proto_sources = []
protobuf_c_sources = []
protobuf_c_headers = []
foreach name : protobuf_proto_names
protobuf_proto_sources += files(name + '.proto')
protobuf_c_sources += [name + '.pb-c.c']
protobuf_c_headers += [name + '.pb-c.h']
endforeach

protobuf_c_sources = custom_target(
'protobuf_c_sources',
command: [protoc, '--proto_path=@CURRENT_SOURCE_DIR@', '--c_out=@OUTDIR@', '@INPUT@'],
input: protobuf_proto_sources,
output: [protobuf_c_sources, protobuf_c_headers]
)

protobuf_dep = declare_dependency(dependencies: protobuf_c, sources: protobuf_c_sources, include_directories: include_directories('.'))
107 changes: 107 additions & 0 deletions src/curve25519/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
curve25519_c_args = c_args
if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
curve25519_c_args += ['-Wno-unused-variable', '-Wno-unused-function', '-Wno-shadow']
endif
if cc.get_id() == 'gcc'
curve25519_c_args += ['-Wno-sign-compare']
if cc.has_argument('-Wno-sign-conversion')
curve25519_c_args += ['-Wno-sign-conversion']
endif
endif
if cc.get_id() == 'clang'
curve25519_c_args += ['-Wno-shorten-64-to-32']
endif
if cc.has_function('memset_s', prefix: '#include <string.h>')
curve25519_c_args += ['-DHAVE_MEMSET_S']
endif

curve25519_sources = files([
'curve25519-donna.c'
])

ed25519_include_directories = [
'ed25519/nacl_includes',
'ed25519/additions',
'ed25519/additions/generalized',
'ed25519/tests',
'ed25519',
]

ed25519_sources = files([
'ed25519/fe_0.c',
'ed25519/fe_1.c',
'ed25519/fe_add.c',
'ed25519/fe_cmov.c',
'ed25519/fe_copy.c',
'ed25519/fe_frombytes.c',
'ed25519/fe_invert.c',
'ed25519/fe_isnegative.c',
'ed25519/fe_isnonzero.c',
'ed25519/fe_mul.c',
'ed25519/fe_neg.c',
'ed25519/fe_pow22523.c',
'ed25519/fe_sq.c',
'ed25519/fe_sq2.c',
'ed25519/fe_sub.c',
'ed25519/fe_tobytes.c',
'ed25519/ge_add.c',
'ed25519/ge_double_scalarmult.c',
'ed25519/ge_frombytes.c',
'ed25519/ge_madd.c',
'ed25519/ge_msub.c',
'ed25519/ge_p1p1_to_p2.c',
'ed25519/ge_p1p1_to_p3.c',
'ed25519/ge_p2_0.c',
'ed25519/ge_p2_dbl.c',
'ed25519/ge_p3_0.c',
'ed25519/ge_p3_dbl.c',
'ed25519/ge_p3_to_cached.c',
'ed25519/ge_p3_to_p2.c',
'ed25519/ge_p3_tobytes.c',
'ed25519/ge_precomp_0.c',
'ed25519/ge_scalarmult_base.c',
'ed25519/ge_sub.c',
'ed25519/ge_tobytes.c',
'ed25519/open.c',
'ed25519/sc_muladd.c',
'ed25519/sc_reduce.c',
'ed25519/sign.c',
'ed25519/additions/compare.c',
'ed25519/additions/curve_sigs.c',
'ed25519/additions/ed_sigs.c',
'ed25519/additions/elligator.c',
'ed25519/additions/fe_edy_to_montx.c',
'ed25519/additions/fe_isequal.c',
'ed25519/additions/fe_isreduced.c',
'ed25519/additions/fe_mont_rhs.c',
'ed25519/additions/fe_montx_to_edy.c',
'ed25519/additions/fe_sqrt.c',
'ed25519/additions/ge_isneutral.c',
'ed25519/additions/ge_montx_to_p3.c',
'ed25519/additions/ge_neg.c',
'ed25519/additions/ge_p3_to_montx.c',
'ed25519/additions/ge_scalarmult.c',
'ed25519/additions/ge_scalarmult_cofactor.c',
'ed25519/additions/keygen.c',
'ed25519/additions/open_modified.c',
'ed25519/additions/sc_clamp.c',
'ed25519/additions/sc_cmov.c',
'ed25519/additions/sc_neg.c',
'ed25519/additions/sign_modified.c',
'ed25519/additions/utility.c',
'ed25519/additions/generalized/ge_p3_add.c',
'ed25519/additions/generalized/gen_eddsa.c',
'ed25519/additions/generalized/gen_labelset.c',
'ed25519/additions/generalized/gen_veddsa.c',
'ed25519/additions/generalized/gen_x.c',
'ed25519/additions/generalized/point_isreduced.c',
'ed25519/additions/generalized/sc_isreduced.c',
'ed25519/additions/xeddsa.c',
'ed25519/additions/zeroize.c',
'ed25519/nacl_sha512/blocks.c',
'ed25519/nacl_sha512/hash.c',
'ed25519/tests/internal_fast_tests.c',
])

curve25519_lib = library('curve25519', curve25519_sources, ed25519_sources, c_args: curve25519_c_args, include_directories: ed25519_include_directories, install: false)
curve25519_dep = declare_dependency(objects: curve25519_lib.extract_all_objects(recursive: false), include_directories: ed25519_include_directories)
81 changes: 81 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
subdir('curve25519')

libomemo_c_include_directories = [
'curve25519/ed25519/nacl_includes',
'curve25519/ed25519/additions',
'curve25519/ed25519/additions/generalized',
'curve25519/ed25519/tests',
'curve25519/ed25519',
'curve25519',
'.',
]

libomemo_c_sources = files([
'vpool.c',
'vpool.h',
'signal_protocol.c',
'signal_protocol.h',
'signal_protocol_types.h',
'signal_protocol_internal.h',
'curve.c',
'curve.h',
'hkdf.c',
'hkdf.h',
'ratchet.c',
'ratchet.h',
'protocol.c',
'protocol.h',
'session_state.c',
'session_state.h',
'session_record.c',
'session_record.h',
'session_pre_key.c',
'session_pre_key.h',
'session_builder.c',
'session_builder.h',
'session_builder_internal.h',
'session_cipher.c',
'session_cipher.h',
'key_helper.c',
'key_helper.h',
'sender_key.c',
'sender_key.h',
'sender_key_state.c',
'sender_key_state.h',
'sender_key_record.c',
'sender_key_record.h',
])

libomemo_c_headers = files([
'signal_protocol.h',
'signal_protocol_types.h',
'curve.h',
'hkdf.h',
'ratchet.h',
'protocol.h',
'session_state.h',
'session_record.h',
'session_pre_key.h',
'session_builder.h',
'session_cipher.h',
'key_helper.h',
'sender_key.h',
'sender_key_state.h',
'sender_key_record.h',
])

libomemo_c_lib = library(
'libomemo-c',
libomemo_c_sources,
include_directories: libomemo_c_include_directories,
c_args: c_args,
dependencies: [cc.find_library('m', required: false), protobuf_dep, curve25519_dep],
install: true,
version: meson.project_version(),
name_prefix: '',
)
libomemo_c_dep = declare_dependency(link_with: libomemo_c_lib, include_directories: include_directories('.'))

install_headers(libomemo_c_headers, subdir: 'omemo')

import('pkgconfig').generate(libomemo_c_lib, description: 'OMEMO C Library', subdirs: 'omemo')
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enable_testing()
find_library(M_LIB m)
find_library(PBC_LIB protobuf-c)
find_library(PBC_LIB protobuf-c REQUIRED)
find_package(Check 0.9.10 REQUIRED)
IF(NOT(APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
find_package(OpenSSL 1.0 REQUIRED)
Expand Down Expand Up @@ -46,6 +46,8 @@ set(common_SRCS
test_common.h
)

message("LIB " ${PBC_LIB})

include_directories(. ../src)

IF(APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down
43 changes: 43 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
tests_dependencies = [libomemo_c_dep]
tests_dependencies += dependency('check')
if host_machine.system() != 'darwin'
tests_dependencies += dependency('openssl')
endif

tests_c_args = c_args
if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
tests_c_args += ['-Wno-unused-function']
endif
if cc.get_id() == 'gcc'
tests_c_args += ['-Wno-sign-compare']
if cc.has_argument('-Wno-sign-conversion')
tests_c_args += ['-Wno-sign-conversion']
endif
endif
if cc.get_id() == 'clang'
tests_c_args += ['-Wno-invalid-source-encoding', '-Wno-shorten-64-to-32']
endif

common_test_sources = files(['test_common.c'])
if host_machine.system() == 'darwin'
common_test_sources += files(['test_common_ccrypto.c'])
else
common_test_sources += files(['test_common_openssl.c'])
endif

tests = [
'test_curve25519',
'test_hkdf',
'test_ratchet',
'test_protocol',
'test_session_record',
'test_session_cipher',
'test_session_builder',
'test_key_helper',
'test_simultaneous_initiate',
'test_sender_key_record',
]

foreach name : tests
test(name, executable(name, name + '.c', common_test_sources, c_args: tests_c_args, dependencies: tests_dependencies))
endforeach

0 comments on commit be0eafb

Please # to comment.