Skip to content

Commit ced8f7b

Browse files
committed
Add Meson build system
Allows to build libical using Meson build system
1 parent 4bf9a2d commit ced8f7b

File tree

7 files changed

+383
-1
lines changed

7 files changed

+383
-1
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ indent_style = space
33
indent_size = 2
44
max_line_length = 120
55

6-
[{*.cmake,CMakeLists.txt}]
6+
[{*.cmake,CMakeLists.txt,meson.build,meson.options}]
77
indent_style = space
88
indent_size = 2

design-data/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ical_parameters_design = files('ical-parameters.csv')
2+
ical_properties_design = files('ical-properties.csv')
3+
ical_value_types_design = files('ical-value-types.csv')
4+
ical_restrictions_design = files('ical-restrictions.csv')

meson.build

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# SPDX-FileCopyrightText: Corentin Noël <[email protected]>
2+
# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
3+
project(
4+
'libical',
5+
'c',
6+
version: '3.99.99',
7+
license: 'MPL-2.0 OR LGPL-2.1-only',
8+
license_files: 'LICENSE.txt',
9+
meson_version: '>=1.1',
10+
)
11+
12+
lib_major_soversion = '4'
13+
lib_soversion_string = '@[email protected]'.format(lib_major_soversion)
14+
project_version = '4.0'
15+
project_url = 'https://libical.github.io/libical/'
16+
17+
languages = ['c']
18+
cxx_bindings_enabled = add_languages('cpp', native: false, required: get_option('cxx_bindings'))
19+
if cxx_bindings_enabled
20+
languages += 'cpp'
21+
endif
22+
23+
pkg = import('pkgconfig')
24+
cc = meson.get_compiler('c')
25+
26+
icu_uc_dep = dependency('icu-uc', required: false)
27+
icu_i18n_dep = dependency('icu-i18n', required: false)
28+
if (icu_uc_dep.found())
29+
icu_binary_dir = icu_uc_dep.get_variable('exec_prefix', default_value: get_option('prefix')) / 'sbin'
30+
endif
31+
32+
33+
# Config checks
34+
config_data = configuration_data()
35+
config_data.set('CMAKE_PROJECT_HOMEPAGE_URL', project_url)
36+
config_data.set('CMAKE_PROJECT_NAME', meson.project_name())
37+
config_data.set('PROJECT_VERSION', project_version)
38+
config_data.set('CMAKE_PROJECT_VERSION_MAJOR', meson.project_version().split('.')[0])
39+
config_data.set('CMAKE_PROJECT_VERSION_MINOR', meson.project_version().split('.')[1])
40+
config_data.set('CMAKE_PROJECT_VERSION_PATCH', meson.project_version().split('.')[2])
41+
42+
config_data.set10('HAVE_BYTESWAP_H', cc.has_header('byteswap.h'))
43+
config_data.set10('HAVE_DIRENT_H', cc.has_header('dirent.h'))
44+
config_data.set10('HAVE_ENDIAN_H', cc.has_header('endian.h'))
45+
config_data.set10('HAVE_INTTYPES_H', cc.has_header('inttypes.h'))
46+
config_data.set10('HAVE_PTHREAD_H', cc.has_header('pthread.h'))
47+
config_data.set10('HAVE_SYS_ENDIAN_H', cc.has_header('sys/endian.h'))
48+
config_data.set10('HAVE_SYS_PARAM_H', cc.has_header('sys/param.h'))
49+
config_data.set10('HAVE_SYS_UTSNAME_H', cc.has_header('sys/utsname.h'))
50+
config_data.set10('HAVE_FCNTL_H', cc.has_header('fcntl.h'))
51+
config_data.set10('HAVE_UNISTD_H', cc.has_header('unistd.h'))
52+
config_data.set10('HAVE_WCTYPE_H', cc.has_header('wctype.h'))
53+
config_data.set10('HAVE_STDBOOL_H', cc.has_header('stdbool.h'))
54+
55+
if target_machine.system() == 'windows' and cc.get_id() == 'msvc'
56+
config_data.set10('HAVE__ACCESS', cc.has_function('_access', prefix: '#include <io.h>'))
57+
config_data.set10('HAVE__GETPID', cc.has_function('_getpid', prefix: '#include <process.h>'))
58+
config_data.set10('HAVE__MKDIR', cc.has_function('_mkdir', prefix: '#include <direct.h>'))
59+
config_data.set10('HAVE__OPEN', cc.has_function('_open', prefix: '#include <io.h>'))
60+
config_data.set10('HAVE__SNPRINTF', cc.has_function('_snprintf', prefix: '#include <stdio.h>'))
61+
config_data.set10('HAVE__STAT', cc.has_function('_stat', prefix: '#include <sys/types.h>\n#include <sys/stat.h>'))
62+
config_data.set10(
63+
'HAVE__FSTAT64',
64+
cc.has_function('_fstat64', prefix: '#include <sys/types.h>\n#include <sys/stat.h>'),
65+
)
66+
config_data.set10('HAVE__STRDUP', cc.has_function('_strdup', prefix: '#include <string.h>'))
67+
config_data.set10('HAVE__STRICMP', cc.has_function('_stricmp', prefix: '#include <string.h>'))
68+
config_data.set10('HAVE__STRNICMP', cc.has_function('_strnicmp', prefix: '#include <string.h>'))
69+
config_data.set10('HAVE__READ', cc.has_function('_read', prefix: '#include <io.h>'))
70+
config_data.set10('HAVE__WRITE', cc.has_function('_write', prefix: '#include <io.h>'))
71+
else
72+
config_data.set10('HAVE_ACCESS', cc.has_function('access', prefix: '#include <unistd.h>'))
73+
config_data.set10('HAVE_FORK', cc.has_function('fork', prefix: '#include <unistd.h>'))
74+
config_data.set10('HAVE_GETOPT', cc.has_function('getopt', prefix: '#include <unistd.h>'))
75+
config_data.set10('HAVE_GETPID', cc.has_function('getpid', prefix: '#include <unistd.h>'))
76+
config_data.set10('HAVE_GETPWENT', cc.has_function('getpwent', prefix: '#include <sys/types.h>\n#include <pwd.h>'))
77+
config_data.set10('HAVE_GMTIME_R', cc.has_function('gmtime_r', prefix: '#include <time.h>'))
78+
config_data.set10('HAVE_LOCALTIME_R', cc.has_function('localtime_r', prefix: '#include <time.h>'))
79+
config_data.set10('HAVE_MKDIR', cc.has_function('mkdir', prefix: '#include <sys/stat.h>\n#include <sys/types.h>'))
80+
config_data.set10(
81+
'HAVE_OPEN',
82+
cc.has_function('open', prefix: '#include <sys/stat.h>\n#include <sys/types.h>\n#include <fcntl.h>'),
83+
)
84+
config_data.set10('HAVE_NANOSLEEP', cc.has_function('nanosleep', prefix: '#include <time.h>'))
85+
config_data.set10('HAVE_SIGNAL', cc.has_function('signal', prefix: '#include <signal.h>'))
86+
config_data.set10(
87+
'HAVE_STAT',
88+
cc.has_function('stat', prefix: '#include <sys/stat.h>\n#include <sys/types.h>\n#include <unistd.h>'),
89+
)
90+
config_data.set10(
91+
'HAVE_FSTAT',
92+
cc.has_function('fstat', prefix: '#include <sys/stat.h>\n#include <sys/types.h>\n#include <unistd.h>'),
93+
)
94+
config_data.set10('HAVE_STRDUP', cc.has_function('strdup', prefix: '#include <string.h>'))
95+
config_data.set10('HAVE_STRCASECMP', cc.has_function('strcasecmp', prefix: '#include <strings.h>'))
96+
config_data.set10('HAVE_STRNCASECMP', cc.has_function('strncasecmp', prefix: '#include <strings.h>'))
97+
config_data.set10('HAVE_READ', cc.has_function('read', prefix: '#include <unistd.h>'))
98+
config_data.set10('HAVE_UNLINK', cc.has_function('unlink', prefix: '#include <unistd.h>'))
99+
config_data.set10('HAVE_USLEEP', cc.has_function('usleep', prefix: '#include <unistd.h>'))
100+
config_data.set10('HAVE_WAITPID', cc.has_function('waitpid', prefix: '#include <sys/types.h>\n#include <sys/wait.h>'))
101+
config_data.set10('HAVE_WRITE', cc.has_function('write', prefix: '#include <unistd.h>'))
102+
config_data.set10('HAVE_ALARM', cc.has_function('alarm', prefix: '#include <unistd.h>'))
103+
endif
104+
105+
config_data.set10('HAVE_BACKTRACE', cc.has_function('backtrace', prefix: '#include <execinfo.h>'))
106+
config_data.set10('HAVE_ISWSPACE', cc.has_function('iswspace', prefix: '#include <wctype.h>'))
107+
config_data.set10('HAVE_SETENV', cc.has_function('setenv', prefix: '#include <stdlib.h>'))
108+
config_data.set10('HAVE_UNSETENV', cc.has_function('unsetenv', prefix: '#include <stdlib.h>'))
109+
config_data.set10('HAVE_SNPRINTF', cc.has_function('snprintf', prefix: '#include <stdio.h>'))
110+
111+
types = {
112+
'intptr_t': '#include <stdint.h>',
113+
'pid_t': '#include <sys/types.h>',
114+
'size_t': '#include <stddef.h>',
115+
'ssize_t': '#include <sys/types.h>',
116+
'time_t': '#include <time.h>',
117+
'__time64_t': '#include <time.h>',
118+
'wint_t': '#include <wctype.h>',
119+
}
120+
121+
foreach type, prefix : types
122+
type_size = cc.sizeof(type, prefix: prefix)
123+
if type_size > 0
124+
upper_type = type.to_upper()
125+
config_data.set10('HAVE_SIZEOF_@0@'.format(upper_type), true)
126+
config_data.set('SIZEOF_@0@'.format(upper_type), type_size)
127+
endif
128+
endforeach
129+
130+
if get_option('64bit_icaltime_t')
131+
if config_data.has('HAS_SIZEOF___TIME64_T')
132+
config_data.set('ICAL_ICALTIME_T_TYPE', '__time64_t')
133+
else
134+
error(
135+
'Option LIBICAL_ENABLE_64BIT_ICALTIME_T is not supported for this compiler or architecture since the __time64_t type is not available.',
136+
)
137+
endif
138+
else
139+
if config_data.get('SIZEOF_TIME_T') == 4
140+
warning(
141+
'The 32-bit time_t type has been detected. Consider reconfiguring with -D64bit_icaltime_t=true to enable 64-bit time_t types.',
142+
)
143+
endif
144+
config_data.set('ICAL_ICALTIME_T_TYPE', 'time_t')
145+
endif
146+
147+
thread_dep = dependency('threads')
148+
config_data.set10(
149+
'HAVE_PTHREAD_ATTR_GET_NP',
150+
cc.has_function('pthread_attr_get_np', dependencies: thread_dep, prefix: '#define _GNU_SOURCE\n#include <pthread.h>'),
151+
)
152+
config_data.set10(
153+
'HAVE_PTHREAD_GETATTR_NP',
154+
cc.has_function('pthread_getattr_np', dependencies: thread_dep, prefix: '#define _GNU_SOURCE\n#include <pthread.h>'),
155+
)
156+
config_data.set10(
157+
'HAVE_PTHREAD_CREATE',
158+
cc.has_function('pthread_create', dependencies: thread_dep, prefix: '#include <pthread.h>'),
159+
)
160+
config_data.set10('HAVE_PTHREAD_H', cc.has_header('pthread_np.h', dependencies: thread_dep))
161+
162+
config_data.set10('ICAL_ALLOW_EMPTY_PROPERTIES', get_option('allow_empty_properties'))
163+
config_data.set10('ICAL_ERRORS_ARE_FATAL', get_option('errors_are_fatal'))
164+
165+
config_h = configure_file(input: 'config.h.cmake', output: 'config.h', format: 'cmake', configuration: config_data)
166+
167+
config_dep = declare_dependency(
168+
include_directories: include_directories('.'),
169+
compile_args: '-DHAVE_CONFIG_H=1',
170+
sources: config_h,
171+
)
172+
173+
perl_bin = find_program('perl', native: true)
174+
175+
add_project_arguments(
176+
'-DICAL_ALLOW_EMPTY_PROPERTIES=@0@'.format(get_option('errors_are_fatal').to_int()),
177+
language: languages,
178+
)
179+
add_project_arguments('-DICAL_ERRORS_ARE_FATAL=@0@'.format(get_option('errors_are_fatal').to_int()), language: languages)
180+
181+
package_data_dir = get_option('prefix') / get_option('datadir') / 'libical'
182+
add_project_arguments('-DPACKAGE_DATA_DIR="@0@"'.format(package_data_dir), language: languages)
183+
184+
subdir('design-data')
185+
subdir('scripts')
186+
subdir('src')

meson.options

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: Corentin Noël <[email protected]>
2+
# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
3+
option('allow_empty_properties', type : 'boolean', value : false, description: 'Set to prevent empty properties from being replaced with X-LIC-ERROR properties.')
4+
option('errors_are_fatal', type : 'boolean', value : false, description: 'icalerror_* calls will abort instead of internally signaling an error.')
5+
option('64bit_icaltime_t', type : 'boolean', value : false, description: 'Redirect icaltime_t and related functions to a 64-bit version of time_t rather than to the C standard library time_t. Intended for use on 32-bit systems which have a 64-bit time_t available. May not be implemented on all platforms yet.')
6+
option('cxx_bindings', type : 'feature', value : 'auto', description: 'Build the C++ bindings.')

scripts/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mk_derived_components = files('mkderivedcomponents.pl')
2+
mk_derived_parameters = files('mkderivedparameters.pl')
3+
mk_derived_properties = files('mkderivedproperties.pl')
4+
mk_derived_values = files('mkderivedvalues.pl')
5+
mk_restriction_table = files('mkrestrictiontable.pl')
6+
scripts_dir = meson.current_source_dir()

src/libical/meson.build

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# SPDX-FileCopyrightText: Corentin Noël <[email protected]>
2+
# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
3+
4+
generation_files = {
5+
'icalderivedproperty': [mk_derived_properties, [ical_properties_design, ical_value_types_design]],
6+
'icalderivedparameter': [mk_derived_parameters, [ical_parameters_design]],
7+
'icalderivedvalue': [mk_derived_values, [ical_value_types_design]],
8+
}
9+
10+
generated_headers = []
11+
generated_sources = []
12+
13+
foreach filename, design_files : generation_files
14+
generated_headers += configure_file(
15+
input: '@[email protected]'.format(filename),
16+
output: '@[email protected]'.format(filename),
17+
command: [perl_bin, '-I', scripts_dir, design_files[0], '-i', '@INPUT@', '-h', design_files[1]],
18+
capture: true,
19+
)
20+
generated_sources += configure_file(
21+
input: '@[email protected]'.format(filename),
22+
output: '@[email protected]'.format(filename),
23+
command: [perl_bin, '-I', scripts_dir, design_files[0], '-i', '@INPUT@', '-c', design_files[1]],
24+
capture: true,
25+
)
26+
endforeach
27+
28+
generated_sources += configure_file(
29+
input: 'icalrestriction.c.in',
30+
output: 'icalrestriction.c',
31+
command: [perl_bin, '-I', scripts_dir, mk_restriction_table, '-i', '@INPUT@', ical_restrictions_design],
32+
capture: true,
33+
)
34+
35+
icaltime_h = configure_file(input: 'icaltime.h.cmake', output: 'icaltime.h', configuration: config_data, format: 'cmake')
36+
37+
icalversion_h = configure_file(input: 'icalversion.h.cmake', output: 'icalversion.h', configuration: config_data)
38+
39+
libical_lib = library(
40+
'ical',
41+
generated_sources,
42+
generated_headers,
43+
'libical_ical_export.h',
44+
'icalarray.c',
45+
'icalarray.h',
46+
'icalattach.h',
47+
'icalattachimpl.h',
48+
'icalattach.c',
49+
'icalcomponent.c',
50+
'icalcomponent.h',
51+
'icalenumarray.c',
52+
'icalenumarray.h',
53+
'icalenums.c',
54+
'icalenums.h',
55+
'icalerror.c',
56+
'icalerror.h',
57+
'icalmemory.c',
58+
'icalmemory.h',
59+
'icalmime.c',
60+
'icalmime.h',
61+
'icalparameter.c',
62+
'icalparameter.h',
63+
'icalparameterimpl.h',
64+
'icalparser.c',
65+
'icalparser.h',
66+
'icalproperty.c',
67+
'icalproperty.h',
68+
'icalrecur.c',
69+
'icalrecur.h',
70+
'icalrestriction.h',
71+
'icalstrarray.c',
72+
'icalstrarray.h',
73+
'icaltime.c',
74+
icaltime_h,
75+
'icaltz-util.c',
76+
'icaltz-util.h',
77+
'icaltimezone.c',
78+
'icaltimezone.h',
79+
'icaltimezoneimpl.h',
80+
'icalduration.h',
81+
'icalduration.c',
82+
'icalperiod.h',
83+
'icalperiod.c',
84+
'icaltypes.c',
85+
'icaltypes.h',
86+
'icalvalue.c',
87+
'icalvalue.h',
88+
'icalvalueimpl.h',
89+
'pvl.c',
90+
'pvl.h',
91+
'sspm.c',
92+
'sspm.h',
93+
'qsort_gen.c',
94+
'qsort_gen.h',
95+
'icallangbind.h',
96+
'icallangbind.c',
97+
'icaldate_p.c',
98+
'icaldate_p.h',
99+
'byref.c',
100+
dependencies: [config_dep, thread_dep],
101+
soversion: lib_soversion_string,
102+
)
103+
104+
libical_dep = declare_dependency(link_with: libical_lib, include_directories: include_directories('.'))
105+
106+
install_headers(
107+
'icalarray.h',
108+
'icalattach.h',
109+
'icalcomponent.h',
110+
generated_headers,
111+
'icaldate_p.h',
112+
'icalduration.h',
113+
'icalenumarray.h',
114+
'icalenums.h',
115+
'icalerror.h',
116+
'icallangbind.h',
117+
'icalmemory.h',
118+
'icalmime.h',
119+
'icalparameter.h',
120+
'icalparser.h',
121+
'icalperiod.h',
122+
'icalproperty.h',
123+
'icalrecur.h',
124+
'icalrestriction.h',
125+
'icalstrarray.h',
126+
icaltime_h,
127+
'icaltz-util.h',
128+
'icaltimezone.h',
129+
'icaltypes.h',
130+
'icalvalue.h',
131+
'libical_deprecated.h',
132+
'libical_sentinel.h',
133+
'libical_ical_export.h',
134+
'pvl.h',
135+
'sspm.h',
136+
subdir: 'libical',
137+
)
138+
139+
pkg.generate(
140+
libical_lib,
141+
description: 'An implementation of basic iCAL protocols',
142+
filebase: 'libical',
143+
url: project_url,
144+
)
145+
146+
if cxx_bindings_enabled
147+
libical_cxx_lib = library(
148+
'ical_cxx',
149+
'icalparameter_cxx.cpp',
150+
'icalparameter_cxx.h',
151+
'icalproperty_cxx.cpp',
152+
'icalproperty_cxx.h',
153+
'icalvalue_cxx.cpp',
154+
'icalvalue_cxx.h',
155+
'icptrholder_cxx.h',
156+
'vcomponent_cxx.cpp',
157+
'vcomponent_cxx.h',
158+
cpp_args: ['-DBUILD_LIBICALDLL'],
159+
dependencies: [libical_dep, config_dep, thread_dep],
160+
soversion: lib_soversion_string,
161+
)
162+
163+
libical_cxx_dep = declare_dependency(
164+
link_with: libical_cxx_lib,
165+
include_directories: include_directories('.'),
166+
dependencies: [libical_dep],
167+
)
168+
169+
install_headers(
170+
'icalparameter_cxx.h',
171+
'icalproperty_cxx.h',
172+
'icalvalue_cxx.h',
173+
'icptrholder_cxx.h',
174+
'vcomponent_cxx.h',
175+
subdir: 'libical',
176+
)
177+
endif

src/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: Corentin Noël <[email protected]>
2+
# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
3+
subdir('libical')

0 commit comments

Comments
 (0)