|
| 1 | +cmake_minimum_required(VERSION 3.13) |
| 2 | + |
| 3 | +project(tree-sitter-elixir |
| 4 | + VERSION "0.3.4" |
| 5 | + DESCRIPTION "Elixir grammar for the tree-sitter parsing library" |
| 6 | + HOMEPAGE_URL "https://github.com/elixir-lang/tree-sitter-elixir" |
| 7 | + LANGUAGES C) |
| 8 | + |
| 9 | +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) |
| 10 | +option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) |
| 11 | + |
| 12 | +set(TREE_SITTER_ABI_VERSION 14 CACHE STRING "Tree-sitter ABI version") |
| 13 | +if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") |
| 14 | + unset(TREE_SITTER_ABI_VERSION CACHE) |
| 15 | + message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") |
| 16 | +endif() |
| 17 | + |
| 18 | +find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") |
| 19 | + |
| 20 | +add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" |
| 21 | + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" |
| 22 | + COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json |
| 23 | + --abi=${TREE_SITTER_ABI_VERSION} |
| 24 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 25 | + COMMENT "Generating parser.c") |
| 26 | + |
| 27 | +add_library(tree-sitter-elixir src/parser.c) |
| 28 | +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) |
| 29 | + target_sources(tree-sitter-elixir PRIVATE src/scanner.c) |
| 30 | +endif() |
| 31 | +target_include_directories(tree-sitter-elixir PRIVATE src) |
| 32 | + |
| 33 | +target_compile_definitions(tree-sitter-elixir PRIVATE |
| 34 | + $<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR> |
| 35 | + $<$<CONFIG:Debug>:TREE_SITTER_DEBUG>) |
| 36 | + |
| 37 | +set_target_properties(tree-sitter-elixir |
| 38 | + PROPERTIES |
| 39 | + C_STANDARD 11 |
| 40 | + POSITION_INDEPENDENT_CODE ON |
| 41 | + SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" |
| 42 | + DEFINE_SYMBOL "") |
| 43 | + |
| 44 | +configure_file(bindings/c/tree-sitter-elixir.pc.in |
| 45 | + "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-elixir.pc" @ONLY) |
| 46 | + |
| 47 | +include(GNUInstallDirs) |
| 48 | + |
| 49 | +install(FILES bindings/c/tree-sitter-elixir.h |
| 50 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") |
| 51 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-elixir.pc" |
| 52 | + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") |
| 53 | +install(TARGETS tree-sitter-elixir |
| 54 | + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
| 55 | + |
| 56 | +add_custom_target(ts-test "${TREE_SITTER_CLI}" test |
| 57 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 58 | + COMMENT "tree-sitter test") |
0 commit comments