mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:36:22 -04:00
build(lib): build using cmake
This commit is contained in:
parent
fcbd67b3fa
commit
26c1202058
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -32,4 +32,5 @@ docs/assets/js/tree-sitter.js
|
||||||
*.wasm
|
*.wasm
|
||||||
.swiftpm
|
.swiftpm
|
||||||
.build
|
.build
|
||||||
|
build
|
||||||
zig-*
|
zig-*
|
||||||
|
|
|
||||||
15
Makefile
15
Makefile
|
|
@ -3,6 +3,8 @@ $(error Windows is not supported)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
VERSION := 0.23.0
|
VERSION := 0.23.0
|
||||||
|
DESCRIPTION := An incremental parsing system for programming tools
|
||||||
|
HOMEPAGE_URL := https://tree-sitter.github.io/tree-sitter/
|
||||||
|
|
||||||
# install directory layout
|
# install directory layout
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
@ -58,12 +60,13 @@ ifneq ($(STRIP),)
|
||||||
$(STRIP) $@
|
$(STRIP) $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
tree-sitter.pc: tree-sitter.pc.in
|
tree-sitter.pc: lib/tree-sitter.pc.in
|
||||||
sed -e 's|@VERSION@|$(VERSION)|' \
|
sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \
|
||||||
-e 's|@LIBDIR@|$(LIBDIR)|' \
|
-e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR)|' \
|
||||||
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
|
-e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR)|' \
|
||||||
-e 's|=$(PREFIX)|=$${prefix}|' \
|
-e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \
|
||||||
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
|
-e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \
|
||||||
|
-e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT)
|
$(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT)
|
||||||
|
|
|
||||||
61
lib/CMakeLists.txt
Normal file
61
lib/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
|
project(tree-sitter
|
||||||
|
VERSION "0.23.0"
|
||||||
|
DESCRIPTION "An incremental parsing system for programming tools"
|
||||||
|
HOMEPAGE_URL "https://tree-sitter.github.io/tree-sitter/"
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
|
set(CMAKE_C_FLAGS "-O3 -Wall -Wextra -Wshadow -Wno-unused-parameter -pedantic")
|
||||||
|
endif(NOT MSVC)
|
||||||
|
|
||||||
|
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
|
||||||
|
option(TREE_SITTER_FEATURE_WASM "Enable the Wasm feature" OFF)
|
||||||
|
|
||||||
|
file(GLOB TS_SOURCE_FILES src/*.c)
|
||||||
|
list(REMOVE_ITEM TS_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/lib.c")
|
||||||
|
|
||||||
|
add_library(tree-sitter ${TS_SOURCE_FILES})
|
||||||
|
|
||||||
|
target_include_directories(tree-sitter PRIVATE src src/wasm include)
|
||||||
|
|
||||||
|
if(TREE_SITTER_FEATURE_WASM)
|
||||||
|
if(NOT DEFINED CACHE{WASMTIME_INCLUDE_DIR})
|
||||||
|
message(CHECK_START "Looking for wasmtime headers")
|
||||||
|
find_path(WASMTIME_INCLUDE_DIR wasmtime.h
|
||||||
|
PATHS ENV DEP_WASMTIME_C_API_INCLUDE
|
||||||
|
REQUIRED)
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
endif(NOT DEFINED CACHE{WASMTIME_INCLUDE_DIR})
|
||||||
|
|
||||||
|
if(NOT DEFINED CACHE{WASMTIME_LIBRARY})
|
||||||
|
message(CHECK_START "Looking for wasmtime library")
|
||||||
|
find_library(WASMTIME_LIBRARY wasmtime
|
||||||
|
REQUIRED)
|
||||||
|
message(CHECK_PASS "found")
|
||||||
|
endif(NOT DEFINED CACHE{WASMTIME_LIBRARY})
|
||||||
|
|
||||||
|
target_compile_definitions(tree-sitter PUBLIC TREE_SITTER_FEATURE_WASM)
|
||||||
|
target_include_directories(tree-sitter SYSTEM PRIVATE "${WASMTIME_INCLUDE_DIR}")
|
||||||
|
target_link_libraries(tree-sitter PRIVATE "${WASMTIME_LIBRARY}")
|
||||||
|
set_property(TARGET tree-sitter PROPERTY C_STANDARD_REQUIRED ON)
|
||||||
|
endif(TREE_SITTER_FEATURE_WASM)
|
||||||
|
|
||||||
|
set_target_properties(tree-sitter
|
||||||
|
PROPERTIES
|
||||||
|
C_STANDARD 11
|
||||||
|
C_VISIBILITY_PRESET hidden
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
|
||||||
|
|
||||||
|
configure_file(tree-sitter.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter.pc" @ONLY)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
install(FILES include/tree_sitter/api.h
|
||||||
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter.pc"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
|
||||||
|
install(TARGETS tree-sitter
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||||
10
lib/tree-sitter.pc.in
Normal file
10
lib/tree-sitter.pc.in
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||||
|
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: tree-sitter
|
||||||
|
Description: @PROJECT_DESCRIPTION@
|
||||||
|
URL: @PROJECT_HOMEPAGE_URL@
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
Libs: -L${libdir} -ltree-sitter
|
||||||
|
Cflags: -I${includedir}
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
prefix=@PREFIX@
|
|
||||||
libdir=@LIBDIR@
|
|
||||||
includedir=@INCLUDEDIR@
|
|
||||||
|
|
||||||
Name: tree-sitter
|
|
||||||
Description: An incremental parsing system for programming tools
|
|
||||||
URL: https://tree-sitter.github.io/
|
|
||||||
Version: @VERSION@
|
|
||||||
Libs: -L${libdir} -ltree-sitter
|
|
||||||
Cflags: -I${includedir}
|
|
||||||
Loading…
Reference in a new issue