Generate openCypher parser sources if missing

Summary:
Makes cmake aware that parser source files are generated, so that it can
know how to set the dependencies for the underlying build tool. When the
files do not exist, invoking e.g. `make` will also run antlr to generate
them. Files will be regenerated only if their dependency changed
(Cypher.g4 file in this case).

Reviewers: buda, florijan

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D94
This commit is contained in:
Teon Banek 2017-03-08 08:59:37 +01:00 committed by Teon Banek
parent b834cdc94a
commit 47ed127086

View File

@ -9,9 +9,14 @@ if(NOT UNIX)
message(FATAL "Unsupported operating system.")
endif()
# Set `make clean` to ignore outputs of add_custom_command. If generated files
# need to be cleaned, set ADDITIONAL_MAKE_CLEAN_FILES property.
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM TRUE)
# ccache setup
# ccache isn't enabled all the time because it makes some problem
# during the code coverage process
find_program(CCACHE_FOUND ccache)
option(USE_CCACHE "ccache:" ON)
message(STATUS "CCache: ${USE_CCACHE}")
if(CCACHE_FOUND AND USE_CCACHE)
@ -269,21 +274,25 @@ set(opencypher_grammar ${opencypher_frontend}/grammar/Cypher.g4)
# enumerate all files that are generated from antlr
set(antlr_opencypher_generated_src
${opencypher_frontend}/generated/CypherLexer.cpp
${opencypher_frontend}/generated/CypherParser.cpp
${opencypher_frontend}/generated/CypherBaseVisitor.cpp
${opencypher_frontend}/generated/CypherVisitor.cpp
${opencypher_generated}/CypherLexer.cpp
${opencypher_generated}/CypherParser.cpp
${opencypher_generated}/CypherBaseVisitor.cpp
${opencypher_generated}/CypherVisitor.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_grammar}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS ${opencypher_grammar})
# add custom target for generation
add_custom_target(generate_opencypher_parser
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_grammar}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS ${opencypher_grammar}
)
DEPENDS ${antlr_opencypher_generated_src})
# include antlr header files
include_directories(
@ -344,10 +353,12 @@ set(memgraph_src_files
# STATIC library used by memgraph executables
add_library(memgraph_lib STATIC ${memgraph_src_files})
add_dependencies(memgraph_lib generate_opencypher_parser)
# -----------------------------------------------------------------------------
# STATIC PIC library used by query engine
add_library(memgraph_pic STATIC ${memgraph_src_files})
add_dependencies(memgraph_pic generate_opencypher_parser)
set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE)
# -----------------------------------------------------------------------------