|
| 1 | +cmake_minimum_required(VERSION 3.0) |
| 2 | +project(re2c VERSION 1.3 HOMEPAGE_URL "https://re2c.org/") |
| 3 | + |
| 4 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 5 | +include(Re2cAutotoolsHelpers) |
| 6 | +include(Re2cBootstrapLexer) |
| 7 | +include(Re2cBootstrapParser) |
| 8 | +include(Re2cBootstrapCompiledHelp) |
| 9 | +include(Re2cBootstrapManual) |
| 10 | +include(Re2cTryCXXFlag) |
| 11 | + |
| 12 | +ac_subst(PACKAGE_VERSION "${PROJECT_VERSION}") |
| 13 | + |
| 14 | +option(RE2C_REBUILD_DOCS "Regenerate manpage" OFF) |
| 15 | +if (RE2C_REBUILD_DOCS) |
| 16 | + find_program(RST2MAN NAMES rst2man rst2man.py) |
| 17 | + if (NOT RST2MAN) |
| 18 | + message(FATAL_ERROR "need rst2man or rst2man.py for RE2C_REBUILD_DOCS=YES") |
| 19 | + endif() |
| 20 | +endif() |
| 21 | + |
| 22 | +option(RE2C_BUILD_LIBS "Build libraries" OFF) |
| 23 | + |
| 24 | +# checks for programs |
| 25 | + |
| 26 | +find_package(BISON) |
| 27 | + |
| 28 | +# checks for C++ compiler flags |
| 29 | + |
| 30 | +set(CMAKE_CXX_STANDARD 98) |
| 31 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 32 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) # make sure object libraries work with shared libraries |
| 33 | +if(NOT CMAKE_BUILD_TYPE) |
| 34 | + try_cxxflag("-O2") |
| 35 | +endif() |
| 36 | +try_cxxflag("-W") |
| 37 | +try_cxxflag("-Wall") |
| 38 | +try_cxxflag("-Wextra") |
| 39 | +try_cxxflag("-Weffc++") |
| 40 | +try_cxxflag("-pedantic") |
| 41 | +try_cxxflag("-Wformat=2") |
| 42 | +try_cxxflag("-Wredundant-decls") |
| 43 | +try_cxxflag("-Wsuggest-attribute=format") |
| 44 | +try_cxxflag("-Wconversion") |
| 45 | +try_cxxflag("-Wsign-conversion") |
| 46 | +try_cxxflag("-Werror=return-type") |
| 47 | +try_cxxflag("-Weverything" |
| 48 | + "-Wno-unknown-warning-option" # CLANG eats some GCC options only to warn they are unknown |
| 49 | + "-Wno-reserved-id-macro" # to allow header guards of the form '_RE2C_PATH_TO_HEADER_BASENAME_' |
| 50 | + "-Wno-padded" |
| 51 | + "-Wno-old-style-cast" # RE2C-generated lexer has lots of C-syle casts because of 're2c:yych:conversion = 1;' |
| 52 | + "-Wno-nested-anon-types" |
| 53 | + "-Wno-global-constructors" # initialization of global constants with std::numeric_limits<...> (mostly for size_t) |
| 54 | + "-Wno-shadow-field-in-constructor" # using same names in ctor seems more like a feature |
| 55 | + "-Wno-undefined-func-template" # explicit specialization to reduce build dependencies |
| 56 | +) |
| 57 | + |
| 58 | +# needed by src/c99_stdint.h |
| 59 | +ac_check_headers("stdint.h") |
| 60 | +# needed for POSIX file API |
| 61 | +ac_check_headers("sys/types.h") |
| 62 | +ac_check_headers("sys/stat.h") |
| 63 | +ac_check_headers("fcntl.h") |
| 64 | +ac_check_headers("unistd.h") |
| 65 | +ac_check_headers("io.h") # windows POSIX-like API |
| 66 | + |
| 67 | +# list of possible types to use in typedefs |
| 68 | +ac_check_sizeof("char") |
| 69 | +ac_check_sizeof("short") |
| 70 | +ac_check_sizeof("int") |
| 71 | +ac_check_sizeof("long") |
| 72 | +ac_check_sizeof("long long") |
| 73 | +ac_check_sizeof("__int64") |
| 74 | +# size of pointers |
| 75 | +ac_check_sizeof("void *") |
| 76 | +# 64-bit integer constant suffix |
| 77 | +ac_check_sizeof("0l") |
| 78 | +ac_check_sizeof("0ll") |
| 79 | +ac_check_sizeof("0i8") |
| 80 | + |
| 81 | +set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}") |
| 82 | +configure_file(doc/manpage.rst.in doc/manpage.rst @ONLY) |
| 83 | +configure_file(doc/help.rst.in doc/help.rst @ONLY) |
| 84 | + |
| 85 | +configure_file(run_tests.sh.in run_tests.sh @ONLY) |
| 86 | +if(CMAKE_HOST_UNIX) |
| 87 | + execute_process(COMMAND chmod +x "${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh") |
| 88 | +endif() |
| 89 | + |
| 90 | +ac_config_headers("config.h") |
| 91 | + |
| 92 | +# Makefile.am |
| 93 | +set(RE2C_STDLIB_DIR "${CMAKE_INSTALL_PREFIX}/share/re2c/stdlib") |
| 94 | +add_compile_definitions("RE2C_STDLIB_DIR=\"${RE2C_STDLIB_DIR}\"") |
| 95 | +add_compile_definitions($<$<CONFIG:Debug>:RE2C_DEBUG>) |
| 96 | +include_directories(. "${CMAKE_CURRENT_BINARY_DIR}") |
| 97 | + |
| 98 | +# sources |
| 99 | +add_library(re2c_generated_ver_to_vernum OBJECT |
| 100 | + "${CMAKE_CURRENT_BINARY_DIR}/src/msg/ver_to_vernum.cc" |
| 101 | +) |
| 102 | + |
| 103 | +add_executable(re2c |
| 104 | + src/codegen/bitmap.cc |
| 105 | + src/codegen/emit_action.cc |
| 106 | + src/codegen/emit_dfa.cc |
| 107 | + src/codegen/label.cc |
| 108 | + src/codegen/go_construct.cc |
| 109 | + src/codegen/go_destruct.cc |
| 110 | + src/codegen/go_emit.cc |
| 111 | + src/codegen/go_used_labels.cc |
| 112 | + src/codegen/input_api.cc |
| 113 | + src/codegen/output.cc |
| 114 | + src/codegen/print.cc |
| 115 | + src/options/opt.cc |
| 116 | + src/nfa/estimate_size.cc |
| 117 | + src/nfa/re_to_nfa.cc |
| 118 | + src/adfa/adfa.cc |
| 119 | + src/adfa/prepare.cc |
| 120 | + src/debug/dump_adfa.cc |
| 121 | + src/debug/dump_cfg.cc |
| 122 | + src/debug/dump_dfa.cc |
| 123 | + src/debug/dump_dfa_tree.cc |
| 124 | + src/debug/dump_interf.cc |
| 125 | + src/debug/dump_nfa.cc |
| 126 | + src/cfg/cfg.cc |
| 127 | + src/cfg/compact.cc |
| 128 | + src/cfg/dce.cc |
| 129 | + src/cfg/freeze.cc |
| 130 | + src/cfg/interfere.cc |
| 131 | + src/cfg/liveanal.cc |
| 132 | + src/cfg/normalize.cc |
| 133 | + src/cfg/optimize.cc |
| 134 | + src/cfg/rename.cc |
| 135 | + src/cfg/varalloc.cc |
| 136 | + src/dfa/closure.cc |
| 137 | + src/dfa/dead_rules.cc |
| 138 | + src/dfa/determinization.cc |
| 139 | + src/dfa/fallback_tags.cc |
| 140 | + src/dfa/fillpoints.cc |
| 141 | + src/dfa/find_state.cc |
| 142 | + src/dfa/minimization.cc |
| 143 | + src/dfa/stacmd.cc |
| 144 | + src/dfa/tagver_table.cc |
| 145 | + src/dfa/tcmd.cc |
| 146 | + src/encoding/ebcdic/ebcdic_regexp.cc |
| 147 | + src/encoding/enc.cc |
| 148 | + src/encoding/range_suffix.cc |
| 149 | + src/encoding/utf8/utf8_regexp.cc |
| 150 | + src/encoding/utf8/utf8.cc |
| 151 | + src/encoding/utf16/utf16_regexp.cc |
| 152 | + src/encoding/utf16/utf16.cc |
| 153 | + src/msg/msg.cc |
| 154 | + src/msg/warn.cc |
| 155 | + src/regexp/ast_to_re.cc |
| 156 | + src/regexp/default_tags.cc |
| 157 | + src/regexp/fixed_tags.cc |
| 158 | + src/regexp/nullable.cc |
| 159 | + src/regexp/rule.cc |
| 160 | + src/regexp/split_charset.cc |
| 161 | + src/regexp/tag.cc |
| 162 | + src/compile.cc |
| 163 | + src/skeleton/control_flow.cc |
| 164 | + src/skeleton/generate_code.cc |
| 165 | + src/skeleton/generate_data.cc |
| 166 | + src/skeleton/maxpath.cc |
| 167 | + src/skeleton/skeleton.cc |
| 168 | + src/parse/ast.cc |
| 169 | + src/parse/input.cc |
| 170 | + src/parse/normalize.cc |
| 171 | + src/parse/scanner.cc |
| 172 | + src/parse/unescape.cc |
| 173 | + src/parse/validate.cc |
| 174 | + src/util/get_dir.cc |
| 175 | + src/util/s_to_n32_unsafe.cc |
| 176 | + src/util/temp_file.cc |
| 177 | + src/util/range.cc |
| 178 | + src/main.cc |
| 179 | + $<TARGET_OBJECTS:re2c_generated_ver_to_vernum> |
| 180 | + "${CMAKE_CURRENT_BINARY_DIR}/src/parse/parser.cc" |
| 181 | + "${CMAKE_CURRENT_BINARY_DIR}/src/parse/parser.h" |
| 182 | + "${CMAKE_CURRENT_BINARY_DIR}/src/msg/help.cc" |
| 183 | + "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex.cc" |
| 184 | + "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex.h" |
| 185 | + "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex_conf.cc" |
| 186 | + "${CMAKE_CURRENT_BINARY_DIR}/src/options/parse_opts.cc" |
| 187 | + "${CMAKE_CURRENT_BINARY_DIR}/doc/re2c.1" # include this so CMake generates it |
| 188 | +) |
| 189 | + |
| 190 | +# target_include_directories(re2c PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/generated") |
| 191 | + |
| 192 | +re2c_bootstrap_lexer("src/parse/lex.re" "src/parse/lex.cc" "src/parse/lex.h") |
| 193 | +re2c_bootstrap_lexer("src/parse/lex_conf.re" "src/parse/lex_conf.cc") |
| 194 | +re2c_bootstrap_lexer("src/options/parse_opts.re" "src/options/parse_opts.cc") |
| 195 | +re2c_bootstrap_lexer("src/msg/ver_to_vernum.re" "src/msg/ver_to_vernum.cc") |
| 196 | +re2c_bootstrap_parser("src/parse/parser.ypp" "src/parse/parser.cc" "src/parse/parser.h") |
| 197 | +re2c_bootstrap_compiled_help("${CMAKE_CURRENT_BINARY_DIR}/doc/help.rst" "src/msg/help.cc") |
| 198 | +re2c_bootstrap_manual("${CMAKE_CURRENT_BINARY_DIR}/doc/manpage.rst" "doc/re2c.1") |
| 199 | + |
| 200 | +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) |
| 201 | + if(UNIX) |
| 202 | + install(TARGETS re2c) |
| 203 | + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/doc/re2c.1" DESTINATION "share/man/man1") |
| 204 | + install(FILES include/unicode_categories.re DESTINATION "${RE2C_STDLIB_DIR}") |
| 205 | + endif() |
| 206 | + |
| 207 | + if(RE2C_REBUILD_DOCS) |
| 208 | + add_custom_target(docs DEPENDS |
| 209 | + "${CMAKE_CURRENT_BINARY_DIR}/doc/re2c.1" |
| 210 | + "${CMAKE_CURRENT_BINARY_DIR}/src/msg/help.cc" |
| 211 | + ) |
| 212 | + else() |
| 213 | + add_custom_target(docs |
| 214 | + COMMAND cmake -E echo "Reconfigure to rebuild docs: cmake -DRE2C_REBUILD_DOCS=YES" |
| 215 | + COMMAND cmake -E false |
| 216 | + ) |
| 217 | + endif() |
| 218 | + |
| 219 | + # rebuild all re2c sources using newly built re2c |
| 220 | + add_custom_target(bootstrap |
| 221 | + COMMAND cmake -E remove_directory "src" |
| 222 | + COMMAND cmake -E remove_directory "doc/re2c.1" |
| 223 | + COMMAND cmake --build "${CMAKE_CURRENT_BINARY_DIR}" |
| 224 | + ) |
| 225 | + |
| 226 | + # tests |
| 227 | + add_custom_target(tests |
| 228 | + DEPENDS run_tests.sh |
| 229 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 230 | + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh" |
| 231 | + ) |
| 232 | + add_dependencies(tests re2c) |
| 233 | + add_custom_target(vtests |
| 234 | + DEPENDS run_tests.sh |
| 235 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 236 | + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh" --valgrind |
| 237 | + ) |
| 238 | + add_dependencies(vtests re2c) |
| 239 | + add_custom_target(wtests |
| 240 | + DEPENDS run_tests.sh |
| 241 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 242 | + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh" --wine -j1 |
| 243 | + ) |
| 244 | + add_dependencies(wtests re2c) |
| 245 | + |
| 246 | + add_executable(re2c_test_range |
| 247 | + src/test/range/test-impl.h |
| 248 | + src/test/range/test.cc |
| 249 | + src/test/range/test.h |
| 250 | + src/util/range.cc |
| 251 | + src/util/range.h |
| 252 | + src/util/static_assert.h |
| 253 | + ) |
| 254 | + add_executable(re2c_test_s_to_n32_unsafe |
| 255 | + src/test/s_to_n32_unsafe/test.cc |
| 256 | + src/util/s_to_n32_unsafe.cc |
| 257 | + ) |
| 258 | + add_executable(re2c_test_ver_to_vernum |
| 259 | + src/test/ver_to_vernum/test.cc |
| 260 | + $<TARGET_OBJECTS:re2c_generated_ver_to_vernum> |
| 261 | + ) |
| 262 | + |
| 263 | + add_custom_target(check |
| 264 | + COMMAND ./re2c_test_range |
| 265 | + COMMAND ./re2c_test_s_to_n32_unsafe |
| 266 | + COMMAND ./re2c_test_ver_to_vernum |
| 267 | + ) |
| 268 | + add_dependencies(check tests re2c_test_range re2c_test_s_to_n32_unsafe re2c_test_ver_to_vernum) |
| 269 | +endif() |
| 270 | + |
| 271 | +if (RE2C_BUILD_LIBS) |
| 272 | + add_library(libre2c_objects OBJECT |
| 273 | + lib/regcomp.cc |
| 274 | + lib/regexec.cc |
| 275 | + lib/regexec_dfa.cc |
| 276 | + lib/regexec_nfa_leftmost.cc |
| 277 | + lib/regexec_nfa_leftmost_trie.cc |
| 278 | + lib/regexec_nfa_posix.cc |
| 279 | + lib/regexec_nfa_posix_trie.cc |
| 280 | + lib/regexec_nfa_posix_backward.cc |
| 281 | + lib/regexec_nfa_posix_kuklewicz.cc |
| 282 | + lib/regfree.cc |
| 283 | + lib/stubs.cc |
| 284 | + src/parse/ast.cc |
| 285 | + src/parse/unescape.cc |
| 286 | + src/options/opt.cc |
| 287 | + src/cfg/cfg.cc |
| 288 | + src/cfg/compact.cc |
| 289 | + src/cfg/dce.cc |
| 290 | + src/cfg/freeze.cc |
| 291 | + src/cfg/interfere.cc |
| 292 | + src/cfg/liveanal.cc |
| 293 | + src/cfg/normalize.cc |
| 294 | + src/cfg/optimize.cc |
| 295 | + src/cfg/rename.cc |
| 296 | + src/cfg/varalloc.cc |
| 297 | + src/dfa/closure.cc |
| 298 | + src/debug/dump_adfa.cc |
| 299 | + src/debug/dump_cfg.cc |
| 300 | + src/debug/dump_dfa.cc |
| 301 | + src/debug/dump_dfa_tree.cc |
| 302 | + src/debug/dump_interf.cc |
| 303 | + src/debug/dump_nfa.cc |
| 304 | + src/dfa/dead_rules.cc |
| 305 | + src/dfa/determinization.cc |
| 306 | + src/dfa/fallback_tags.cc |
| 307 | + src/dfa/fillpoints.cc |
| 308 | + src/dfa/find_state.cc |
| 309 | + src/dfa/minimization.cc |
| 310 | + src/dfa/stacmd.cc |
| 311 | + src/dfa/tagver_table.cc |
| 312 | + src/dfa/tcmd.cc |
| 313 | + src/nfa/estimate_size.cc |
| 314 | + src/nfa/re_to_nfa.cc |
| 315 | + src/encoding/enc.cc |
| 316 | + src/encoding/range_suffix.cc |
| 317 | + src/encoding/ebcdic/ebcdic_regexp.cc |
| 318 | + src/encoding/utf16/utf16.cc |
| 319 | + src/encoding/utf16/utf16_regexp.cc |
| 320 | + src/encoding/utf8/utf8.cc |
| 321 | + src/encoding/utf8/utf8_regexp.cc |
| 322 | + src/msg/msg.cc |
| 323 | + src/msg/warn.cc |
| 324 | + src/regexp/ast_to_re.cc |
| 325 | + src/regexp/default_tags.cc |
| 326 | + src/regexp/fixed_tags.cc |
| 327 | + src/regexp/nullable.cc |
| 328 | + src/regexp/rule.cc |
| 329 | + src/regexp/split_charset.cc |
| 330 | + src/regexp/tag.cc |
| 331 | + src/skeleton/control_flow.cc |
| 332 | + src/skeleton/maxpath.cc |
| 333 | + src/skeleton/skeleton.cc |
| 334 | + src/util/range.cc |
| 335 | + src/util/s_to_n32_unsafe.cc |
| 336 | + "${CMAKE_CURRENT_BINARY_DIR}/lib/lex.cc" |
| 337 | + "${CMAKE_CURRENT_BINARY_DIR}/lib/parse.cc" |
| 338 | + ) |
| 339 | + set(libre2c_sources $<TARGET_OBJECTS:libre2c_objects> $<TARGET_OBJECTS:re2c_generated_ver_to_vernum>) |
| 340 | + |
| 341 | + # build shared libraries |
| 342 | + if ((NOT DEFINED BUILD_SHARED_LIBS) OR BUILD_SHARED_LIBS) |
| 343 | + add_library(libre2c_shared SHARED ${libre2c_sources}) |
| 344 | + set_target_properties(libre2c_shared PROPERTIES OUTPUT_NAME "re2c") |
| 345 | + if (UNIX) |
| 346 | + install(TARGETS libre2c_shared) |
| 347 | + endif() |
| 348 | + endif() |
| 349 | + |
| 350 | + # build static libraries |
| 351 | + if ((NOT DEFINED BUILD_SHARED_LIBS) OR (NOT BUILD_SHARED_LIBS)) |
| 352 | + add_library(libre2c_static STATIC ${libre2c_sources}) |
| 353 | + if (UNIX) |
| 354 | + set_target_properties(libre2c_static PROPERTIES OUTPUT_NAME "re2c") |
| 355 | + install(TARGETS libre2c_static) |
| 356 | + else() |
| 357 | + set_target_properties(libre2c_static PROPERTIES OUTPUT_NAME "re2c_static") |
| 358 | + endif() |
| 359 | + endif() |
| 360 | + |
| 361 | + # define top-level aliases to either static or shared libraries (default is static) |
| 362 | + if (BUILD_SHARED_LIBS) |
| 363 | + add_library(libre2c ALIAS libre2c_shared) |
| 364 | + else() |
| 365 | + add_library(libre2c ALIAS libre2c_static) |
| 366 | + endif() |
| 367 | + |
| 368 | + re2c_bootstrap_lexer("lib/lex.re" "lib/lex.cc") |
| 369 | + re2c_bootstrap_parser("lib/parse.ypp" "lib/parse.cc" "lib/parse.h") |
| 370 | + |
| 371 | + add_executable(test_libre2c lib/test.cc) |
| 372 | + target_link_libraries(test_libre2c libre2c) |
| 373 | + |
| 374 | + # check_PROGRAMS += test_libre2c // TODO |
| 375 | + |
| 376 | + add_executable(bench_libre2c lib/bench.cc) |
| 377 | + set_property(TARGET bench_libre2c PROPERTY CXX_STANDARD 11) |
| 378 | + target_link_libraries(bench_libre2c libre2c) |
| 379 | + |
| 380 | + find_path(RE2_INCLUDE_DIRECTORY "re2/re2.h") |
| 381 | + find_library(RE2_LIBRARY "re2") |
| 382 | + if (RE2_INCLUDE_DIRECTORY AND RE2_LIBRARY) |
| 383 | + target_compile_definitions(bench_libre2c PRIVATE "HAVE_RE2_RE_H=1") |
| 384 | + target_include_directories(bench_libre2c PRIVATE "${RE2_INCLUDE_DIRECTORY}") |
| 385 | + target_link_libraries(bench_libre2c "${RE2_LIBRARY}") |
| 386 | + endif() |
| 387 | +endif() |
0 commit comments