| 1 |
# ------------------------------------------------------------------------------------------------------------------- |
| 2 |
## Parser Generation Targets |
| 3 |
|
| 4 |
# When updating the cached files, update MD5 sums defined in this file |
| 5 |
include(${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake) |
| 6 |
|
| 7 |
macro(MD5 filename md5sum) |
| 8 |
file(READ "${filename}" RAW_MD5_FILE) |
| 9 |
string(REGEX REPLACE "\r" "" STRIPPED_MD5_FILE "${RAW_MD5_FILE}") |
| 10 |
string(MD5 ${md5sum} "${STRIPPED_MD5_FILE}") |
| 11 |
endmacro(MD5) |
| 12 |
|
| 13 |
find_package(BISON 3.4) |
| 14 |
find_package(FLEX 2.5) |
| 15 |
|
| 16 |
if(BISON_FOUND AND FLEX_FOUND) |
| 17 |
BISON_TARGET(MZNParser |
| 18 |
${PROJECT_SOURCE_DIR}/lib/parser.yxx |
| 19 |
${PROJECT_BINARY_DIR}/parser.tab.cpp |
| 20 |
DEFINES_FILE ${PROJECT_BINARY_DIR}/include/minizinc/parser.tab.hh |
| 21 |
COMPILE_FLAGS "-p mzn_yy -l -Werror" |
| 22 |
) |
| 23 |
|
| 24 |
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include/minizinc/support/) |
| 25 |
BISON_TARGET(RegExParser |
| 26 |
${PROJECT_SOURCE_DIR}/lib/support/regex/parser.yxx |
| 27 |
${PROJECT_BINARY_DIR}/regex_parser.tab.cpp |
| 28 |
DEFINES_FILE ${PROJECT_BINARY_DIR}/include/minizinc/support/regex_parser.tab.hh |
| 29 |
COMPILE_FLAGS "-p regex_yy -l -Werror" |
| 30 |
) |
| 31 |
|
| 32 |
FLEX_TARGET(MZNLexer |
| 33 |
${PROJECT_SOURCE_DIR}/lib/lexer.lxx |
| 34 |
${PROJECT_BINARY_DIR}/lexer.yy.cpp |
| 35 |
COMPILE_FLAGS "-P mzn_yy -L" |
| 36 |
) |
| 37 |
ADD_FLEX_BISON_DEPENDENCY(MZNLexer MZNParser) |
| 38 |
|
| 39 |
FLEX_TARGET(RegExLexer |
| 40 |
${PROJECT_SOURCE_DIR}/lib/support/regex/lexer.lxx |
| 41 |
${PROJECT_BINARY_DIR}/regex_lexer.yy.cpp |
| 42 |
COMPILE_FLAGS "-P regex_yy -L" |
| 43 |
) |
| 44 |
ADD_FLEX_BISON_DEPENDENCY(RegExLexer RegExParser) |
| 45 |
else() |
| 46 |
MD5(${PROJECT_SOURCE_DIR}/lib/parser.yxx parser_yxx_md5) |
| 47 |
if(NOT "${parser_yxx_md5}" STREQUAL "${parser_yxx_md5_cached}") |
| 48 |
message(FATAL_ERROR |
| 49 |
"The file parser.yxx has been modified but bison cannot be run.\n" |
| 50 |
"If you are sure parser.tab.cpp and minizinc/parser.tab.hh in ${PROJECT_SOURCE_DIR}/lib/cached/ are correct " |
| 51 |
"then copy parser.yxx's md5 ${parser_yxx_md5} into ${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake" |
| 52 |
) |
| 53 |
endif() |
| 54 |
|
| 55 |
MD5(${PROJECT_SOURCE_DIR}/lib/support/regex/parser.yxx regex_parser_yxx_md5) |
| 56 |
if(NOT "${regex_parser_yxx_md5}" STREQUAL "${regex_parser_yxx_md5_cached}") |
| 57 |
message(FATAL_ERROR |
| 58 |
"The file regex/parser.yxx has been modified but bison cannot be run.\n" |
| 59 |
"If you are sure regex_parser.tab.cpp and minizinc/support/regex_parser.tab.hh in " |
| 60 |
"${PROJECT_SOURCE_DIR}/lib/cached/ are correct then copy regex_parser.yxx's md5 ${regex_parser_yxx_md5} into " |
| 61 |
"${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake" |
| 62 |
) |
| 63 |
endif() |
| 64 |
|
| 65 |
MD5(${PROJECT_SOURCE_DIR}/lib/lexer.lxx lexer_lxx_md5) |
| 66 |
if(NOT "${lexer_lxx_md5}" STREQUAL "${lexer_lxx_md5_cached}") |
| 67 |
message(FATAL_ERROR |
| 68 |
"The file lexer.lxx has been modified but flex cannot be run.\n" |
| 69 |
"If you are sure ${PROJECT_SOURCE_DIR}/lib/cached/lexer.yy.cpp is correct then " |
| 70 |
"copy lexer.lxx's md5 ${lexer_lxx_md5} into ${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake" |
| 71 |
) |
| 72 |
endif() |
| 73 |
|
| 74 |
MD5(${PROJECT_SOURCE_DIR}/lib/support/regex/lexer.lxx regex_lexer_lxx_md5) |
| 75 |
if(NOT "${regex_lexer_lxx_md5}" STREQUAL "${regex_lexer_lxx_md5_cached}") |
| 76 |
message(FATAL_ERROR |
| 77 |
"The file regex/lexer.lxx has been modified but flex cannot be run.\n" |
| 78 |
"If you are sure ${PROJECT_SOURCE_DIR}/lib/cached/regex_lexer.yy.cpp is correct then " |
| 79 |
"copy regex/lexer.lxx's md5 ${regex_lexer_lxx_md5} into ${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake" |
| 80 |
) |
| 81 |
endif() |
| 82 |
|
| 83 |
include_directories(${PROJECT_SOURCE_DIR}/lib/cached) |
| 84 |
set(BISON_MZNParser_OUTPUTS |
| 85 |
${PROJECT_SOURCE_DIR}/lib/cached/parser.tab.cpp |
| 86 |
${PROJECT_SOURCE_DIR}/lib/cached/minizinc/parser.tab.hh |
| 87 |
) |
| 88 |
set(BISON_RegExParser_OUTPUTS |
| 89 |
${PROJECT_SOURCE_DIR}/lib/cached/regex_parser.tab.cpp |
| 90 |
${PROJECT_SOURCE_DIR}/lib/cached/minizinc/support/regex_parser.tab.hh |
| 91 |
) |
| 92 |
set(FLEX_MZNLexer_OUTPUTS ${PROJECT_SOURCE_DIR}/lib/cached/lexer.yy.cpp) |
| 93 |
set(FLEX_RegExLexer_OUTPUTS ${PROJECT_SOURCE_DIR}/lib/cached/regex_lexer.yy.cpp) |
| 94 |
endif() |
| 95 |
|
| 96 |
if(NOT GECODE_FOUND) |
| 97 |
set(FLEX_RegExLexer_OUTPUTS "") |
| 98 |
set(BISON_RegExParser_OUTPUTS "") |
| 99 |
endif() |
| 100 |
|
| 101 |
add_library(minizinc_parser OBJECT |
| 102 |
${BISON_MZNParser_OUTPUTS} |
| 103 |
${FLEX_MZNLexer_OUTPUTS} |
| 104 |
${BISON_RegExParser_OUTPUTS} |
| 105 |
${FLEX_RegExLexer_OUTPUTS} |
| 106 |
) |
| 107 |
set_target_properties(minizinc_parser PROPERTIES |
| 108 |
CXX_CLANG_TIDY "" |
| 109 |
) |
| 110 |
|
| 111 |
if(GECODE_FOUND) |
| 112 |
target_include_directories(minizinc_parser PRIVATE "${GECODE_INCLUDE_DIRS}") |
| 113 |
target_compile_definitions(minizinc_parser PRIVATE HAS_GECODE) |
| 114 |
endif() |