2016-07-25 03:58:45 +08:00
|
|
|
# -*- mode:cmake -*-
|
2016-05-06 22:48:59 +08:00
|
|
|
if(NOT UNIX)
|
2017-10-31 02:55:58 +08:00
|
|
|
message(WARNING "Unsupported operating system")
|
2016-05-06 22:48:59 +08:00
|
|
|
endif()
|
|
|
|
|
2016-07-25 03:58:45 +08:00
|
|
|
set(antlr4-demo-GENERATED_SRC
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TLexer.cpp
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TParser.cpp
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TParserBaseListener.cpp
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TParserBaseVisitor.cpp
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TParserListener.cpp
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated/TParserVisitor.cpp
|
|
|
|
)
|
|
|
|
|
2018-10-31 00:48:58 +08:00
|
|
|
foreach(src_file ${antlr4-demo-GENERATED_SRC})
|
2016-07-25 03:58:45 +08:00
|
|
|
set_source_files_properties(
|
|
|
|
${src_file}
|
|
|
|
PROPERTIES
|
|
|
|
GENERATED TRUE
|
|
|
|
)
|
2018-10-31 00:48:58 +08:00
|
|
|
endforeach(src_file ${antlr4-demo-GENERATED_SRC})
|
2016-05-06 22:48:59 +08:00
|
|
|
|
2017-11-06 22:40:11 +08:00
|
|
|
add_custom_target(GenerateParser DEPENDS ${antlr4-demo-GENERATED_SRC})
|
|
|
|
add_custom_command(OUTPUT ${antlr4-demo-GENERATED_SRC}
|
2016-07-25 03:58:45 +08:00
|
|
|
COMMAND
|
2016-05-06 22:48:59 +08:00
|
|
|
${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/demo/generated/
|
|
|
|
COMMAND
|
2016-07-25 03:58:45 +08:00
|
|
|
"${Java_JAVA_EXECUTABLE}" -jar ${ANTLR_JAR_LOCATION} -Werror -Dlanguage=Cpp -listener -visitor -o ${PROJECT_SOURCE_DIR}/demo/generated/ -package antlrcpptest ${PROJECT_SOURCE_DIR}/demo/TLexer.g4 ${PROJECT_SOURCE_DIR}/demo/TParser.g4
|
|
|
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
|
|
|
DEPENDS ${PROJECT_SOURCE_DIR}/demo/TLexer.g4 ${PROJECT_SOURCE_DIR}/demo/TParser.g4
|
|
|
|
)
|
2016-05-06 22:48:59 +08:00
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src/misc
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src/atn
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src/dfa
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src/tree
|
|
|
|
${PROJECT_SOURCE_DIR}/runtime/src/support
|
|
|
|
${PROJECT_SOURCE_DIR}/demo/generated
|
|
|
|
)
|
|
|
|
|
|
|
|
#file(GLOB antlr4-demo_SRC "${PROJECT_SOURCE_DIR}/demo/generated/*")
|
|
|
|
set(antlr4-demo_SRC
|
2016-05-09 21:17:03 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/demo/Linux/main.cpp
|
2016-07-25 03:58:45 +08:00
|
|
|
${antlr4-demo-GENERATED_SRC}
|
2016-05-06 22:48:59 +08:00
|
|
|
)
|
|
|
|
|
2018-10-31 00:48:58 +08:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2017-10-31 02:55:58 +08:00
|
|
|
set (flags_1 "-Wno-overloaded-virtual")
|
|
|
|
else()
|
|
|
|
set (flags_1 "-MP /wd4251")
|
|
|
|
endif()
|
|
|
|
|
2018-10-31 00:48:58 +08:00
|
|
|
foreach(src_file ${antlr4-demo_SRC})
|
2016-05-09 21:17:03 +08:00
|
|
|
set_source_files_properties(
|
|
|
|
${src_file}
|
|
|
|
PROPERTIES
|
2017-10-31 02:55:58 +08:00
|
|
|
COMPILE_FLAGS "${COMPILE_FLAGS} ${flags_1}"
|
2016-05-09 21:17:03 +08:00
|
|
|
)
|
2018-10-31 00:48:58 +08:00
|
|
|
endforeach(src_file ${antlr4-demo_SRC})
|
2016-05-09 21:17:03 +08:00
|
|
|
|
2016-05-06 22:48:59 +08:00
|
|
|
add_executable(antlr4-demo
|
|
|
|
${antlr4-demo_SRC}
|
|
|
|
)
|
2016-06-17 21:54:21 +08:00
|
|
|
#add_precompiled_header(antlr4-demo ${PROJECT_SOURCE_DIR}/runtime/src/antlrcpp-Prefix.h)
|
2016-05-06 22:48:59 +08:00
|
|
|
|
2018-10-31 00:48:58 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2017-10-31 02:55:58 +08:00
|
|
|
target_compile_options(antlr4-demo PRIVATE "/MT$<$<CONFIG:Debug>:d>")
|
|
|
|
endif()
|
|
|
|
|
2016-05-06 22:48:59 +08:00
|
|
|
add_dependencies(antlr4-demo GenerateParser)
|
|
|
|
|
|
|
|
target_link_libraries(antlr4-demo antlr4_static)
|
|
|
|
|
|
|
|
install(TARGETS antlr4-demo
|
|
|
|
DESTINATION "share"
|
|
|
|
COMPONENT dev
|
|
|
|
)
|
|
|
|
|