From a3229881bfcf353e34074ce74349f0fede1dbfb2 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Fri, 31 Jan 2020 12:35:22 +0100 Subject: [PATCH] Move Antlr generation to query Summary: The antlr openCypher parser generation is moved to query. Also, header files have been added to the list of generated files so that if any header file is deleted CMake will know that it has to regenerate it. Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2652 --- CMakeLists.txt | 34 ----------------------------- src/query/CMakeLists.txt | 46 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 384013049..0854782a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,41 +156,7 @@ include_directories(SYSTEM ${BZIP2_INCLUDE_DIR}) include_directories(SYSTEM ${ZLIB_INCLUDE_DIR}) include_directories(SYSTEM ${ROCKSDB_INCLUDE_DIR}) include_directories(SYSTEM ${LIBRDKAFKA_INCLUDE_DIR}) -# ----------------------------------------------------------------------------- -# openCypher parser ----------------------------------------------------------- -set(opencypher_frontend ${CMAKE_SOURCE_DIR}/src/query/frontend/opencypher) -set(opencypher_generated ${opencypher_frontend}/generated) -set(opencypher_lexer_grammar ${opencypher_frontend}/grammar/MemgraphCypherLexer.g4) -set(opencypher_parser_grammar ${opencypher_frontend}/grammar/MemgraphCypher.g4) - -# enumerate all files that are generated from antlr -set(antlr_opencypher_generated_src - ${opencypher_generated}/MemgraphCypherLexer.cpp - ${opencypher_generated}/MemgraphCypher.cpp - ${opencypher_generated}/MemgraphCypherBaseVisitor.cpp - ${opencypher_generated}/MemgraphCypherVisitor.cpp -) - -# Provide a command to generate sources if missing. If this were a -# custom_target, it would always run and we don't want that. -add_custom_command(OUTPUT ${antlr_opencypher_generated_src} - COMMAND - ${CMAKE_COMMAND} -E make_directory ${opencypher_generated} - COMMAND - java -jar ${CMAKE_SOURCE_DIR}/libs/antlr-4.6-complete.jar -Dlanguage=Cpp -visitor -o ${opencypher_generated} -package antlropencypher ${opencypher_lexer_grammar} ${opencypher_parser_grammar} - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - DEPENDS ${opencypher_lexer_grammar} ${opencypher_parser_grammar} - ${opencypher_frontend}/grammar/CypherLexer.g4 - ${opencypher_frontend}/grammar/Cypher.g4) - -# add custom target for generation -add_custom_target(generate_opencypher_parser - DEPENDS ${antlr_opencypher_generated_src}) - -add_library(antlr_opencypher_parser_lib STATIC ${antlr_opencypher_generated_src}) -target_link_libraries(antlr_opencypher_parser_lib antlr4) -# ----------------------------------------------------------------------------- # Optional subproject configuration ------------------------------------------- option(TEST_COVERAGE "Generate coverage reports from running memgraph" OFF) diff --git a/src/query/CMakeLists.txt b/src/query/CMakeLists.txt index a1f63942a..90bba7824 100644 --- a/src/query/CMakeLists.txt +++ b/src/query/CMakeLists.txt @@ -31,7 +31,49 @@ set(mg_query_sources add_library(mg-query STATIC ${mg_query_sources}) add_dependencies(mg-query generate_lcp_query) -add_dependencies(mg-query generate_opencypher_parser) target_include_directories(mg-query PRIVATE ${CMAKE_SOURCE_DIR}/include) -target_link_libraries(mg-query dl cppitertools antlr_opencypher_parser_lib) +target_link_libraries(mg-query dl cppitertools) target_link_libraries(mg-query mg-storage-v2) + +# Generate Antlr openCypher parser + +set(opencypher_frontend ${CMAKE_CURRENT_SOURCE_DIR}/frontend/opencypher) +set(opencypher_generated ${opencypher_frontend}/generated) +set(opencypher_lexer_grammar ${opencypher_frontend}/grammar/MemgraphCypherLexer.g4) +set(opencypher_parser_grammar ${opencypher_frontend}/grammar/MemgraphCypher.g4) + +set(antlr_opencypher_generated_src + ${opencypher_generated}/MemgraphCypherLexer.cpp + ${opencypher_generated}/MemgraphCypher.cpp + ${opencypher_generated}/MemgraphCypherBaseVisitor.cpp + ${opencypher_generated}/MemgraphCypherVisitor.cpp +) +set(antlr_opencypher_generated_include + ${opencypher_generated}/MemgraphCypherLexer.h + ${opencypher_generated}/MemgraphCypher.h + ${opencypher_generated}/MemgraphCypherBaseVisitor.h + ${opencypher_generated}/MemgraphCypherVisitor.h +) + +add_custom_command( + OUTPUT ${antlr_opencypher_generated_src} ${antlr_opencypher_generated_include} + COMMAND ${CMAKE_COMMAND} -E make_directory ${opencypher_generated} + COMMAND + java -jar ${CMAKE_SOURCE_DIR}/libs/antlr-4.6-complete.jar + -Dlanguage=Cpp -visitor -package antlropencypher + -o ${opencypher_generated} + ${opencypher_lexer_grammar} ${opencypher_parser_grammar} + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + DEPENDS + ${opencypher_lexer_grammar} ${opencypher_parser_grammar} + ${opencypher_frontend}/grammar/CypherLexer.g4 + ${opencypher_frontend}/grammar/Cypher.g4) + +add_custom_target(generate_opencypher_parser + DEPENDS ${antlr_opencypher_generated_src} ${antlr_opencypher_generated_include}) + +add_library(antlr_opencypher_parser_lib STATIC ${antlr_opencypher_generated_src}) +add_dependencies(antlr_opencypher_parser_lib generate_opencypher_parser) +target_link_libraries(antlr_opencypher_parser_lib antlr4) + +target_link_libraries(mg-query antlr_opencypher_parser_lib)