-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
138 lines (106 loc) · 3.41 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Project ----
project(LarsParser
VERSION 1.11
LANGUAGES CXX
)
if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# ---- Configuration variables ----
option(LARS_PARSER_BUILD_EXAMPLES "Enable examples" OFF)
option(LARS_PARSER_ENABLE_TESTS "Enable tests" OFF)
option(LARS_PARSER_BUILD_GLUE_ELEMENT "Build LarsParser Glue extension" OFF)
# ---- Dependencies ----
if(${LARS_PARSER_ENABLE_TESTS})
set(LARS_PARSER_BUILD_GLUE_ELEMENT ON)
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake)
CPMAddPackage(
NAME LHC
GIT_REPOSITORY https://github.com/TheLartians/LHC.git
VERSION 0.8
)
if(${LARS_PARSER_BUILD_GLUE_ELEMENT})
CPMAddPackage(
NAME Glue
GIT_REPOSITORY https://github.com/TheLartians/Glue.git
VERSION 0.9.6-a
GIT_TAG 1c77bce7a4fd97749caba8ac79d50af165a0a600
)
endif()
# ---- Create library ----
SET(headers
"${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/grammar.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/parser.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/interpreter.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/generator.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/peg.h"
)
SET(sources
"${CMAKE_CURRENT_SOURCE_DIR}/source/grammar.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/source/parser.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/source/interpreter.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/source/peg.cpp"
)
if(${LARS_PARSER_BUILD_GLUE_ELEMENT})
LIST(APPEND headers "${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/glue.h")
LIST(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/source/glue.cpp")
endif()
add_library(LarsParser ${sources} ${headers})
set_target_properties(LarsParser PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-Wall -pedantic -Wextra")
target_link_libraries(LarsParser PRIVATE LHC)
if(${LARS_PARSER_BUILD_GLUE_ELEMENT})
target_link_libraries(LarsParser PUBLIC Glue)
endif()
target_include_directories(LarsParser
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/LarsParserConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# ---- Install ----
install(
TARGETS LarsParser
EXPORT LarsParserTargets
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/LarsParserConfig.cmake.in"
"${PROJECT_BINARY_DIR}/LarsParserConfig.cmake"
INSTALL_DESTINATION lib/cmake/LarsParser
)
install(
EXPORT LarsParserTargets
DESTINATION lib/cmake/LarsParser
)
install(
FILES
"${PROJECT_BINARY_DIR}/LarsParserConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/LarsParserConfig.cmake"
DESTINATION
lib/cmake/LarsParser
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include
)
# ---- Examples ----
IF(${LARS_PARSER_BUILD_EXAMPLES})
add_subdirectory(examples)
ENDIF()
# ---- Tests ----
if(${LARS_PARSER_ENABLE_TESTS})
ENABLE_TESTING()
add_subdirectory(tests)
endif()