forked from skvadrik/re2c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
542 lines (503 loc) · 18.8 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
cmake_minimum_required(VERSION 3.12)
project(re2c VERSION 3.0 HOMEPAGE_URL "https://re2c.org/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(Re2cAutotoolsHelpers)
include(Re2cBootstrapLexer)
include(Re2cBootstrapParser)
include(Re2cBuildType)
include(Re2cGenDocs)
include(Re2cCompilerFlags)
ac_subst(PACKAGE_VERSION "${PROJECT_VERSION}")
option(RE2C_REBUILD_LEXERS "Regenerate lexers" OFF)
if(RE2C_REBUILD_LEXERS AND NOT RE2C_FOR_BUILD)
message(FATAL_ERROR "option RE2C_FOR_BUILD is required for RE2C_REBUILD_LEXERS")
endif()
option(RE2C_REBUILD_PARSERS "Regenerate parsers with Bison" OFF)
if(RE2C_REBUILD_PARSERS AND NOT RE2C_FOR_BUILD)
find_package(BISON REQUIRED)
endif()
option(RE2C_REBUILD_DOCS "Regenerate manpage" OFF)
option(RE2C_BUILD_LIBS "Build libraries" OFF)
option(RE2C_BUILD_RE2GO "Build re2go executable (an alias for `re2c --lang go`)" ON)
option(RE2C_BUILD_RE2RUST "Build re2rust executable (an alias for `re2c --lang rust`)" ON)
option(RE2C_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(RE2C_REGEN_BENCHMARKS "Regenerate C code for benchmarks" OFF)
# checks for programs
find_package(Python3 COMPONENTS Interpreter)
# starting from cmake 3.19 find_package can do version check, but we are on 3.12
if(Python3_VERSION VERSION_LESS 3.7)
message(FATAL_ERROR "python version 3.7 or higher is required")
endif()
if(RE2C_REBUILD_DOCS)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "import docutils"
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
)
if (NOT ${EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "python package docutils (needed for docs) not found")
endif()
endif()
# checks for C++ compiler flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # make sure object libraries work with shared libraries
# needed for POSIX file API
ac_check_headers("sys/types.h")
ac_check_headers("sys/stat.h")
ac_check_headers("fcntl.h")
ac_check_headers("unistd.h")
# windows POSIX-like API
ac_check_headers("io.h")
# docs (manpages and help)
set(re2c_manpage_source "${CMAKE_CURRENT_BINARY_DIR}/doc/manpage.rst")
set(re2c_help_source "${CMAKE_CURRENT_BINARY_DIR}/doc/help.rst")
set(re2c_manpage_bootstrap_c "${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/doc/re2c.1")
set(re2c_manpage_bootstrap_go "${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/doc/re2go.1")
set(re2c_manpage_bootstrap_rust "${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/doc/re2rust.1")
set(re2c_help_bootstrap "${CMAKE_CURRENT_SOURCE_DIR}/bootstrap/src/msg/help.cc")
set(re2c_manpage_c "${CMAKE_CURRENT_BINARY_DIR}/doc/re2c.1")
set(re2c_manpage_go "${CMAKE_CURRENT_BINARY_DIR}/doc/re2go.1")
set(re2c_manpage_rust "${CMAKE_CURRENT_BINARY_DIR}/doc/re2rust.1")
set(re2c_help "${CMAKE_CURRENT_BINARY_DIR}/src/msg/help.cc")
set(re2c_rst2man "${CMAKE_CURRENT_SOURCE_DIR}/build/rst2man.py")
set(re2c_rst2txt "${CMAKE_CURRENT_SOURCE_DIR}/build/rst2txt.py")
set(re2c_splitman "${CMAKE_CURRENT_SOURCE_DIR}/build/split_man.py")
set(re2c_docs
"${re2c_help}"
"${re2c_manpage_c}"
"$<$<BOOL:${RE2C_BUILD_RE2GO}>:${re2c_manpage_go}>"
"$<$<BOOL:${RE2C_BUILD_RE2RUST}>:${re2c_manpage_rust}>"
)
set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
set(top_builddir "${CMAKE_CURRENT_BINARY_DIR}")
set(PYTHON "${Python3_EXECUTABLE}")
configure_file(doc/manpage.rst.in doc/manpage.rst @ONLY)
configure_file(doc/help.rst.in doc/help.rst @ONLY)
configure_file(run_tests.py.in run_tests.py @ONLY)
set(RE2C_RUN_TESTS "${CMAKE_CURRENT_BINARY_DIR}/run_tests.py")
if(CMAKE_HOST_UNIX)
execute_process(COMMAND chmod +x "${RE2C_RUN_TESTS}")
endif()
ac_config_headers("config.h")
# Makefile.am
set(RE2C_STDLIB_DIR "${CMAKE_INSTALL_PREFIX}/share/re2c/stdlib")
add_compile_definitions(
"RE2C_STDLIB_DIR=\"${RE2C_STDLIB_DIR}\""
$<$<CONFIG:Debug>:RE2C_DEBUG>
)
include_directories(. "${CMAKE_CURRENT_BINARY_DIR}")
# Build autogenerated sources into an object library to ensure that they are
# generated once at the beginning of build (as with Automake BUILT_SOURCES).
# WARNING: custom target that depends on autogenerated sources won't do here
# as its dependencies get built multiple times, which ruins parallel builds.
add_library(re2c_objects_autogen OBJECT
"${CMAKE_CURRENT_BINARY_DIR}/src/parse/parser.cc"
"${CMAKE_CURRENT_BINARY_DIR}/src/parse/parser.h"
"${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex.cc"
"${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex.h"
"${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex_conf.cc"
"${CMAKE_CURRENT_BINARY_DIR}/src/options/parse_opts.cc"
"${re2c_docs}"
)
add_library(re2c_objects_autogen_ver_to_vernum OBJECT
"${CMAKE_CURRENT_BINARY_DIR}/src/msg/ver_to_vernum.cc"
)
set(re2c_sources
src/codegen/code_goto.cc
src/codegen/combine.cc
src/codegen/gen_bitmaps.cc
src/codegen/gen_delayed.cc
src/codegen/gen_dfa.cc
src/codegen/gen_goto.cc
src/codegen/gen_program.cc
src/codegen/gen_state.cc
src/codegen/helpers.cc
src/codegen/remove_empty.cc
src/codegen/render.cc
src/options/opt.cc
src/options/symtab.cc
src/nfa/re_to_nfa.cc
src/adfa/adfa.cc
src/debug/dump_adfa.cc
src/debug/dump_cfg.cc
src/debug/dump_dfa.cc
src/debug/dump_dfa_tree.cc
src/debug/dump_interf.cc
src/debug/dump_nfa.cc
src/cfg/cfg.cc
src/cfg/compact.cc
src/cfg/dce.cc
src/cfg/freeze.cc
src/cfg/interfere.cc
src/cfg/liveanal.cc
src/cfg/normalize.cc
src/cfg/optimize.cc
src/cfg/rename.cc
src/cfg/varalloc.cc
src/dfa/closure.cc
src/dfa/dead_rules.cc
src/dfa/determinization.cc
src/dfa/fallback_tags.cc
src/dfa/fillpoints.cc
src/dfa/find_state.cc
src/dfa/minimization.cc
src/dfa/tagver_table.cc
src/dfa/tcmd.cc
src/encoding/ebcdic.cc
src/encoding/enc.cc
src/encoding/range_suffix.cc
src/encoding/utf8.cc
src/encoding/utf16.cc
src/msg/msg.cc
src/msg/warn.cc
src/regexp/ast_to_re.cc
src/regexp/default_tags.cc
src/regexp/fixed_tags.cc
src/regexp/nullable.cc
src/regexp/regexp.cc
src/regexp/split_charset.cc
src/compile.cc
src/skeleton/control_flow.cc
src/skeleton/generate_code.cc
src/skeleton/generate_data.cc
src/skeleton/maxpath.cc
src/skeleton/skeleton.cc
src/parse/ast.cc
src/parse/input.cc
src/util/file_utils.cc
src/util/string_utils.cc
src/util/range.cc
src/main.cc
$<TARGET_OBJECTS:re2c_objects_autogen>
$<TARGET_OBJECTS:re2c_objects_autogen_ver_to_vernum>
)
# re2c
add_executable(re2c ${re2c_sources})
# re2go
if (RE2C_BUILD_RE2GO)
add_executable(re2go ${re2c_sources})
target_compile_definitions(re2go PUBLIC "RE2C_LANG=Lang::GO")
endif()
# re2rust
if (RE2C_BUILD_RE2RUST)
add_executable(re2rust ${re2c_sources})
target_compile_definitions(re2rust PUBLIC "RE2C_LANG=Lang::RUST")
endif()
re2c_bootstrap_lexer("src/parse/lex.re" "src/parse/lex.cc" "src/parse/lex.h")
re2c_bootstrap_lexer("src/parse/lex_conf.re" "src/parse/lex_conf.cc")
re2c_bootstrap_lexer("src/options/parse_opts.re" "src/options/parse_opts.cc")
re2c_bootstrap_lexer("src/msg/ver_to_vernum.re" "src/msg/ver_to_vernum.cc")
re2c_bootstrap_parser("src/parse/parser.ypp" "src/parse/parser.cc" "src/parse/parser.h")
# docs
set(re2c_docs_sources
"${re2c_manpage_source}"
"doc/manual/api/interface.rst_"
"doc/manual/conditions/blocks.rst_"
"doc/manual/conditions/conditions.rst_"
"doc/manual/configurations/configurations.rst_"
"doc/manual/directives/directives.rst_"
"doc/manual/dot/dot.rst_"
"doc/manual/encodings/encodings.rst_"
"doc/manual/eof/01_sentinel.rst_"
"doc/manual/eof/02_bounds_checking.rst_"
"doc/manual/eof/03_eof_rule.rst_"
"doc/manual/eof/04_generic_api.rst_"
"doc/manual/eof/eof.rst_"
"doc/manual/fill/01_fill.rst_"
"doc/manual/fill/02_fill.rst_"
"doc/manual/fill/fill.rst_"
"doc/manual/headers/headers.rst_"
"doc/manual/includes/includes.rst_"
"doc/manual/options/debug.rst_"
"doc/manual/options/internal.rst_"
"doc/manual/options/options.rst_"
"doc/manual/regexps/regular_expressions.rst_"
"doc/manual/reuse/reuse.rst_"
"doc/manual/skeleton/skeleton.rst_"
"doc/manual/state/state.rst_"
"doc/manual/submatch/submatch_example_mtags.rst_"
"doc/manual/submatch/submatch_example_posix.rst_"
"doc/manual/submatch/submatch_example_stags_fill.rst_"
"doc/manual/submatch/submatch_example_stags.rst_"
"doc/manual/submatch/submatch.rst_"
"doc/manual/synopsis.rst_"
"doc/manual/syntax/api1.rst_"
"doc/manual/syntax/api2_c.rst_"
"doc/manual/syntax/api2_go.rst_"
"doc/manual/syntax/api2_rust.rst_"
"doc/manual/syntax/api3.rst_"
"doc/manual/syntax/intro.rst_"
"doc/manual/syntax/syntax.rst_"
"doc/manual/warnings/warnings_general.rst_"
"doc/manual/warnings/warnings_list.rst_"
"examples/c/01_basic.re"
"examples/c/01_basic.c"
"examples/c/conditions/parse_u32_blocks.re"
"examples/c/conditions/parse_u32_conditions.re"
"examples/c/encodings/unicode_identifier.re"
"examples/c/eof/01_sentinel.re"
"examples/c/eof/02_bounds_checking.re"
"examples/c/eof/03_eof_rule.re"
"examples/c/eof/05_generic_api_eof_rule.re"
"examples/c/fill/01_fill.re"
"examples/c/fill/02_fill.re"
"examples/c/headers/header.re"
"examples/c/headers/lexer/state.h"
"examples/c/includes/include.re"
"examples/c/includes/definitions.h"
"examples/c/reuse/reuse.re"
"examples/c/reuse/usedir.re"
"examples/c/state/push.re"
"examples/c/submatch/01_stags_fill.re"
"examples/c/submatch/01_stags.re"
"examples/c/submatch/02_mtags.re"
"examples/c/submatch/03_posix.re"
"examples/go/01_basic.re"
"examples/go/01_basic.go"
"examples/go/conditions/parse_u32_blocks.re"
"examples/go/conditions/parse_u32_conditions.re"
"examples/go/encodings/unicode_identifier.re"
"examples/go/eof/01_sentinel.re"
"examples/go/eof/02_bounds_checking.re"
"examples/go/eof/03_eof_rule.re"
"examples/go/eof/05_generic_api_eof_rule.re"
"examples/go/fill/01_fill.re"
"examples/go/fill/02_fill.re"
"examples/go/headers/header.re"
"examples/go/headers/lexer/state.go"
"examples/go/includes/include.re"
"examples/go/includes/definitions.go"
"examples/go/reuse/reuse.re"
"examples/go/reuse/usedir.re"
"examples/go/state/push.re"
"examples/go/submatch/01_stags_fill.re"
"examples/go/submatch/01_stags.re"
"examples/go/submatch/02_mtags.re"
"examples/go/submatch/03_posix.re"
"examples/rust/01_basic.re"
"examples/rust/01_basic.rs"
"examples/rust/conditions/parse_u32_blocks.re"
"examples/rust/conditions/parse_u32_conditions.re"
"examples/rust/encodings/unicode_identifier.re"
"examples/rust/eof/01_sentinel.re"
"examples/rust/eof/02_bounds_checking.re"
"examples/rust/eof/03_eof_rule.re"
"examples/rust/eof/05_generic_api_eof_rule.re"
"examples/rust/fill/01_fill.re"
"examples/rust/fill/02_fill.re"
"examples/rust/headers/header.re"
"examples/rust/headers/lexer/state.rs"
"examples/rust/includes/include.re"
"examples/rust/includes/definitions.rs"
"examples/rust/reuse/reuse.re"
"examples/rust/reuse/usedir.re"
"examples/rust/state/push.re"
"examples/rust/submatch/01_stags_fill.re"
"examples/rust/submatch/01_stags.re"
"examples/rust/submatch/02_mtags.re"
"examples/rust/submatch/03_posix.re"
)
re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_c}" "${re2c_manpage_bootstrap_c}" "c")
re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_go}" "${re2c_manpage_bootstrap_go}" "go")
re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_rust}" "${re2c_manpage_bootstrap_rust}" "rust")
re2c_gen_help("${re2c_help_source}" "${re2c_help}" "${re2c_help_bootstrap}")
add_custom_target(docs DEPENDS "${re2c_docs}")
# install and test targets are enabled only if re2c is the root project
if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# install
install(TARGETS re2c RUNTIME DESTINATION bin)
install(FILES "${re2c_manpage_c}" DESTINATION "share/man/man1")
if(RE2C_BUILD_RE2GO)
install(TARGETS re2go RUNTIME DESTINATION bin)
install(FILES "${re2c_manpage_go}" DESTINATION "share/man/man1")
endif()
if(RE2C_BUILD_RE2RUST)
install(TARGETS re2rust RUNTIME DESTINATION bin)
install(FILES "${re2c_manpage_rust}" DESTINATION "share/man/man1")
endif()
install(FILES include/unicode_categories.re DESTINATION "${RE2C_STDLIB_DIR}")
# rebuild all re2c sources using newly built re2c
add_custom_target(bootstrap
COMMAND "${CMAKE_COMMAND}" -E remove_directory "src"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "doc"
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}"
)
# tests
add_custom_target(tests
DEPENDS "${RE2C_RUN_TESTS}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND "${Python3_EXECUTABLE}" "${RE2C_RUN_TESTS}"
)
add_dependencies(tests re2c)
add_custom_target(vtests
DEPENDS "${RE2C_RUN_TESTS}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND "${Python3_EXECUTABLE}" "${RE2C_RUN_TESTS}" --valgrind
)
add_dependencies(vtests re2c)
add_custom_target(wtests
DEPENDS "${RE2C_RUN_TESTS}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND "${Python3_EXECUTABLE}" "${RE2C_RUN_TESTS}" --wine -j1
)
add_dependencies(wtests re2c)
add_executable(re2c_test_range
src/test/range/test-impl.h
src/test/range/test.cc
src/test/range/test.h
src/util/range.cc
src/util/range.h
)
add_executable(re2c_test_s_to_n32_unsafe
src/test/s_to_n32_unsafe/test.cc
src/util/string_utils.cc
)
add_executable(re2c_test_ver_to_vernum
src/test/ver_to_vernum/test.cc
$<TARGET_OBJECTS:re2c_objects_autogen_ver_to_vernum>
)
add_executable(re2c_test_argsubst
src/test/argsubst/test.cc
src/codegen/helpers.cc
)
add_custom_target(check_re2c
COMMAND ./re2c_test_range
COMMAND ./re2c_test_s_to_n32_unsafe
COMMAND ./re2c_test_ver_to_vernum
COMMAND ./re2c_test_argsubst
)
add_dependencies(check_re2c
tests
re2c_test_range
re2c_test_s_to_n32_unsafe
re2c_test_ver_to_vernum
re2c_test_argsubst
)
endif()
if (RE2C_BUILD_LIBS)
# Build autogenerated sources into an object library to ensure that they are
# generated once at the beginning of build (as with Automake BUILT_SOURCES).
# WARNING: custom target that depends on autogenerated sources won't do here
# as its dependencies get built multiple times, which ruins parallel builds.
add_library(libre2c_objects_autogen OBJECT
"${CMAKE_CURRENT_BINARY_DIR}/lib/lex.cc"
"${CMAKE_CURRENT_BINARY_DIR}/lib/parse.cc"
)
re2c_bootstrap_lexer("lib/lex.re" "lib/lex.cc")
re2c_bootstrap_parser("lib/parse.ypp" "lib/parse.cc" "lib/parse.h")
add_library(test_libre2c_objects_autogen OBJECT
"${CMAKE_CURRENT_BINARY_DIR}/lib/test_helper.cc"
)
re2c_bootstrap_lexer("lib/test_helper.re" "lib/test_helper.cc")
set(libre2c_sources
lib/regcomp.cc
lib/regexec.cc
lib/regexec_dfa.cc
lib/regexec_dfa_multipass.cc
lib/regexec_nfa_leftmost.cc
lib/regexec_nfa_leftmost_trie.cc
lib/regexec_nfa_posix.cc
lib/regexec_nfa_posix_trie.cc
lib/regfree.cc
lib/stubs.cc
src/parse/ast.cc
src/parse/input.cc
src/options/opt.cc
src/options/symtab.cc
src/cfg/cfg.cc
src/cfg/compact.cc
src/cfg/dce.cc
src/cfg/freeze.cc
src/cfg/interfere.cc
src/cfg/liveanal.cc
src/cfg/normalize.cc
src/cfg/optimize.cc
src/cfg/rename.cc
src/cfg/varalloc.cc
src/dfa/closure.cc
src/debug/dump_adfa.cc
src/debug/dump_cfg.cc
src/debug/dump_dfa.cc
src/debug/dump_dfa_tree.cc
src/debug/dump_interf.cc
src/debug/dump_nfa.cc
src/dfa/dead_rules.cc
src/dfa/determinization.cc
src/dfa/fallback_tags.cc
src/dfa/fillpoints.cc
src/dfa/find_state.cc
src/dfa/minimization.cc
src/dfa/tagver_table.cc
src/dfa/tcmd.cc
src/nfa/re_to_nfa.cc
src/encoding/enc.cc
src/encoding/range_suffix.cc
src/encoding/ebcdic.cc
src/encoding/utf16.cc
src/encoding/utf8.cc
src/msg/msg.cc
src/msg/warn.cc
src/regexp/ast_to_re.cc
src/regexp/default_tags.cc
src/regexp/fixed_tags.cc
src/regexp/nullable.cc
src/regexp/regexp.cc
src/regexp/split_charset.cc
src/skeleton/control_flow.cc
src/skeleton/maxpath.cc
src/skeleton/skeleton.cc
src/util/range.cc
src/util/file_utils.cc
src/util/string_utils.cc
$<TARGET_OBJECTS:libre2c_objects_autogen>
$<TARGET_OBJECTS:re2c_objects_autogen_ver_to_vernum>
)
# on Windows add suffix to static libs to avoid collision of .lib files with shared libs
set(RE2C_STATIC_LIB_SFX "$<$<PLATFORM_ID:Windows>:_static>")
# build static libraries
if ((NOT DEFINED BUILD_SHARED_LIBS) OR (NOT BUILD_SHARED_LIBS))
add_library(libre2c_static STATIC ${libre2c_sources})
set_target_properties(libre2c_static PROPERTIES OUTPUT_NAME "re2c${RE2C_STATIC_LIB_SFX}")
if (UNIX)
install(TARGETS libre2c_static ARCHIVE DESTINATION lib)
endif()
endif()
# build shared libraries
if ((NOT DEFINED BUILD_SHARED_LIBS) OR BUILD_SHARED_LIBS)
add_library(libre2c_shared SHARED ${libre2c_sources})
set_target_properties(libre2c_shared PROPERTIES OUTPUT_NAME "re2c")
if (UNIX)
install(TARGETS libre2c_shared LIBRARY DESTINATION lib)
endif()
endif()
# define top-level aliases to either static or shared libraries (default is static)
if (BUILD_SHARED_LIBS)
add_library(libre2c ALIAS libre2c_shared)
else()
add_library(libre2c ALIAS libre2c_static)
endif()
# libre2c test
add_executable(test_libre2c lib/test.cc)
target_link_libraries(test_libre2c libre2c)
target_link_libraries(test_libre2c test_libre2c_objects_autogen)
add_custom_target(check_libre2c
COMMAND ./test_libre2c
)
if(RE2C_BUILD_BENCHMARKS)
add_subdirectory(benchmarks/submatch_nfa)
add_subdirectory(benchmarks/submatch_dfa_jit)
add_subdirectory(benchmarks/submatch_java)
endif()
else()
# empty check target
add_custom_target(check_libre2c)
endif()
if(RE2C_BUILD_BENCHMARKS)
add_subdirectory(benchmarks/submatch_dfa_aot)
endif()
# only add check target if toplevel project
if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
add_custom_target(check)
add_dependencies(check check_re2c check_libre2c)
endif()