BuildTreesitter.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # BuildTreeSitter(TARGET targetname CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
  2. function(BuildTreeSitter)
  3. cmake_parse_arguments(_treesitter
  4. "BUILD_IN_SOURCE"
  5. "TARGET"
  6. "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
  7. ${ARGN})
  8. if(NOT _treesitter_CONFIGURE_COMMAND AND NOT _treesitter_BUILD_COMMAND
  9. AND NOT _treesitter_INSTALL_COMMAND)
  10. message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
  11. endif()
  12. if(NOT _treesitter_TARGET)
  13. set(_treesitter_TARGET "tree-sitter")
  14. endif()
  15. ExternalProject_Add(tree-sitter
  16. PREFIX ${DEPS_BUILD_DIR}
  17. URL ${TREESITTER_URL}
  18. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/tree-sitter
  19. INSTALL_DIR ${DEPS_INSTALL_DIR}
  20. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  21. -DPREFIX=${DEPS_BUILD_DIR}
  22. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/tree-sitter
  23. -DURL=${TREESITTER_URL}
  24. -DEXPECTED_SHA256=${TREESITTER_SHA256}
  25. -DTARGET=tree-sitter
  26. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  27. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  28. BUILD_IN_SOURCE ${_treesitter_BUILD_IN_SOURCE}
  29. PATCH_COMMAND ""
  30. CONFIGURE_COMMAND "${_treesitter_CONFIGURE_COMMAND}"
  31. BUILD_COMMAND "${_treesitter_BUILD_COMMAND}"
  32. INSTALL_COMMAND "${_treesitter_INSTALL_COMMAND}")
  33. endfunction()
  34. if(MSVC)
  35. BuildTreeSitter(BUILD_IN_SOURCE
  36. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy
  37. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TreesitterCMakeLists.txt
  38. ${DEPS_BUILD_DIR}/src/tree-sitter/CMakeLists.txt
  39. COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/tree-sitter/CMakeLists.txt
  40. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  41. -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  42. -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
  43. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  44. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  45. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
  46. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}
  47. )
  48. else()
  49. set(TS_CFLAGS "-O3 -Wall -Wextra")
  50. BuildTreeSitter(BUILD_IN_SOURCE
  51. CONFIGURE_COMMAND ""
  52. BUILD_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER} CFLAGS=${TS_CFLAGS}
  53. INSTALL_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER} PREFIX=${DEPS_INSTALL_DIR} install)
  54. endif()
  55. list(APPEND THIRD_PARTY_DEPS tree-sitter)