tree-sitter-omega
aien-dev/tree-sitter-omega
Brought by drakestapleton
tree-sitter-omega / CMakeLists.txt
| 1 | cmake_minimum_required(VERSION 3.13) |
| 2 | |
| 3 | project(tree-sitter-omega |
| 4 | VERSION "0.1.0" |
| 5 | DESCRIPTION "Omega (.om, Omegese) grammar for tree-sitter" |
| 6 | HOMEPAGE_URL "https://github.com/aien-dev/tree-sitter-omega" |
| 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 15 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 | include(GNUInstallDirs) |
| 19 | |
| 20 | find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI" REQUIRED) |
| 21 | |
| 22 | add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" |
| 23 | "${CMAKE_CURRENT_SOURCE_DIR}/src/node-types.json" |
| 24 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/grammar.js" |
| 25 | COMMAND "${TREE_SITTER_CLI}" generate grammar.js --no-parser |
| 26 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 27 | COMMENT "Generating grammar.json") |
| 28 | |
| 29 | add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" |
| 30 | BYPRODUCTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/parser.h" |
| 31 | "${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/alloc.h" |
| 32 | "${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/array.h" |
| 33 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" |
| 34 | COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json |
| 35 | --abi=${TREE_SITTER_ABI_VERSION} |
| 36 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 37 | COMMENT "Generating parser.c") |
| 38 | |
| 39 | add_library(tree-sitter-omega src/parser.c) |
| 40 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) |
| 41 | target_sources(tree-sitter-omega PRIVATE src/scanner.c) |
| 42 | endif() |
| 43 | target_include_directories(tree-sitter-omega |
| 44 | PRIVATE src |
| 45 | INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c> |
| 46 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 47 | |
| 48 | target_compile_definitions(tree-sitter-omega PRIVATE |
| 49 | $<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR> |
| 50 | $<$<CONFIG:Debug>:TREE_SITTER_DEBUG>) |
| 51 | |
| 52 | set_target_properties(tree-sitter-omega |
| 53 | PROPERTIES |
| 54 | C_STANDARD 11 |
| 55 | POSITION_INDEPENDENT_CODE ON |
| 56 | SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" |
| 57 | DEFINE_SYMBOL "") |
| 58 | |
| 59 | configure_file(bindings/c/tree-sitter-omega.pc.in |
| 60 | "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-omega.pc" @ONLY) |
| 61 | |
| 62 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" |
| 63 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 64 | FILES_MATCHING PATTERN "*.h") |
| 65 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-omega.pc" |
| 66 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 67 | install(TARGETS tree-sitter-omega |
| 68 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
| 69 | |
| 70 | file(GLOB QUERIES queries/*.scm) |
| 71 | install(FILES ${QUERIES} |
| 72 | DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/omega") |
| 73 | |
| 74 | add_custom_target(ts-test "${TREE_SITTER_CLI}" test |
| 75 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 76 | COMMENT "tree-sitter test") |