-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
91 lines (79 loc) · 2.26 KB
/
CMakeLists.txt
File metadata and controls
91 lines (79 loc) · 2.26 KB
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
cmake_minimum_required(VERSION 3.19)
project(cpp-tree-sitter)
set(PACKAGE_NAME cpp-tree-sitter)
set(PACKAGE_VERSION 0.0.3)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "[email protected]")
add_compile_options(
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall;-Wextra;-Wconversion>"
)
include(cmake/CPM.cmake)
# We want to automatically download and provide tree-sitter to users of
# the package, so pull it in and retrofit cmake dependencies on top of it.
CPMAddPackage(
NAME tree-sitter
GIT_REPOSITORY https://github.com/tree-sitter/tree-sitter.git
VERSION 0.22.6
DOWNLOAD_ONLY YES
)
if (tree-sitter_ADDED)
add_library(tree-sitter)
target_sources(tree-sitter
PRIVATE
"${tree-sitter_SOURCE_DIR}/lib/src/lib.c"
)
target_include_directories(tree-sitter
PRIVATE
$<BUILD_INTERFACE:${tree-sitter_SOURCE_DIR}/lib/src>
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${tree-sitter_SOURCE_DIR}/lib/include>
)
target_compile_options(tree-sitter
PRIVATE
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-conversion>"
)
endif()
function(add_grammar_from_repo NAME REPO VERSION)
CPMAddPackage(
NAME ${NAME}
GIT_REPOSITORY ${REPO}
VERSION ${VERSION}
DOWNLOAD_ONLY YES
)
if ("${${NAME}_ADDED}")
add_library(${NAME})
file(GLOB maybe_scanner "${${NAME}_SOURCE_DIR}/src/scanner.c")
target_sources(${NAME}
PRIVATE
"${${NAME}_SOURCE_DIR}/src/parser.c"
${maybe_scanner}
)
target_include_directories(${NAME}
PRIVATE
# parser.h is stored within the src directory, so we need to include
# src in the search paths
$<BUILD_INTERFACE:${${NAME}_SOURCE_DIR}/src>
PUBLIC
$<INSTALL_INTERFACE:include>
)
target_link_libraries(${NAME}
INTERFACE
tree-sitter
)
target_compile_options(${NAME}
PRIVATE
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-but-set-variable>"
)
endif()
endfunction(add_grammar_from_repo)
add_library(cpp-tree-sitter INTERFACE)
target_include_directories(cpp-tree-sitter
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(cpp-tree-sitter
INTERFACE
tree-sitter
)