forked from P4-ACMMMRW/dpli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
83 lines (59 loc) · 2.78 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(dpl)
enable_testing()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Can not be upgraded to C++20 because of a bug in github actions with chrono header
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(ANTLR4_WITH_STATIC_CRT ON)
add_definitions(-DANTLR4CPP_STATIC)
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
include(ExternalAntlr4Cpp)
set(ANTLR_EXECUTABLE ${PROJECT_SOURCE_DIR}/lib/antlr/antlr-4.13.1-complete.jar)
find_package(ANTLR REQUIRED)
# ANTLR targets
antlr_target(DplLexer ${PROJECT_SOURCE_DIR}/grammar/DplLexer.g4 LEXER
PACKAGE dplgrammar
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/antlr4cpp_generated_src/DplLexer/grammar)
antlr_target(DplParser ${PROJECT_SOURCE_DIR}/grammar/DplParser.g4 PARSER
PACKAGE dplgrammar
DEPENDS_ANTLR DplLexer
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/antlr4cpp_generated_src/DplParser/grammar
COMPILE_FLAGS -lib ${ANTLR_DplLexer_OUTPUT_DIR} -visitor)
message(STATUS "ANTLR_DplLexer_OUTPUT_DIR: ${ANTLR_DplLexer_OUTPUT_DIR}")
message(STATUS "ANTLR_DplParser_OUTPUT_DIR: ${ANTLR_DplParser_OUTPUT_DIR}")
message(STATUS "ANTLR_DplLexer_CXX_OUTPUTS: ${ANTLR_DplLexer_CXX_OUTPUTS}")
message(STATUS "ANTLR_DplParser_CXX_OUTPUTS: ${ANTLR_DplParser_CXX_OUTPUTS}")
file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")
message(STATUS "SOURCES: ${SOURCES}")
message(STATUS "Compiling with ${CMAKE_CXX_COMPILER_ID}")
add_library(dpllib STATIC ${SOURCES} ${ANTLR_DplLexer_CXX_OUTPUTS} ${ANTLR_DplParser_CXX_OUTPUTS})
target_include_directories(dpllib PUBLIC
${ANTLR_DplLexer_OUTPUT_DIR}
${ANTLR_DplParser_OUTPUT_DIR}
${PROJECT_SOURCE_DIR}/lib/argz
${PROJECT_SOURCE_DIR}/include/src
${PROJECT_SOURCE_DIR}/include/src/symbol-table
${PROJECT_SOURCE_DIR}/include/src/ast
${PROJECT_SOURCE_DIR}/include/src/ast/nodes
${PROJECT_SOURCE_DIR}/include/src/ast/nodes/abstract
${PROJECT_SOURCE_DIR}/include/src/error-handling
${PROJECT_SOURCE_DIR}/include/src/error-handling/exceptions
)
target_link_libraries(dpllib PUBLIC antlr4_static)
add_executable(dpli Main.cpp)
target_include_directories(dpli PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(dpli PRIVATE dpllib antlr4_static)
add_subdirectory(tests)
# Strip debug symbols in Release mode
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET dpli POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:dpli>)
endif()